@@ -203,6 +203,46 @@ impl PsbtOutputDataWithAddress {
203203 }
204204}
205205
206+ // ============================================================================
207+ // Helper functions for PSBT introspection - shared by WrapPsbt and BitGoPsbt
208+ // ============================================================================
209+
210+ /// Get all PSBT inputs as an array of PsbtInputData
211+ pub fn get_inputs_from_psbt ( psbt : & Psbt ) -> Result < JsValue , WasmUtxoError > {
212+ let inputs: Vec < PsbtInputData > = psbt. inputs . iter ( ) . map ( PsbtInputData :: from) . collect ( ) ;
213+ inputs. try_to_js_value ( )
214+ }
215+
216+ /// Get all PSBT outputs as an array of PsbtOutputData
217+ pub fn get_outputs_from_psbt ( psbt : & Psbt ) -> Result < JsValue , WasmUtxoError > {
218+ let outputs: Vec < PsbtOutputData > = psbt
219+ . unsigned_tx
220+ . output
221+ . iter ( )
222+ . zip ( psbt. outputs . iter ( ) )
223+ . map ( |( tx_out, psbt_out) | PsbtOutputData :: from ( tx_out, psbt_out) )
224+ . collect ( ) ;
225+ outputs. try_to_js_value ( )
226+ }
227+
228+ /// Get all PSBT outputs with resolved address strings
229+ pub fn get_outputs_with_address_from_psbt (
230+ psbt : & Psbt ,
231+ network : crate :: Network ,
232+ ) -> Result < JsValue , WasmUtxoError > {
233+ let outputs: Vec < PsbtOutputDataWithAddress > = psbt
234+ . unsigned_tx
235+ . output
236+ . iter ( )
237+ . zip ( psbt. outputs . iter ( ) )
238+ . map ( |( tx_out, psbt_out) | {
239+ let base = PsbtOutputData :: from ( tx_out, psbt_out) ;
240+ PsbtOutputDataWithAddress :: from ( base, network)
241+ } )
242+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
243+ outputs. try_to_js_value ( )
244+ }
245+
206246#[ wasm_bindgen]
207247pub struct WrapPsbt ( Psbt ) ;
208248
@@ -585,8 +625,7 @@ impl WrapPsbt {
585625 /// for each input. This is useful for introspecting the PSBT structure.
586626 #[ wasm_bindgen( js_name = getInputs) ]
587627 pub fn get_inputs ( & self ) -> Result < JsValue , WasmUtxoError > {
588- let inputs: Vec < PsbtInputData > = self . 0 . inputs . iter ( ) . map ( PsbtInputData :: from) . collect ( ) ;
589- inputs. try_to_js_value ( )
628+ get_inputs_from_psbt ( & self . 0 )
590629 }
591630
592631 /// Get all PSBT outputs as an array of PsbtOutputData
@@ -595,15 +634,7 @@ impl WrapPsbt {
595634 /// for each output. This is useful for introspecting the PSBT structure.
596635 #[ wasm_bindgen( js_name = getOutputs) ]
597636 pub fn get_outputs ( & self ) -> Result < JsValue , WasmUtxoError > {
598- let outputs: Vec < PsbtOutputData > = self
599- . 0
600- . unsigned_tx
601- . output
602- . iter ( )
603- . zip ( self . 0 . outputs . iter ( ) )
604- . map ( |( tx_out, psbt_out) | PsbtOutputData :: from ( tx_out, psbt_out) )
605- . collect ( ) ;
606- outputs. try_to_js_value ( )
637+ get_outputs_from_psbt ( & self . 0 )
607638 }
608639
609640 /// Get all PSBT outputs with resolved address strings.
@@ -614,18 +645,7 @@ impl WrapPsbt {
614645 pub fn get_outputs_with_address ( & self , coin : & str ) -> Result < JsValue , WasmUtxoError > {
615646 let network = crate :: Network :: from_coin_name ( coin)
616647 . ok_or_else ( || WasmUtxoError :: new ( & format ! ( "Unknown coin: {}" , coin) ) ) ?;
617- let outputs: Vec < PsbtOutputDataWithAddress > = self
618- . 0
619- . unsigned_tx
620- . output
621- . iter ( )
622- . zip ( self . 0 . outputs . iter ( ) )
623- . map ( |( tx_out, psbt_out) | {
624- let base = PsbtOutputData :: from ( tx_out, psbt_out) ;
625- PsbtOutputDataWithAddress :: from ( base, network)
626- } )
627- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
628- outputs. try_to_js_value ( )
648+ get_outputs_with_address_from_psbt ( & self . 0 , network)
629649 }
630650
631651 /// Get partial signatures for an input
0 commit comments