1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 01:43:29 +01:00
electrs/contrib/tx_fee.py

24 lines
714 B
Python
Raw Normal View History

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))
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"])
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()