Skip to content

Instantly share code, notes, and snippets.

View mutatrum's full-sized avatar
💭
hodl.camp

mutatrum mutatrum

💭
hodl.camp
View GitHub Profile
@mutatrum
mutatrum / bitcoin-logo-white.svg
Last active November 8, 2022 21:54
Remake of the original bitcoin logo
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mutatrum
mutatrum / decode_hex.jq
Created October 6, 2022 08:12
Define decode_hex function for jq.
def decode_hex:
def decode: if . < 58 then .-48 elif . < 91 then .-55 else .-87 end;
def decode_byte: map(decode) | (.[0] * 16) + .[1];
def pairs: explode | range(0;length;2) as $i | [.[$i], .[$i+1]];
def filter: if (. < 32 or (. >= 128 and . <= 159)) then 46 else . end;
[pairs|decode_byte|filter] | implode;
@mutatrum
mutatrum / value_on_nulldata.sh
Last active October 6, 2022 08:13
Find transactions which put value on nulldata
#!/bin/bash
BLOCK=$(bitcoin-cli getblockcount)
for ((i=BLOCK; i>=1; i--))
do
echo $i
bitcoin-cli getblock $(bitcoin-cli getblockhash $i) 3 | jq -L $HOME -r 'include ".jq/decode_hex";
.tx[] | select(any(.vout[]; .scriptPubKey.type == "nulldata" and .value != 0)) | .txid + " " + (.vout[0].value * 1e8 | tostring) + " " + (.vout[0].scriptPubKey.hex[4:] | decode_hex)'
done
@mutatrum
mutatrum / difficulty_adjustments.sh
Last active September 14, 2022 20:26
Print all historical difficulty adjustments
#!/bin/bash
CURRENTHEIGHT=$(bitcoin-cli getblockchaininfo | jq -r .blocks)
DIFFICULTY=1
for ((HEIGHT = 0 ; HEIGHT < CURRENTHEIGHT ; HEIGHT += 2016))
do
NEW_DIFFICULTY=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $HEIGHT) | jq -r .difficulty)
ADJUSTMENT=$(bc <<< "scale=16 ; ((($NEW_DIFFICULTY * 100 / $DIFFICULTY)) - 100)" | awk '{printf("%.2f \n",$1)}')
echo $((HEIGHT / 2016)) $HEIGHT $NEW_DIFFICULTY $ADJUSTMENT
DIFFICULTY=$NEW_DIFFICULTY
done
@mutatrum
mutatrum / blocktime.sh
Last active September 14, 2022 20:52
Calculate block height based on a timestamp
#!/bin/bash
TIME=$(date -d "$1" +"%s")
function getBlockTime {
echo $(bitcoin-cli getblockheader $(bitcoin-cli getblockhash $1) | jq -r .time)
}
function binarySearch {
L=$1
@mutatrum
mutatrum / montyhodlonaut.js
Last active May 9, 2022 11:17
Monty Hodlonaut
BOXES = [[ '₿', '₿'], // Box A
[ '₿', '💩'], // Box B
['💩', '💩']] // Box C
var count = 0, success = 0;
while(count <= 1_000_000) {
// You choose a box at random
var drawbox = Math.floor(Math.random() * 3);
@mutatrum
mutatrum / supply.js
Created May 3, 2022 08:36
Block reward and supply calculation
for (block_height = 0; block_height < 6_930_000; block_height += 210_000) {
epoch = Math.floor(block_height / 210_000) + 1
coin = 100_000_000
reward = Math.floor(100 * coin / Math.pow(2, epoch))
supply = 0
for (i = 1; i <= epoch; i++) {
supply += Math.floor(100 * coin / Math.pow(2, i)) * 210_000
@mutatrum
mutatrum / chan_id.js
Last active September 2, 2021 12:01
Convert ChannelLink notation to hashed notation
#!/usr/bin/env node
var input = process.argv[2].split(':')
var result = (BigInt(input[0]) << 40n) + (BigInt(input[1]) << 16n) + (BigInt(input[2]))
console.log(result.toString())
#!/bin/bash
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo)
CURRENTHEIGHT=$(echo $BLOCKCHAININFO | jq -r .blocks)
CURRENTTIME=$(echo $BLOCKCHAININFO | jq -r .mediantime)
BLOCKS=$((CURRENTHEIGHT%2016))
REMAINING=$((2016-BLOCKS))
LOOKBACKHEIGHT=$((CURRENTHEIGHT-REMAINING))
LOOKBACKBLOCK=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $LOOKBACKHEIGHT))
LOOKBACKTIME=$(echo $LOOKBACKBLOCK | jq -r .mediantime)
LOOKBACKDELTA=$((CURRENTTIME-LOOKBACKTIME))
#!/bin/bash
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo)
CURRENTHEIGHT=$(echo $BLOCKCHAININFO | jq -r .blocks)
CURRENTTIME=$(echo $BLOCKCHAININFO | jq -r .mediantime)
BLOCKS=$((CURRENTHEIGHT%2016))
STARTHEIGHT=$((CURRENTHEIGHT-BLOCKS))
STARTBLOCK=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $STARTHEIGHT))
STARTTIME=$(echo $STARTBLOCK | jq -r .mediantime)
AVERAGETIME=$(((CURRENTTIME-STARTTIME)/BLOCKS))
PERCENT=$(awk "BEGIN {print -100+(60000/$AVERAGETIME)}")