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 / halving.sh
Last active January 26, 2021 00:02
Get estimated halving date from a bitcoin node
#!/bin/bash
CURRENT_BLOCK="$(bitcoin-cli getblockcount)"
CURRENT_BLOCK_HASH="$(bitcoin-cli getblockhash $CURRENT_BLOCK)"
CURRENT_BLOCK_TIME="$(bitcoin-cli getblock $CURRENT_BLOCK_HASH | jq '.mediantime')"
HALVING_BLOCK="$(((($CURRENT_BLOCK/210000)+1)*210000))"
BLOCK_DELTA="$(($HALVING_BLOCK-$CURRENT_BLOCK))"
PREVIOUS_BLOCK="$(($CURRENT_BLOCK-$BLOCK_DELTA))"
PREVIOUS_BLOCK_HASH="$(bitcoin-cli getblockhash $PREVIOUS_BLOCK)"
PREVIOUS_BLOCK_TIME="$(bitcoin-cli getblock $PREVIOUS_BLOCK_HASH | jq '.mediantime')"
DELTA_TIME="$(($CURRENT_BLOCK_TIME-$PREVIOUS_BLOCK_TIME))"
Eligius<5Benedictus Iesus in sanctissimo altaris Sacramento.
Eligius5<Benedictus Deus in Angelis suis, et in Sanctis suis. Amen.
Eligius%ZLTO my God, I am heartily sorry for having offended Thee and I detest all my sins...
EligiusLS...because of Thy just punishments, but most of all because they offend Thee, ...
EligiusA;...my God, who art all good and deserving of all my love.
Eligius(AI firmly resolve, with the help of Thy grace, to sin no more...
EligiusD/...and avoid the near occasions of sin. Amen.
EligiusLOO my God! I firmly believe that Thou art one God in three Divine persons, ...
EligiusELO...Father, Son, and Holy Ghost; I believe that Thy Divine Son became man, ...
Eligiusr;LT...and died for our sins, and that he will come to, judge the living and the dead.
#!/bin/bash
HEIGHT=$(bitcoin-cli getblockcount)
echo "$HEIGHT"
for ((i=1; i<=$HEIGHT; i++ ))
do
COINBASE=$(bitcoin-cli decoderawtransaction $(bitcoin-cli getrawtransaction $(bitcoin-cli getblock $(bitcoin-cli getblockhash $i) | jq -r '.tx[0]')) | jq -r '.vin[0].coinbase' | xxd -r -p | tr -cd '[:print:]')
echo "$COINBASE"
const fs = require('fs');
const readline = require('readline');
var english = fs.readFileSync('english.txt', 'utf8').split("\n")
const readInterface = readline.createInterface({
input: fs.createReadStream('coinbase.txt'),
console: false
});
@mutatrum
mutatrum / BitcoinJTest.java
Created April 16, 2020 15:59
Using bitcoinj to derive legacy, segwit and bech32 addresses from account xpub
import org.bitcoinj.core.*;
import org.bitcoinj.crypto.*;
import org.bitcoinj.params.*;
import org.bitcoinj.script.*;
import org.junit.*;
public class BitcoinJTest
{
private static NetworkParameters params = MainNetParams.get();
@mutatrum
mutatrum / lndgraph.js
Created March 5, 2021 13:07
Find depth of BOS nodes in LND node graph
const fs = require('fs');
// Fill in your own node alias
const NAME = '<nodealias>';
console.log('start');
// lncli describegraph > graph.json
var graph = JSON.parse(fs.readFileSync('graph.json'));
// https://bos.lightning.jorijn.com/data/export.json
map $http_accept_language $header_lang {
default en-US;
~*^en-US en-US;
~*^en en-US;
~*^ar ar;
~*^cs cs;
~*^de de;
~*^es es;
~*^fa fa;
~*^fr fr;
@mutatrum
mutatrum / taproot.sh
Last active June 12, 2021 16:44
Print a taproot signalling block diagram
#!/bin/bash
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9)
SINCE=$(echo "$TAPROOT" | jq .since)
PERIOD=$(echo "$TAPROOT" | jq .statistics.period)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
PERIOD_COUNT=$(((BLOCKS - SINCE) / PERIOD))
SINCE=$((SINCE + (PERIOD * PERIOD_COUNT)))
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed)
#!/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)}")