1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-24 15:02:21 +01:00
electrs/contrib/tx_fee.py
2021-04-14 18:38:59 +03:00

23 lines
714 B
Python
Executable file

#!/usr/bin/env python3
import argparse
import client
def main():
parser = argparse.ArgumentParser()
parser.add_argument("txid")
args = parser.parse_args()
conn = client.Client(("localhost", 50001))
tx = conn.call("blockchain.transaction.get", args.txid, True)["result"]
fee = 0
for vin in tx["vin"]:
prev_txid = vin["txid"]
prev_tx = conn.call("blockchain.transaction.get", prev_txid, True)["result"]
txo = prev_tx["vout"][vin["vout"]]
fee += txo["value"]
fee -= sum(vout["value"] for vout in tx["vout"])
print(f'vSize = {tx["vsize"]}, Fee = {1e3 * fee:.2f} mBTC = {1e8 * fee / tx["vsize"]:.2f} sat/vB')
if __name__ == "__main__":
main()