signed.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.signed: THORChain signed transaction class
  12. """
  13. from ....tx import signed as TxBase
  14. from ....obj import CoinTxID, NonNegativeInt
  15. from .completed import Completed
  16. class Signed(Completed, TxBase.Signed):
  17. desc = 'signed transaction'
  18. def parse_txfile_serialized_data(self):
  19. from .protobuf import RuneTx
  20. tx = RuneTx.loads(bytes.fromhex(self.serialized))
  21. b = tx.body.messages[0].body
  22. i = tx.authInfo
  23. from_k, amt_k = ('signer', 'coins') if self.is_swap else ('fromAddress', 'amount')
  24. self.txobj = {
  25. 'from': self.proto.encode_addr_bech32x(getattr(b, from_k)),
  26. 'to': None if self.is_swap else self.proto.encode_addr_bech32x(b.toAddress),
  27. 'amt': self.proto.coin_amt(int(getattr(b, amt_k)[0].amount), from_unit='satoshi'),
  28. 'gas': NonNegativeInt(i.fee.gasLimit),
  29. 'sequence': NonNegativeInt(i.signerInfos[0].sequence)}
  30. txid = CoinTxID(tx.txid)
  31. assert txid == self.coin_txid, 'serialized txid doesn’t match txid in MMGen transaction file'
  32. class AutomountSigned(TxBase.AutomountSigned, Signed):
  33. pass