From e223a776d8b99ad09b147017abdba0c9c2ec9fa5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 27 Oct 2022 16:45:56 +0000 Subject: [PATCH] minor addition and cleanups --- mmgen/proto/btc/tx/base.py | 12 ++++++------ mmgen/protocol.py | 9 ++++----- mmgen/util.py | 5 +++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mmgen/proto/btc/tx/base.py b/mmgen/proto/btc/tx/base.py index cb3155a7..7a8c31dc 100755 --- a/mmgen/proto/btc/tx/base.py +++ b/mmgen/proto/btc/tx/base.py @@ -239,12 +239,12 @@ class Base(TxBase.Base): wsize = get_witness_size() # TODO: compute real varInt sizes instead of assuming 1 byte - # old serialization: [nVersion] [vInt][txins][vInt][txouts] [nLockTime] - old_size = 4 + 1 + isize + 1 + osize + 4 - # marker = 0x00, flag = 0x01 - # new serialization: [nVersion][marker][flag][vInt][txins][vInt][txouts][witness][nLockTime] - new_size = 4 + 1 + 1 + 1 + isize + 1 + osize + wsize + 4 \ - if wsize else old_size + # Serialization: + # old: [nVersion] [vInt][txins][vInt][txouts] [nLockTime] + old_size = 4 + 1 + isize + 1 + osize + 4 + # marker = 0x00, flag = 0x01 + # new: [nVersion][marker][flag][vInt][txins][vInt][txouts][witness][nLockTime] + new_size = 4 + 1 + 1 + 1 + isize + 1 + osize + wsize + 4 if wsize else old_size ret = (old_size * 3 + new_size) // 4 diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 494843fe..30c65d75 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -100,12 +100,11 @@ class CoinProtocol(MMGenObject): if need_amt: import mmgen.amt - setattr( self, 'coin_amt', getattr(mmgen.amt,self.coin_amt) ) - fee = getattr(self,'max_tx_fee',None) - setattr( self, 'max_tx_fee', (self.coin_amt(fee) if fee else None) ) + self.coin_amt = getattr(mmgen.amt,self.coin_amt) + self.max_tx_fee = self.coin_amt(self.max_tx_fee) if hasattr(self,'max_tx_fee') else None else: - setattr( self, 'coin_amt', None ) - setattr( self, 'max_tx_fee', None ) + self.coin_amt = None + self.max_tx_fee = None @property def dcoin(self): diff --git a/mmgen/util.py b/mmgen/util.py index 60d599ed..0f1ffad9 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -289,6 +289,11 @@ def is_int(s): except: return False +def check_int_between(val,imin,imax,desc): + if not imin <= int(val) <= imax: + die(1,f'{val}: invalid value for {desc} (must be between {imin} and {imax})') + return int(val) + def is_hex_str(s): return set(s) <= set(hexdigits)