Skip to content

Instantly share code, notes, and snippets.

@rocket-pig
Last active November 8, 2019 06:41
Show Gist options
  • Save rocket-pig/3f21bf82ba1e1f9d5b8a03f31cd126e1 to your computer and use it in GitHub Desktop.
Save rocket-pig/3f21bf82ba1e1f9d5b8a03f31cd126e1 to your computer and use it in GitHub Desktop.
Check if your navcoind's best block hash matches chainz and navexplorer sites. Output some stats about recent staking.
#!/usr/bin/python3
import requests
import subprocess
import json
# Check local best block hash against api.navexplorer.com's best hash.
# 'navcoin-cli' needs to be in your PATH, and obvs navexplorer.com has to be up.
def api_get(endpoint):
resp = requests.get('https://api.navexplorer.com/api/'+str(endpoint))
if resp.status_code != 200:
# This means something went wrong.
raise ApiError('GET /api/ {}'.format(resp.status_code))
return resp.json()
def chainz_get(height):
resp = requests.get('https://chainz.cryptoid.info/nav/api.dws?q=getblockhash&height='+str(height))
if resp.status_code != 200:
# This means something went wrong.
raise ApiError('GET /api/ {}'.format(resp.status_code))
return resp.json()
def navcoin_cli(command,arg=None):
if arg != None:
process = subprocess.Popen(['navcoin-cli',command,arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if arg == None:
process = subprocess.Popen(['navcoin-cli',command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
o=out.decode(encoding="utf-8").replace("\n","")
return(o)
#show balance.
balance = subprocess.getoutput("navcoin-cli getwalletinfo | jq .balance")
print("balance: "+str(balance))
#stakes since last run:
db = open('amiforked.db','r')
oldbal = db.read()
db.close()
print("Bal+ since last run: "+str(float(balance)-float(oldbal)))
#save this run's balance for next time.
db = open('amiforked.db','w')
db.write(balance)
db.close()
# 7-day total navs from stake (Not total stakes).
weekly_total = subprocess.getoutput("""navcoin-cli getstakereport | jq '.["Last 7 Days"]'""")
print("Weekly Total: "+str(weekly_total))
#get orphan info:
orphans=subprocess.getoutput('navcoin-cli listtransactions "*" 1000 0 true | grep -A 5 -B 5 orphan')
if len(orphans) == 0:
orphans = '0'
print("Orphans: "+str(orphans))
si=json.loads(navcoin_cli('getstakinginfo'))
print("staking: "+str(si['staking']))
bestblock=str(api_get('bestblock'))
bestblockhash=api_get('block/'+bestblock)['hash']
chainz_bestblockhash=chainz_get(bestblock)
local_bestblockhash=navcoin_cli('getblockhash',bestblock)
print("Hash of block "+str(bestblock)+":")
print("local:\t\t"+bestblockhash)
print("navex:\t\t"+local_bestblockhash)
print("chainz:\t\t"+chainz_bestblockhash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment