Advertisement
Guest User

Seeded Nu Auctions

a guest
Jun 6th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  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:%[email protected]:%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:%[email protected]:%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. try:
  23.  endblk = input('Enter Block Height of Auction Close: ')
  24.  blkcnt = rpc.getblockcount()
  25.  confirm = blkcnt - endblk
  26.  print "Auction ended ",confirm," blocks ago"
  27. except:
  28.  print "Please enter a 6 or 7 digit number like '384498'"
  29.  sys.exit(1)
  30.  
  31. receivednbt = rpc.listunspent(confirm)
  32. receivednsr = nsrrpc.listunspent(confirm)
  33.  
  34. nbttotal=0
  35. nsrtotal=0
  36. usersnbt = {}
  37. usersnsr = {}
  38.  
  39. for i in range(0,len(receivednbt)):
  40.  packet = receivednbt[i]
  41.  nbttotal = nbttotal + packet['amount']
  42.  
  43. for i in range(0,len(receivednsr)):
  44.  packet = receivednsr[i]
  45.  nsrtotal = nsrtotal + packet['amount']
  46.  
  47. print 'total nbt:',nbttotal
  48. print 'total nsr:',nsrtotal
  49.  
  50. price = max(nbttotal,0.001) / max(nsrtotal,1)
  51. print 'price:',price
  52.  
  53. for i in range(1,len(receivednbt)):
  54.  packet = receivednbt[i]
  55.  txid=packet['txid']
  56.  tx=rpc.gettransaction(txid)
  57.  trim=tx['details'][0]
  58.  addy = trim['address']
  59.  if not addy in usersnbt:
  60.   usersnbt[addy] = packet['amount']/price
  61.  else:
  62.   usersnbt[addy] =  usersnbt[addy] + packet['amount']/price
  63.  
  64. for i in range(1,len(receivednsr)):
  65.  packet = receivednsr[i]
  66.  txid=packet['txid']
  67.  tx=nsrrpc.gettransaction(txid)
  68.  trim=tx['details'][0]
  69.  addy = trim['address']
  70.  if not addy in usersnsr:
  71.   usersnsr[addy] = packet['amount']*price
  72.  else:
  73.   usersnsr[addy] =  usersnsr[addy] + packet['amount']*price
  74.  
  75. outnbt = {}
  76. for addr in usersnbt:
  77.   outnbt[addr] = float("%.8f" % usersnbt[addr])
  78. print jsonrpc.dumps(outnbt).replace(' ', '')
  79.  
  80. outnsr = {}
  81. for addr in usersnsr:
  82.   outnsr[addr] = float("%.8f" % usersnsr[addr])
  83. print jsonrpc.dumps(outnsr).replace(' ', '')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement