tzeromq: Transaction broadcasting. - electrum - Electrum Bitcoin wallet
 (HTM) git clone https://git.parazyd.org/electrum
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
       ---
 (DIR) commit 8c84ffe6af24cf3bf1c08ee67413965ad7c58a1d
 (DIR) parent 28ec2b6be35f4d2e8dfdfbc33200ffa31478ecae
 (HTM) Author: parazyd <parazyd@dyne.org>
       Date:   Fri, 12 Mar 2021 22:15:27 +0100
       
       zeromq: Transaction broadcasting.
       
       Diffstat:
         M electrum/interface.py               |       6 ++++++
         M electrum/network.py                 |      22 +++++-----------------
         M electrum/zeromq.py                  |       8 +++++++-
       
       3 files changed, 18 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/electrum/interface.py b/electrum/interface.py
       t@@ -901,6 +901,12 @@ class Interface(Logger):
                    res = int(res * bitcoin.COIN)
                return res
        
       +    async def broadcast_transaction(self, tx, timeout=None):
       +        """Broadcasts given transaction"""
       +        __("Interface: broadcast_transaction")
       +        assert_hex_str(tx)
       +        return await self.client.broadcast_transaction(tx)
       +
        
        def _assert_header_does_not_check_against_any_chain(header: dict) -> None:
            __("Interface: _assert_header_does_not_check_against_any_chain")
 (DIR) diff --git a/electrum/network.py b/electrum/network.py
       t@@ -881,22 +881,10 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
            async def broadcast_transaction(self, tx: 'Transaction', *, timeout=None) -> None:
                if timeout is None:
                    timeout = self.get_network_timeout_seconds(NetworkTimeout.Urgent)
       -        try:
       -            # TODO: libbitcoin
       -            out = await self.interface.session.send_request('blockchain.transaction.broadcast', [tx.serialize()], timeout=timeout)
       -            # note: both 'out' and exception messages are untrusted input from the server
       -        except (RequestTimedOut, asyncio.CancelledError, asyncio.TimeoutError):
       -            raise  # pass-through
       -        except aiorpcx.jsonrpc.CodeMessageError as e:
       -            self.logger.info(f"broadcast_transaction error [DO NOT TRUST THIS MESSAGE]: {repr(e)}")
       -            raise TxBroadcastServerReturnedError(self.sanitize_tx_broadcast_response(e.message)) from e
       -        except BaseException as e:  # intentional BaseException for sanity!
       -            self.logger.info(f"broadcast_transaction error2 [DO NOT TRUST THIS MESSAGE]: {repr(e)}")
       -            send_exception_to_crash_reporter(e)
       -            raise TxBroadcastUnknownError() from e
       -        if out != tx.txid():
       -            self.logger.info(f"unexpected txid for broadcast_transaction [DO NOT TRUST THIS MESSAGE]: {out} != {tx.txid()}")
       -            raise TxBroadcastHashMismatch(_("Server returned unexpected transaction ID."))
       +        # TODO: libbitcoin
       +        _ec = await self.interface.broadcast_transaction(tx.serialize(), timeout=timeout)
       +        if _ec != 0:
       +            raise TxBroadcastServerReturnedError(f"not validated, error: {_ec!r}")
        
            async def try_broadcasting(self, tx, name):
                try:
       t@@ -1346,7 +1334,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
                        await interface.close()
                        return
                    try:
       -                # TODO: libbitcoin
       +                # TODO: libbitcoin XXX:
                        res = await interface.session.send_request(method, params, timeout=10)
                    except Exception as e:
                        res = e
 (DIR) diff --git a/electrum/zeromq.py b/electrum/zeromq.py
       t@@ -400,6 +400,12 @@ class Client:
                    return error_code, None
                return None, data
        
       +    async def broadcast_transaction(self, rawtx):
       +        __("Zeromq Client: broadcast_transaction")
       +        __(rawtx)
       +        command = b'transaction_pool.broadcast'
       +        return await self._simple_request(command, unhexlify(rawtx))
       +
            async def history4(self, scripthash, height=0):
                __("Zeromq Client: history4")
                command = b'blockchain.fetch_history4'
       t@@ -413,7 +419,7 @@ class Client:
                    kind, tx_hash, index, height, value = row
                    return (
                        kind,
       -                #COutPoint(tx_hash, index),
       +                #COutPoint(tx_hash, index),  # TODO: libbitcoin XXX:
                        (tx_hash, index),
                        height,
                        value,