util.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. tx.util: transaction utilities
  12. """
  13. def get_autosign_obj(cfg, add_cfg={}):
  14. from ..cfg import Config
  15. from ..autosign import Autosign
  16. return Autosign(
  17. Config({
  18. '_clone': cfg,
  19. 'mountpoint': cfg.autosign_mountpoint,
  20. 'coins': cfg.coin,
  21. # used only in online environment (xmrwallet, txcreate, txsend, txbump):
  22. 'online': not cfg.offline} | add_cfg))
  23. def mount_removable_device(cfg, do_umount=True, asi=None, add_cfg={}, do_umount_registered=[]):
  24. asi = asi or get_autosign_obj(cfg, add_cfg=add_cfg)
  25. if not asi.device_inserted:
  26. from ..util import die
  27. die(1, 'Removable device not present!')
  28. if do_umount and not do_umount_registered:
  29. import atexit
  30. atexit.register(lambda: asi.do_umount())
  31. do_umount_registered.append(None)
  32. asi.do_mount()
  33. return asi