@@ -539,6 +539,21 @@ def list_unspent(source, allow_unconfirmed_inputs):
539
539
return []
540
540
541
541
542
+ def get_vin_info (vin , no_retry = False ):
543
+ vin_info = vin .get ("info" )
544
+ if vin_info is None :
545
+ logger .error (f"vin_info not found for vin { vin } " )
546
+ try :
547
+ vin_ctx = get_decoded_transaction (vin ["hash" ], no_retry = no_retry )
548
+ is_segwit = vin_ctx ["segwit" ]
549
+ vout = vin_ctx ["vout" ][vin ["n" ]]
550
+ return vout ["value" ], vout ["script_pub_key" ], is_segwit
551
+ except exceptions .BitcoindRPCError as e :
552
+ raise exceptions .DecodeError ("vin not found" ) from e
553
+ else :
554
+ return vin_info ["value" ], vin_info ["script_pub_key" ], vin_info ["is_segwit" ]
555
+
556
+
542
557
def get_vins_info (vins , no_retry = False ):
543
558
hashes = [vin ["hash" ] for vin in vins ]
544
559
inputs_txs = getrawtransaction_batch (hashes , verbose = False , return_dict = True , no_retry = no_retry )
@@ -554,6 +569,25 @@ def get_vins_info(vins, no_retry=False):
554
569
return vins_info
555
570
556
571
572
+ def complete_vins_info (decoded_tx , no_retry = False ):
573
+ missing_vins = []
574
+ for vin in decoded_tx ["vin" ]:
575
+ if "info" not in vin or vin ["info" ] is None :
576
+ missing_vins .append (vin )
577
+
578
+ if len (missing_vins ) > 0 :
579
+ missing_vins_info = get_vins_info (missing_vins , no_retry = no_retry )
580
+ for i , vin in enumerate (missing_vins ):
581
+ vin_info = missing_vins_info [i ]
582
+ vin ["info" ] = {
583
+ "value" : vin_info [0 ],
584
+ "script_pub_key" : vin_info [1 ],
585
+ "is_segwit" : vin_info [2 ],
586
+ }
587
+
588
+ return decoded_tx
589
+
590
+
557
591
def get_transaction (tx_hash : str , format : str = "json" ):
558
592
"""
559
593
Get a transaction from the blockchain
0 commit comments