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

29 lines
859 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()
parser.add_argument('--host', default='localhost')
2021-03-26 09:05:58 +01:00
parser.add_argument("txid")
2019-08-03 13:46:39 +02:00
args = parser.parse_args()
conn = client.Client((args.host, 50001))
tx, = conn.call([client.request("blockchain.transaction.get", args.txid, True)])
requests = []
2021-03-26 09:05:58 +01:00
for vin in tx["vin"]:
prev_txid = vin["txid"]
requests.append(client.request("blockchain.transaction.get", prev_txid, True))
fee = 0
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-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()