Skip to content

Instantly share code, notes, and snippets.

@jonasnick
Created January 2, 2019 16:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonasnick/e4a2b41215a35a461099a5ca2d8affc4 to your computer and use it in GitHub Desktop.
Save jonasnick/e4a2b41215a35a461099a5ca2d8affc4 to your computer and use it in GitHub Desktop.
# bitcoin-cli wrapper for running c-lightning with a pruned Bitcoin node
# (EXPERIMENTAL). It forwards all requests to bitcoind. If a getblock request fails,
# blockstream.info is queried instead. If your prune setting is high enough (2 weeks
# = 2016?) using this wrapper SHOULDN'T have security implications because the
# important blocks are still queried through your own bitcoind.
# Tested with c-lightning 0.6.2. Set the --bitcoin-cli=PATH option in c-lightning to
# the path of this file to use it.
BCLI=bitcoin-cli
getblock() {
hash=$1
txids=$(curl -H "Accept: application/json" https://blockstream.info/api/block/"$hash"/txids 2> /dev/null)
if [[ $txids = *[![:ascii:]]* ]]; then
exit 1
fi
echo "{ \"txs\": $txids }"
}
i=0
argsArray=( "$@" )
for var in "$@"
do
i=$(( i+1 ))
if [[ ${var:0:1} == "-" ]];
then
continue
elif [ "$var" == "getblock" ];
then
$BCLI "$@"
if [ $? -ne 0 ]; then
getblock "${argsArray[$i]}"
fi;
break
else
set -e
$BCLI "$@"
break
fi
done
@shesek
Copy link

shesek commented Aug 11, 2020

This is very useful, thanks!

@sha-265
Copy link

sha-265 commented Aug 11, 2020

Thanks. Shebang #!/bin/bash should be added in first line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment