Skip to content

Instantly share code, notes, and snippets.

@lorepozo
Created March 31, 2017 19:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lorepozo/eadd6340ac1a96ad85ca8a09caf9f497 to your computer and use it in GitHub Desktop.
Save lorepozo/eadd6340ac1a96ad85ca8a09caf9f497 to your computer and use it in GitHub Desktop.
zbalance: quickly get your zcash addresses (taddr and zaddr) and their balances
#!/bin/sh
# zbalance: quickly get your zcash addresses (taddr and zaddr) and their balances.
# REQUIRES zcash-cli (https://z.cash) AND jq (https://stedolan.github.io/jq)
zaddr_withbalance () {
while read a
do echo $(zcash-cli z_getbalance $a) $a
done
}
taddr_withbalance () {
unspent=$(zcash-cli listunspent | jq -r '.[] | "\(.amount) \(.address)"')
while read a
do
row=$(echo $unspent | grep " $a\$")
if test $? -eq 0
then echo $row
else echo 0 $a
fi
done
}
getbalances () {
( zcash-cli listreceivedbyaddress 0 true | jq -r '.[] | .address' ; \
zcash-cli listunspent | jq -r '.[] | .address' ) \
| sort -u | taddr_withbalance
zcash-cli z_listaddresses | jq -r '.[]' | zaddr_withbalance
}
prettybalances () {
while read line
do
bal=$( echo $line | cut -d' ' -f1)
addr=$(echo $line | cut -d' ' -f2)
echo $(printf %.8f $bal) $addr
done
}
getbalances | prettybalances
@lorepozo
Copy link
Author

See lucasem/cryptocurrency-things for an up-to-date version.

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