1
0
Files
electrum/electrum/scripts/txbroadcast.py
SomberNight 312f2641e7 don't use bare except
use "except Exception", or if really needed explicitly "except BaseException"
2023-04-24 12:58:01 +00:00

37 lines
953 B
Python

#!/usr/bin/env python3
#
# Connect to lots of servers and broadcast a given tx to each.
import sys
import asyncio
from electrum.network import filter_protocol, Network
from electrum.util import create_and_start_event_loop, log_exceptions
from electrum.simple_config import SimpleConfig
try:
rawtx = sys.argv[1]
except Exception:
print("usage: txbroadcast rawtx")
sys.exit(1)
config = SimpleConfig()
loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()
@log_exceptions
async def f():
try:
peers = await network.get_peers()
peers = filter_protocol(peers)
results = await network.send_multiple_requests(peers, 'blockchain.transaction.broadcast', [rawtx])
for server, resp in results.items():
print(f"result: server={server}, response={resp}")
finally:
stopping_fut.set_result(1)
asyncio.run_coroutine_threadsafe(f(), loop)