From 1c5e8ad5816830a0003447d74872578c5b250bd0 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 13 Oct 2023 09:51:13 +0000 Subject: [PATCH] proto.btc.tx.online.Signed.sign(): cleanup error handling --- mmgen/proto/btc/tx/online.py | 55 +++++++++++++++++------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/mmgen/proto/btc/tx/online.py b/mmgen/proto/btc/tx/online.py index 847ff0c8..5da30753 100755 --- a/mmgen/proto/btc/tx/online.py +++ b/mmgen/proto/btc/tx/online.py @@ -42,42 +42,39 @@ class OnlineSigned(Signed,TxBase.OnlineSigned): self.confirm_send() if self.cfg.bogus_send: - ret = None + m = 'BOGUS transaction NOT sent: {}' else: + m = 'Transaction sent: {}' try: ret = await self.rpc.call('sendrawtransaction',self.serialized) except Exception as e: errmsg = str(e) - ret = False - - if ret is False: # TODO: test send errors - if errmsg.count('Signature must use SIGHASH_FORKID'): - m = ('The Aug. 1 2017 UAHF has activated on this chain.\n' - + 'Re-run the script with the --coin=bch option.' ) - elif errmsg.count('Illegal use of SIGHASH_FORKID'): - m = ('The Aug. 1 2017 UAHF is not yet active on this chain.\n' - + 'Re-run the script without the --coin=bch option.' ) - elif errmsg.count('64: non-final'): - m = "Transaction with nLockTime {!r} can't be included in this block!".format( - self.strfmt_locktime(self.get_serialized_locktime()) ) + if errmsg.count('Signature must use SIGHASH_FORKID'): + m = ( + 'The Aug. 1 2017 UAHF has activated on this chain.\n' + 'Re-run the script with the --coin=bch option.') + elif errmsg.count('Illegal use of SIGHASH_FORKID'): + m = ( + 'The Aug. 1 2017 UAHF is not yet active on this chain.\n' + 'Re-run the script without the --coin=bch option.') + elif errmsg.count('64: non-final'): + m = "Transaction with nLockTime {!r} can't be included in this block!".format( + self.strfmt_locktime(self.get_serialized_locktime())) + else: + m = errmsg + ymsg(m) + rmsg(f'Send of MMGen transaction {self.txid} failed') + if exit_on_fail: + sys.exit(1) + return False else: - m = errmsg - ymsg(m) - rmsg(f'Send of MMGen transaction {self.txid} failed') - if exit_on_fail: - sys.exit(1) - return False - else: - if self.cfg.bogus_send: - m = 'BOGUS transaction NOT sent: {}' - else: - m = 'Transaction sent: {}' assert ret == self.coin_txid, 'txid mismatch (after sending)' - msg(m.format(self.coin_txid.hl())) - self.add_timestamp() - self.add_blockcount() - self.desc = 'sent transaction' - return True + + msg(m.format(self.coin_txid.hl())) + self.add_timestamp() + self.add_blockcount() + self.desc = 'sent transaction' + return True def print_contract_addr(self): pass