commit 4937fd2788211e2c20f31a6e8b5cdbf965de0c6b
parent 26d73cba0ee6ad8e07ba2262dc716a8658863899
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 23 Feb 2021 04:19:47 +0100
scripts: add script that broadcasts tx to lots of servers
useful when trying to RBF a tx that did not opt-in to RBF
Diffstat:
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/electrum/scripts/txbroadcast.py b/electrum/scripts/txbroadcast.py
@@ -0,0 +1,36 @@
+#!/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:
+ 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)