Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import jsonrpc
- import sys, os
- NUCONFIG='%s/.nu/nu.conf'%os.getenv("HOME")
- opts = dict(tuple(line.strip().replace(' ','').split('=')) for line in open(NUCONFIG).readlines())
- try:
- opts['rpcuser'],opts['rpcpassword'],opts.pop('rpcport', 14002)))
- except:
- print "could not connect to daemon"
- sys.exit(1)
- try:
- opts['rpcuser'],opts['rpcpassword'],opts.pop('rpcport', 14001)))
- except:
- print "could not connect to daemon"
- sys.exit(1)
- try:
- endblk = input('Enter Block Height of Auction Close: ')
- blkcnt = rpc.getblockcount()
- confirm = blkcnt - endblk
- print "Auction ended ",confirm," blocks ago"
- except:
- print "Please enter a 6 or 7 digit number like '384498'"
- sys.exit(1)
- receivednbt = rpc.listunspent(confirm)
- receivednsr = nsrrpc.listunspent(confirm)
- nbttotal=0
- nsrtotal=0
- usersnbt = {}
- usersnsr = {}
- for i in range(0,len(receivednbt)):
- packet = receivednbt[i]
- nbttotal = nbttotal + packet['amount']
- for i in range(0,len(receivednsr)):
- packet = receivednsr[i]
- nsrtotal = nsrtotal + packet['amount']
- print 'total nbt:',nbttotal
- print 'total nsr:',nsrtotal
- price = max(nbttotal,0.001) / max(nsrtotal,1)
- print 'price:',price
- for i in range(1,len(receivednbt)):
- packet = receivednbt[i]
- txid=packet['txid']
- tx=rpc.gettransaction(txid)
- trim=tx['details'][0]
- addy = trim['address']
- if not addy in usersnbt:
- usersnbt[addy] = packet['amount']/price
- else:
- usersnbt[addy] = usersnbt[addy] + packet['amount']/price
- for i in range(1,len(receivednsr)):
- packet = receivednsr[i]
- txid=packet['txid']
- tx=nsrrpc.gettransaction(txid)
- trim=tx['details'][0]
- addy = trim['address']
- if not addy in usersnsr:
- usersnsr[addy] = packet['amount']*price
- else:
- usersnsr[addy] = usersnsr[addy] + packet['amount']*price
- outnbt = {}
- for addr in usersnbt:
- outnbt[addr] = float("%.8f" % usersnbt[addr])
- print jsonrpc.dumps(outnbt).replace(' ', '')
- outnsr = {}
- for addr in usersnsr:
- outnsr[addr] = float("%.8f" % usersnsr[addr])
- print jsonrpc.dumps(outnsr).replace(' ', '')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement