@@ -181,13 +181,13 @@ type Maybe<T> = Result<T, JsError>;
181181}
182182
183183#[ wasm_bindgen( js_name = sendSigned) ]
184- pub fn send_signed ( signer : & Keypair , options : & JsValue ) -> Maybe < JsValue > {
184+ pub fn send_signed ( signer : & Keypair , options : & JsValue ) -> Maybe < Object > {
185185 let ( mut psbt, _) = send_from_js ( options, None , None ) ?;
186186 Pst ( psbt) . to_signed ( signer)
187187}
188188
189189#[ wasm_bindgen( js_name = sendUnsigned) ]
190- pub fn send_unsigned ( options : & JsValue ) -> Maybe < JsValue > {
190+ pub fn send_unsigned ( options : & JsValue ) -> Maybe < Object > {
191191 ret_pst ( & send_from_js ( options, None , None ) ?. 0 )
192192}
193193
@@ -284,16 +284,13 @@ pub fn pst (arg: Object) -> Maybe<Pst> {
284284 }
285285 /// Show [PartiallySignedTransaction]
286286 #[ wasm_bindgen( js_name = toPset) ]
287- pub fn to_pset ( & self ) -> Maybe < JsValue > {
287+ pub fn to_pset ( & self ) -> Maybe < Object > {
288288 ret_pst ( & self . 0 )
289289 }
290290 /// Simplified sign procedure.
291291 #[ wasm_bindgen( js_name = toSigned) ]
292- pub fn to_signed ( & self , keypair : & Keypair ) -> Maybe < JsValue > {
293- let signed = sign ( & self , keypair) ?;
294- let result = ret_pst ( & signed. 0 ) ?;
295- set ! ( result, "signedHex" , JsValue :: from( pset_to_hex( & signed. 0 ) ?) ) ;
296- Ok ( result)
292+ pub fn to_signed ( & self , keypair : & Keypair ) -> Maybe < Object > {
293+ ret_pst ( & sign ( & self , keypair) ?. 0 )
297294 }
298295}
299296
@@ -454,7 +451,7 @@ pub fn witness_types (source: JsString) -> Maybe<Object> {
454451 /// Partially-signed redeem transaction without witnesses.
455452 /// For manual signing.
456453 #[ wasm_bindgen( js_name = redeemPsbt) ]
457- pub fn redeem_psbt ( & self , options : & JsValue ) -> Maybe < JsValue > {
454+ pub fn redeem_psbt ( & self , options : & JsValue ) -> Maybe < Object > {
458455 ret_pst ( & self . redeem_psbt_utxo ( options) ?. 0 )
459456 }
460457
@@ -668,11 +665,11 @@ fn arg_utxos (options: JsValue) -> Maybe<Vec<(OutPoint, TxOut)>> {
668665}
669666
670667fn arg_utxo ( options : JsValue ) -> Maybe < ( OutPoint , TxOut ) > {
671- let txid = get ! ( options, "txid" , arg_txid) ?;
672- let vout = get ! ( options, "vout" , arg_vout) ?;
673- let recip = get ! ( options, "recipient " , arg_address) ?;
674- let asset = get ! ( options, "asset" , arg_asset_id) ?;
675- let value = get ! ( options, "value" , arg_sats) ?;
668+ let txid = get ! ( options, "txid" , arg_txid) ?;
669+ let vout = get ! ( options, "vout" , arg_vout) ?;
670+ let recip = get ! ( options, "address " , arg_address) ?;
671+ let asset = get ! ( options, "asset" , arg_asset_id) ?;
672+ let value = get ! ( options, "amount" , arg_sats) ?;
676673 Ok ( ( OutPoint { txid, vout } , TxOut {
677674 script_pubkey : recip. script_pubkey ( ) ,
678675 value : TxValue :: Explicit ( value) ,
@@ -700,7 +697,7 @@ fn arg_sats (input: JsValue) -> Maybe<u64> {
700697 warn ! ( "Number -> sats (u64): * 10^8; use BigInt to avoid precision issues" ) ;
701698 try_ ! ( "Number -> sats (u64)" : f64 :: try_from( input) . map( |x|( x * 100000000.0 ) as u64 ) )
702699 } else if JsString :: is_type_of ( & input) {
703- warn ! ( "String -> sats (u64): use BigInt to avoid typing issues" ) ;
700+ warn ! ( "String -> sats (u64): use BigInt to avoid type issues" ) ;
704701 try_debug ! ( "String -> sats (u64)" : u64 :: from_str( & input. as_string( ) . unwrap_or_default( ) ) )
705702 } else {
706703 return err ! ( "sats: received {:?}: need integer" , input. js_typeof( ) )
@@ -755,9 +752,11 @@ fn ret_tx (tx: &Transaction) -> Maybe<Object> {
755752 } )
756753}
757754
758- fn ret_pst ( psbt : & PartiallySignedTransaction ) -> Maybe < JsValue > {
759- match JSON :: parse ( serde_json:: to_string ( & psbt) ?. as_str ( ) ) {
760- Ok ( psbt) => Ok ( psbt) ,
761- Err ( _) => err ! ( "failed to deserialize interim psbt" )
762- }
755+ fn ret_pst ( pst : & PartiallySignedTransaction ) -> Maybe < Object > {
756+ Ok ( obj ! {
757+ "global" = try_!( "pst: serialize global" : JSON :: parse( serde_json:: to_string( & pst. global) ?. as_str( ) ) ) ?,
758+ "inputs" = try_!( "pst: serialize inputs" : JSON :: parse( serde_json:: to_string( & pst. inputs( ) ) ?. as_str( ) ) ) ?,
759+ "outputs" = try_!( "pst: serialize outputs" : JSON :: parse( serde_json:: to_string( & pst. outputs( ) ) ?. as_str( ) ) ) ?,
760+ "hex" = JsValue :: from( pset_to_hex( & pst) ?) ,
761+ } )
763762}
0 commit comments