online.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. proto.rune.tx.online: THORChain online signed transaction class
  12. """
  13. from ....util import msg, pp_msg, die
  14. from ....tx import online as TxBase
  15. from .signed import Signed
  16. class OnlineSigned(Signed, TxBase.OnlineSigned):
  17. async def test_sendable(self, txhex):
  18. res = self.rpc.tx_op(txhex, op='check_tx')
  19. if res['code'] == 0:
  20. return True
  21. else:
  22. pp_msg(res)
  23. return False
  24. async def send_checks(self):
  25. pass
  26. async def send_with_node(self, txhex):
  27. res = self.rpc.tx_op(txhex, op='broadcast_tx_sync') # broadcast_tx_async
  28. if res['code'] == 0:
  29. return res['hash'].lower()
  30. else:
  31. pp_msg(res)
  32. die(2, 'Transaction send failed')
  33. async def post_network_send(self, coin_txid):
  34. return True
  35. async def get_receipt(self, txid, *, receipt_only=False):
  36. try:
  37. return self.rpc.get_tx_info(txid)
  38. except Exception as e:
  39. msg(f'{type(e).__name__}: {e}')
  40. return False
  41. class Sent(TxBase.Sent, OnlineSigned):
  42. pass
  43. class AutomountOnlineSigned(TxBase.AutomountOnlineSigned, OnlineSigned):
  44. pass
  45. class AutomountSent(TxBase.AutomountSent, AutomountOnlineSigned):
  46. pass