@@ -20,9 +20,10 @@ class Transaction(dict):
2020 :param boolean testnet: address type for "decoded" transaction representation.
2121
2222 """
23- def __init__ (self , raw_tx = None , format = "decoded" , version = 1 , lock_time = 0 , testnet = False ):
23+ def __init__ (self , raw_tx = None , format = "decoded" , version = 1 , lock_time = 0 , testnet = False , auto_commit = True ):
2424 if format not in ("decoded" , "raw" ):
2525 raise ValueError ("format error, raw or decoded allowed" )
26+ self .auto_commit = auto_commit
2627 self ["format" ] = format
2728 self ["testnet" ] = testnet
2829 self ["segwit" ] = False
@@ -468,7 +469,8 @@ def add_input(self, tx_id=None, v_out=0, sequence=0xffffffff,
468469 self ["vIn" ][k ]["value" ] = amount
469470 if private_key :
470471 self ["vIn" ][k ].private_key = private_key
471- self .__refresh__ ()
472+ if self .auto_commit :
473+ self .commit ()
472474 return self
473475
474476 def add_output (self , amount , address = None , script_pub_key = None ):
@@ -518,7 +520,8 @@ def add_output(self, amount, address=None, script_pub_key=None):
518520 self ["testnet" ],
519521 sh ,
520522 witness_version )
521- self .__refresh__ ()
523+ if self .auto_commit :
524+ self .commit ()
522525 return self
523526
524527 def del_output (self , n = None ):
@@ -533,7 +536,8 @@ def del_output(self, n=None):
533536 new_out [c ] = self ["vOut" ][i ]
534537 c += 1
535538 self ["vOut" ] = new_out
536- self .__refresh__ ()
539+ if self .auto_commit :
540+ self .commit ()
537541 return self
538542
539543 def del_input (self , n ):
@@ -548,7 +552,8 @@ def del_input(self, n):
548552 new_in [c ] = self ["vIn" ][i ]
549553 c += 1
550554 self ["vIn" ] = new_in
551- self .__refresh__ ()
555+ if self .auto_commit :
556+ self .commit ()
552557 return self
553558
554559 def sign_input (self , n , private_key = None , script_pub_key = None ,
@@ -622,7 +627,8 @@ def sign_input(self, n, private_key=None, script_pub_key=None,
622627 self ["vIn" ][n ]["scriptSig" ] = script_sig .hex ()
623628 self ["vIn" ][n ]["scriptSigOpcodes" ] = decode_script (script_sig )
624629 self ["vIn" ][n ]["scriptSigAsm" ] = decode_script (script_sig , 1 )
625- self .__refresh__ ()
630+ if self .auto_commit :
631+ self .commit ()
626632 return self
627633
628634 def __sign_bare_multisig__ (self , n , private_key , public_key , script_pub_key , sighash_type ):
@@ -1022,7 +1028,7 @@ def sig_hash_segwit(self, n, amount, script_pub_key=None, sighash_type=SIGHASH_A
10221028 pm = double_sha256 (pm )
10231029 return pm if self ["format" ] == "raw" else pm .hex ()
10241030
1025- def __refresh__ (self ):
1031+ def commit (self ):
10261032 if not self ["vOut" ] or not self ["vIn" ]:
10271033 return
10281034 if self ["segwit" ]:
0 commit comments