Advertisement
Guest User

Untitled

a guest
May 21st, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.08 KB | None | 0 0
  1. from rpc_connection import RPC_Connection
  2. import math
  3. import time
  4. import datetime
  5.  
  6. if __name__ == '__main__':
  7.     server = 1
  8.     rpcuser = "rpcUserName"
  9.     rpcpassword = "rpcPassword"
  10.  
  11.     rpcport = 22555
  12.     port = 22556
  13.  
  14.     # set to 0 to reduce output
  15.     verbose = 1
  16.  
  17.     rpc = RPC_Connection(rpcuser, rpcpassword, "127.0.0.1", rpcport)
  18.  
  19.     # get current block to start
  20.     currentheight = 0
  21.     currentheight = rpc.command("getblockcount")
  22.  
  23.     #     1 block = 1 minute
  24.     #   60 blocks = 1 hour
  25.     # 1440 blocks = 1 day
  26.  
  27.     # define how much data you want to have
  28.     countLoop = 1 #1440
  29.     actLoop = 0
  30.     isCoinbase = 0
  31.     while (actLoop < countLoop):
  32.         # get the hash of the block height
  33.         currenthash = ""
  34.         currenthash = rpc.command("getblockhash", params=[currentheight])
  35.  
  36.         data = rpc.command("getblock", params=[currenthash])
  37.         if verbose == 1:
  38.             print ("Block hash: " + str(data))
  39.  
  40.         inSum = 0
  41.         outSum = 0
  42.         ageSum = 0
  43.         dustPenality = 0
  44.         # get the TXs of the block
  45.         for t in data["tx"]:
  46.             rawTx = rpc.command("getrawtransaction", params=[t])
  47.             Tx = rpc.command("decoderawtransaction", params=[rawTx])
  48.  
  49.             # get the inputs of the transaction
  50.             inCount = 0
  51.             avgConf = 0
  52.             for i in Tx["vin"]:
  53.                 try:
  54.                     #print("input: " + str(i["txid"]) + " (" + str(i["vout"]) +")")
  55.                     # ,1 is for verbose to get the block hash and calculate the age (confirmations)
  56.                     inCount = inCount +1
  57.                     rawTxIn = rpc.command("getrawtransaction", params=[i["txid"],1])
  58.                     #print (rawTxIn)
  59.                     #print("Confirmations: " + str(rawTxIn["confirmations"]))
  60.                     avgConf = avgConf + rawTxIn["confirmations"]
  61.                     TxIn = rpc.command("decoderawtransaction", params=[rawTxIn["hex"]])
  62.                     #print (TxIn)
  63.                     #print (TxIn["vout"])
  64.                     for l in TxIn["vout"]:
  65.                         if l["n"] == i["vout"]:
  66.                             #print (l["value"])
  67.                             inSum = inSum + l["value"]
  68.                             # "confirmations and transaction value are multiplied to calculate the output age" -- opreturn_net
  69.                             ageSum = ageSum + (l["value"] * rawTxIn["confirmations"])
  70.                 except:
  71.                     #print ("input: coinbase")
  72.                     isCoinbase = 1
  73.  
  74.             avgConf = avgConf / inCount
  75.             inCount = 0
  76.             for o in Tx["vout"]:
  77.                 #print("value: " + str(o["value"]))
  78.                 outSum = outSum + o["value"]
  79.                 if o["value"] < 1:
  80.                     dustPenality = dustPenality +1
  81.                     # 1 Doge fee per dust
  82.             print("==================")
  83.             print("Tran:     " + str(Tx["txid"]))
  84.             if isCoinbase == 1:
  85.                 print("input:    coinbase")
  86.             if isCoinbase == 0:
  87.                 fee = inSum - outSum
  88.  
  89.                 print("Size:     "+str(Tx["size"]))
  90.                 print("InSum:    "+str(inSum))
  91.                 print("OutSum:   "+str(outSum))
  92.                 print("Fee:      "+str(fee))
  93.                 print("Age:      "+str(ageSum))
  94.                 print("Avg Conf: "+str(avgConf))
  95.                 newFee = 0
  96.                 if avgConf < 1000:
  97.                     newFee = 1
  98.                 elif 1000 >= avgConf < 10000:
  99.                     newFee = 0.1
  100.                 else:
  101.                     newFee = 0.01
  102.  
  103.                 #1 doge <1000 conf >0.1 doge <10,000 conf > 0.01 doge <100,000 conf
  104.                 print("New Fee:  "+str(newFee))
  105.                 bestFee = math.ceil(Tx["size"] / 1000)+dustPenality
  106.                 print("Best Fee: " + str(bestFee))
  107.  
  108.             inSum = 0
  109.             outSum = 0
  110.             ageSum = 0
  111.             isCoinbase = 0
  112.             dustPenality = 0
  113.  
  114.         currentheight = currentheight -1
  115.         actLoop = actLoop +1
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement