daily pastebin goal
58%
SHARE
TWEET

Seeded Auctions

a guest Jun 6th, 2015 219 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3. import jsonrpc
  4. import sys, os
  5.  
  6. NUCONFIG='%s/.nu/nu.conf'%os.getenv("HOME")
  7. opts = dict(tuple(line.strip().replace(' ','').split('=')) for line in open(NUCONFIG).readlines())
  8. try:
  9.   rpc = jsonrpc.ServiceProxy("http://%s:%s@127.0.0.1:%s"%(
  10.     opts['rpcuser'],opts['rpcpassword'],opts.pop('rpcport', 14002)))
  11. except:
  12.   print "could not connect to daemon"
  13.   sys.exit(1)
  14.  
  15. try:
  16.   nsrrpc = jsonrpc.ServiceProxy("http://%s:%s@127.0.0.1:%s"%(
  17.     opts['rpcuser'],opts['rpcpassword'],opts.pop('rpcport', 14001)))
  18. except:
  19.   print "could not connect to daemon"
  20.   sys.exit(1)
  21.  
  22.  
  23. receivednbt = rpc.listunspent()
  24. receivednsr = nsrrpc.listunspent()
  25.  
  26. nbttotal=0
  27. nsrtotal=0
  28. usersnbt = {}
  29. usersnsr = {}
  30.  
  31. for i in range(1,len(receivednbt)):
  32.  packet = receivednbt[i]
  33.  nbttotal = nbttotal + packet['amount']
  34.  
  35. for i in range(1,len(receivednsr)):
  36.  packet = receivednsr[i]
  37.  nsrtotal = nsrtotal + packet['amount']
  38.  
  39. print 'total nbt:',nbttotal
  40. print 'total nsr:',nsrtotal
  41.  
  42. price = max(nbttotal,0.001) / max(nsrtotal,1)
  43. print 'price:',price
  44.  
  45. for i in range(1,len(receivednbt)):
  46.  packet = receivednbt[i]
  47.  txid=packet['txid']
  48.  tx=rpc.gettransaction(txid)
  49.  trim=tx['details'][0]
  50.  addy = trim['address']
  51.  if not addy in usersnbt:
  52.   usersnbt[addy] = packet['amount']/price
  53.  else:
  54.   usersnbt[addy] =  usersnbt[addy] + packet['amount']/price
  55.  
  56. for i in range(1,len(receivednsr)):
  57.  packet = receivednsr[i]
  58.  txid=packet['txid']
  59.  tx=nsrrpc.gettransaction(txid)
  60.  trim=tx['details'][0]
  61.  addy = trim['address']
  62.  if not addy in usersnsr:
  63.   usersnsr[addy] = packet['amount']*price
  64.  else:
  65.   usersnsr[addy] =  usersnsr[addy] + packet['amount']*price
  66.  
  67.  
  68. outnbt = {}
  69. for addr in usersnbt:
  70.   outnbt[addr] = float("%.8f" % usersnbt[addr])
  71. print jsonrpc.dumps(outnbt).replace(' ', '')
  72.  
  73. outnsr = {}
  74. for addr in usersnsr:
  75.   outnsr[addr] = float("%.8f" % usersnsr[addr])
  76. print jsonrpc.dumps(outnsr).replace(' ', '')
RAW Paste Data
Top