2019-08-03 13:46:39 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
2021-03-26 09:05:58 +01:00
|
|
|
import client
|
2019-08-03 13:46:39 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
2021-03-26 09:05:58 +01:00
|
|
|
parser.add_argument("txid")
|
2019-08-03 13:46:39 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
conn = client.Client(("localhost", 50001))
|
2021-06-13 13:57:55 +02:00
|
|
|
tx, = conn.call([client.request("blockchain.transaction.get", args.txid, True)])
|
2021-05-21 12:56:04 +02:00
|
|
|
requests = []
|
2021-03-26 09:05:58 +01:00
|
|
|
for vin in tx["vin"]:
|
|
|
|
prev_txid = vin["txid"]
|
2021-06-13 13:57:55 +02:00
|
|
|
requests.append(client.request("blockchain.transaction.get", prev_txid, True))
|
2021-05-21 12:56:04 +02:00
|
|
|
|
|
|
|
fee = 0
|
2021-06-13 13:57:55 +02:00
|
|
|
for vin, prev_tx in zip(tx["vin"], conn.call(requests)):
|
2021-03-26 09:05:58 +01:00
|
|
|
txo = prev_tx["vout"][vin["vout"]]
|
|
|
|
fee += txo["value"]
|
2021-05-21 12:56:04 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
fee -= sum(vout["value"] for vout in tx["vout"])
|
2019-08-03 13:46:39 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
print(f'vSize = {tx["vsize"]}, Fee = {1e3 * fee:.2f} mBTC = {1e8 * fee / tx["vsize"]:.2f} sat/vB')
|
2019-08-03 13:46:39 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
if __name__ == "__main__":
|
2019-08-03 13:46:39 +02:00
|
|
|
main()
|