completed.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2023 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. tx.completed: completed transaction class
  12. """
  13. from .base import Base
  14. class Completed(Base):
  15. """
  16. signed or unsigned transaction with associated file
  17. """
  18. filename_api = True
  19. def __init__(self,cfg,*args,filename=None,data=None,quiet_open=False,**kwargs):
  20. assert (filename or data) and not (filename and data), 'CompletedTX_chk1'
  21. super().__init__(cfg=cfg,*args,**kwargs)
  22. if data:
  23. data['twctl'] = self.twctl
  24. self.__dict__ = data
  25. self.name = type(self).__name__
  26. else:
  27. from .file import MMGenTxFile
  28. MMGenTxFile(self).parse(filename,quiet_open=quiet_open)
  29. self.check_serialized_integrity()
  30. # repeat with sign and send, because coin daemon could be restarted
  31. self.check_correct_chain()
  32. if self.check_sigs() != self.signed:
  33. from ..util import die
  34. die(1,'Transaction is {}signed!'.format('not ' if self.signed else ''))
  35. @property
  36. def info(self):
  37. from .info import init_info
  38. return init_info(self)
  39. @property
  40. def file(self):
  41. from .file import MMGenTxFile
  42. return MMGenTxFile(self)
  43. @classmethod
  44. def ext_to_cls(cls,ext,proto):
  45. """
  46. see twctl:import_token()
  47. """
  48. from .unsigned import Unsigned
  49. if ext == Unsigned.ext:
  50. return Unsigned
  51. if proto.tokensym:
  52. from .online import OnlineSigned as Signed
  53. else:
  54. from .signed import Signed
  55. if ext == Signed.ext:
  56. return Signed