Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from rpc_connection import RPC_Connection
- import math
- import time
- import datetime
- if __name__ == '__main__':
- server = 1
- rpcuser = "rpcUserName"
- rpcpassword = "rpcPassword"
- rpcport = 22555
- port = 22556
- # set to 0 to reduce output
- verbose = 1
- rpc = RPC_Connection(rpcuser, rpcpassword, "127.0.0.1", rpcport)
- # get current block to start
- currentheight = 0
- currentheight = rpc.command("getblockcount")
- # 1 block = 1 minute
- # 60 blocks = 1 hour
- # 1440 blocks = 1 day
- # define how much data you want to have
- countLoop = 1 #1440
- actLoop = 0
- isCoinbase = 0
- while (actLoop < countLoop):
- # get the hash of the block height
- currenthash = ""
- currenthash = rpc.command("getblockhash", params=[currentheight])
- data = rpc.command("getblock", params=[currenthash])
- if verbose == 1:
- print ("Block hash: " + str(data))
- inSum = 0
- outSum = 0
- ageSum = 0
- dustPenality = 0
- # get the TXs of the block
- for t in data["tx"]:
- rawTx = rpc.command("getrawtransaction", params=[t])
- Tx = rpc.command("decoderawtransaction", params=[rawTx])
- # get the inputs of the transaction
- inCount = 0
- avgConf = 0
- for i in Tx["vin"]:
- try:
- #print("input: " + str(i["txid"]) + " (" + str(i["vout"]) +")")
- # ,1 is for verbose to get the block hash and calculate the age (confirmations)
- inCount = inCount +1
- rawTxIn = rpc.command("getrawtransaction", params=[i["txid"],1])
- #print (rawTxIn)
- #print("Confirmations: " + str(rawTxIn["confirmations"]))
- avgConf = avgConf + rawTxIn["confirmations"]
- TxIn = rpc.command("decoderawtransaction", params=[rawTxIn["hex"]])
- #print (TxIn)
- #print (TxIn["vout"])
- for l in TxIn["vout"]:
- if l["n"] == i["vout"]:
- #print (l["value"])
- inSum = inSum + l["value"]
- # "confirmations and transaction value are multiplied to calculate the output age" -- opreturn_net
- ageSum = ageSum + (l["value"] * rawTxIn["confirmations"])
- except:
- #print ("input: coinbase")
- isCoinbase = 1
- avgConf = avgConf / inCount
- inCount = 0
- for o in Tx["vout"]:
- #print("value: " + str(o["value"]))
- outSum = outSum + o["value"]
- if o["value"] < 1:
- dustPenality = dustPenality +1
- # 1 Doge fee per dust
- print("==================")
- print("Tran: " + str(Tx["txid"]))
- if isCoinbase == 1:
- print("input: coinbase")
- if isCoinbase == 0:
- fee = inSum - outSum
- print("Size: "+str(Tx["size"]))
- print("InSum: "+str(inSum))
- print("OutSum: "+str(outSum))
- print("Fee: "+str(fee))
- print("Age: "+str(ageSum))
- print("Avg Conf: "+str(avgConf))
- newFee = 0
- if avgConf < 1000:
- newFee = 1
- elif 1000 >= avgConf < 10000:
- newFee = 0.1
- else:
- newFee = 0.01
- #1 doge <1000 conf >0.1 doge <10,000 conf > 0.01 doge <100,000 conf
- print("New Fee: "+str(newFee))
- bestFee = math.ceil(Tx["size"] / 1000)+dustPenality
- print("Best Fee: " + str(bestFee))
- inSum = 0
- outSum = 0
- ageSum = 0
- isCoinbase = 0
- dustPenality = 0
- currentheight = currentheight -1
- actLoop = actLoop +1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement