Skip to content

Instantly share code, notes, and snippets.

@strophy
Created March 25, 2020 07:29
Show Gist options
  • Save strophy/f3df01c5c4253d924880cfeb7c2c4a13 to your computer and use it in GitHub Desktop.
Save strophy/f3df01c5c4253d924880cfeb7c2c4a13 to your computer and use it in GitHub Desktop.
Find all superblock payments to a given list of addresses (CSV two fields: address,description)
#!/bin/bash
n=0
echo "Reading csv from stdin..." 1>&2
while IFS=,$'\r' read a b;do
echo "$a - $b" 1>&2
ADDRESS[$n]="$a"
DESC[$n]="$b"
((n++))
done
echo "Read $n rows." 1>&2
if [[ $n = 0 ]];then exit 1;fi
height=$(dash-cli getblockcount)
if [ $? -ne 0 ];then echo "dash-cli does not seem to be working..." 1>&2;exit 2;fi
# Print the csv header
echo "${ADDRESS[0]},${DESC[0]},date,block_num,tx_hash,DASH_recieved"
for ((block=332320;block<height;block+=16616));do
blockhash=$(dash-cli getblockhash $block)
txhash=$(dash-cli getblock $blockhash|jq -r '.tx[0]')
time=$(dash-cli getblock $blockhash|jq -r '.time')
time=$(TZ=GMT date -d @$time +"%Y%m%d%H%M")
tx=$(dash-cli getrawtransaction $txhash 1)
length=$(jq '.vout|length'<<<"$tx")
for ((i=0; i<length; i++));do
addresses=$(jq ".vout[$i].scriptPubKey.addresses"<<<"$tx")
for ((j=0; j<"${#ADDRESS[*]}"; j++));do
grep -q "${ADDRESS[$j]}"<<<"$addresses"
if [ $? -eq 0 ];then
# A match has been found!
valueDASH=$(jq ".vout[$i].value"<<<"$tx")
echo "${ADDRESS[$j]},${DESC[$j]},$time,$block,$txhash,$valueDASH"
fi
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment