completed.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2024 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. self.__dict__ = data | {'twctl': self.twctl}
  24. self.name = type(self).__name__
  25. else:
  26. from .file import MMGenTxFile
  27. MMGenTxFile(self).parse(str(filename), quiet_open=quiet_open)
  28. self.check_serialized_integrity()
  29. # repeat with sign and send, because coin daemon could be restarted
  30. self.check_correct_chain()
  31. if self.check_sigs() != self.signed:
  32. from ..util import die
  33. die(1,'Transaction is {}signed!'.format('not ' if self.signed else ''))
  34. self.infile = filename
  35. @property
  36. def file(self):
  37. from .file import MMGenTxFile
  38. return MMGenTxFile(self)
  39. @classmethod
  40. def ext_to_cls(cls,ext,proto):
  41. """
  42. see twctl:import_token()
  43. """
  44. from .unsigned import Unsigned
  45. from .online import Sent
  46. for cls in (Unsigned, Sent):
  47. if ext == getattr(cls, 'ext'):
  48. return cls
  49. if proto.tokensym:
  50. from .online import OnlineSigned as Signed
  51. else:
  52. from .signed import Signed
  53. if ext == Signed.ext:
  54. return Signed