bump.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based 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. proto.btc.tx.bump: Bitcoin transaction bump class
  12. """
  13. from ....tx import bump as TxBase
  14. from ....util import msg
  15. from .new import New
  16. from .completed import Completed
  17. from .unsigned import AutomountUnsigned
  18. class Bump(Completed,New,TxBase.Bump):
  19. desc = 'fee-bumped transaction'
  20. @property
  21. def min_fee(self):
  22. return self.sum_inputs() - self.sum_outputs() + self.relay_fee
  23. def bump_fee(self,idx,fee):
  24. self.update_output_amt(
  25. idx,
  26. self.sum_inputs() - self.sum_outputs(exclude=idx) - fee
  27. )
  28. def convert_and_check_fee(self,fee,desc):
  29. ret = super().convert_and_check_fee(fee,desc)
  30. if ret is False:
  31. return ret
  32. if ret < self.min_fee:
  33. msg('{} {c}: {} fee too small. Minimum fee: {} {c} ({} {})'.format(
  34. ret.hl(),
  35. desc,
  36. self.min_fee,
  37. self.fee_abs2rel(self.min_fee),
  38. self.rel_fee_desc,
  39. c = self.coin ))
  40. return False
  41. output_amt = self.outputs[self.bump_output_idx].amt
  42. if ret >= output_amt:
  43. msg('{} {c}: {} fee too large. Maximum fee: <{} {c}'.format(
  44. ret.hl(),
  45. desc,
  46. output_amt.hl(),
  47. c = self.coin ))
  48. return False
  49. return ret
  50. class AutomountBump(Bump):
  51. desc = 'unsigned fee-bumped automount transaction'
  52. ext = AutomountUnsigned.ext
  53. automount = AutomountUnsigned.automount