@@ -379,33 +379,54 @@ u64 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role)
379379 return serial_id ;
380380}
381381
382+ #include <stdio.h>
383+ #include <common/type_to_string.h>
384+
382385bool psbt_has_required_fields (struct wally_psbt * psbt )
383386{
387+ psbt_set_version (psbt , 0 );
388+ fprintf (stderr , "wally_psbt: %s\n" , type_to_string (tmpctx , struct wally_psbt , psbt ));
389+ psbt_set_version (psbt , 2 );
390+
384391 u64 serial_id ;
385392 for (size_t i = 0 ; i < psbt -> num_inputs ; i ++ ) {
386393 const struct wally_map_item * redeem_script ;
387394 struct wally_psbt_input * input = & psbt -> inputs [i ];
388395
389- if (!psbt_get_serial_id (& input -> unknowns , & serial_id ))
396+ if (!psbt_get_serial_id (& input -> unknowns , & serial_id )) {
397+ fprintf (stderr , "in[%ld]: missing serial id\n" , i );
390398 return false;
399+ }
391400
392401 /* Required because we send the full tx over the wire now */
393- if (!input -> utxo )
402+ /* Only insist on PSBT_IN_NON_WITNESS_UTXO (.utxo) if
403+ * PSBT_IN_WITNESS_UTXO (.witness_utxo) is not present
404+ * because PSBT_IN_NON_WITNESS_UTXO uses a lot of
405+ * memory */
406+ if (!input -> witness_utxo && !input -> utxo ) {
407+ fprintf (stderr , "in[%ld]: missing both utxo\n" , i );
394408 return false;
409+ }
395410
396- /* If is P2SH, redeemscript must be present */
397- assert (psbt -> inputs [i ].index < input -> utxo -> num_outputs );
398- const u8 * outscript =
399- wally_tx_output_get_script (tmpctx ,
400- & input -> utxo -> outputs [psbt -> inputs [i ].index ]);
401- redeem_script = wally_map_get_integer (& psbt -> inputs [i ].psbt_fields , /* PSBT_IN_REDEEM_SCRIPT */ 0x04 );
402- if (is_p2sh (outscript , NULL ) && (!redeem_script || redeem_script -> value_len == 0 ))
403- return false;
411+ if (input -> utxo ) {
412+ /* If is P2SH, redeemscript must be present */
413+ assert (psbt -> inputs [i ].index < input -> utxo -> num_outputs );
414+ const u8 * outscript =
415+ wally_tx_output_get_script (tmpctx ,
416+ & input -> utxo -> outputs [psbt -> inputs [i ].index ]);
417+ redeem_script = wally_map_get_integer (& psbt -> inputs [i ].psbt_fields , /* PSBT_IN_REDEEM_SCRIPT */ 0x04 );
418+ if (is_p2sh (outscript , NULL ) && (!redeem_script || redeem_script -> value_len == 0 )) {
419+ fprintf (stderr , "in[%ld]: missing redeemscript\n" , i );
420+ return false;
421+ }
422+ }
404423 }
405424
406425 for (size_t i = 0 ; i < psbt -> num_outputs ; i ++ ) {
407- if (!psbt_get_serial_id (& psbt -> outputs [i ].unknowns , & serial_id ))
426+ if (!psbt_get_serial_id (& psbt -> outputs [i ].unknowns , & serial_id )) {
427+ fprintf (stderr , "out[%ld]: missing serial id\n" , i );
408428 return false;
429+ }
409430 }
410431
411432 return true;
0 commit comments