Browse Source

minor addition and cleanups

The MMGen Project 2 years ago
parent
commit
e223a776d8
3 changed files with 15 additions and 11 deletions
  1. 6 6
      mmgen/proto/btc/tx/base.py
  2. 4 5
      mmgen/protocol.py
  3. 5 0
      mmgen/util.py

+ 6 - 6
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
 

+ 4 - 5
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):

+ 5 - 0
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)