@@ -20,9 +20,10 @@ class Transaction(dict):
20
20
:param boolean testnet: address type for "decoded" transaction representation.
21
21
22
22
"""
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 ):
24
24
if format not in ("decoded" , "raw" ):
25
25
raise ValueError ("format error, raw or decoded allowed" )
26
+ self .auto_commit = auto_commit
26
27
self ["format" ] = format
27
28
self ["testnet" ] = testnet
28
29
self ["segwit" ] = False
@@ -468,7 +469,8 @@ def add_input(self, tx_id=None, v_out=0, sequence=0xffffffff,
468
469
self ["vIn" ][k ]["value" ] = amount
469
470
if private_key :
470
471
self ["vIn" ][k ].private_key = private_key
471
- self .__refresh__ ()
472
+ if self .auto_commit :
473
+ self .commit ()
472
474
return self
473
475
474
476
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):
518
520
self ["testnet" ],
519
521
sh ,
520
522
witness_version )
521
- self .__refresh__ ()
523
+ if self .auto_commit :
524
+ self .commit ()
522
525
return self
523
526
524
527
def del_output (self , n = None ):
@@ -533,7 +536,8 @@ def del_output(self, n=None):
533
536
new_out [c ] = self ["vOut" ][i ]
534
537
c += 1
535
538
self ["vOut" ] = new_out
536
- self .__refresh__ ()
539
+ if self .auto_commit :
540
+ self .commit ()
537
541
return self
538
542
539
543
def del_input (self , n ):
@@ -548,7 +552,8 @@ def del_input(self, n):
548
552
new_in [c ] = self ["vIn" ][i ]
549
553
c += 1
550
554
self ["vIn" ] = new_in
551
- self .__refresh__ ()
555
+ if self .auto_commit :
556
+ self .commit ()
552
557
return self
553
558
554
559
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,
622
627
self ["vIn" ][n ]["scriptSig" ] = script_sig .hex ()
623
628
self ["vIn" ][n ]["scriptSigOpcodes" ] = decode_script (script_sig )
624
629
self ["vIn" ][n ]["scriptSigAsm" ] = decode_script (script_sig , 1 )
625
- self .__refresh__ ()
630
+ if self .auto_commit :
631
+ self .commit ()
626
632
return self
627
633
628
634
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
1022
1028
pm = double_sha256 (pm )
1023
1029
return pm if self ["format" ] == "raw" else pm .hex ()
1024
1030
1025
- def __refresh__ (self ):
1031
+ def commit (self ):
1026
1032
if not self ["vOut" ] or not self ["vIn" ]:
1027
1033
return
1028
1034
if self ["segwit" ]:
0 commit comments