| 440 | } |
| 441 | |
| 442 | bool psbt_has_required_fields(struct wally_psbt *psbt) |
| 443 | { |
| 444 | u64 serial_id; |
| 445 | for (size_t i = 0; i < psbt->num_inputs; i++) { |
| 446 | const struct wally_map_item *redeem_script; |
| 447 | const struct wally_tx_output *txout; |
| 448 | struct wally_psbt_input *input = &psbt->inputs[i]; |
| 449 | |
| 450 | if (!psbt_get_serial_id(&input->unknowns, &serial_id)) |
| 451 | return false; |
| 452 | |
| 453 | /* Required because we send the full tx over the wire now */ |
| 454 | if (!input->utxo) |
| 455 | return false; |
| 456 | |
| 457 | assert(input->index < input->utxo->num_outputs); |
| 458 | txout = &input->utxo->outputs[input->index]; |
| 459 | if (!is_p2sh(txout->script, txout->script_len, NULL)) |
| 460 | continue; |
| 461 | /* P2SH: redeemscript must be present */ |
| 462 | const u32 key = 0x04; /* PSBT_IN_REDEEM_SCRIPT */ |
| 463 | redeem_script = wally_map_get_integer(&input->psbt_fields, key); |
| 464 | if (!redeem_script || !redeem_script->value_len) |
| 465 | return false; |
| 466 | } |
| 467 | |
| 468 | for (size_t i = 0; i < psbt->num_outputs; i++) { |
| 469 | if (!psbt_get_serial_id(&psbt->outputs[i].unknowns, &serial_id)) |
| 470 | return false; |
| 471 | } |
| 472 | |
| 473 | return true; |
| 474 | } |
| 475 | |
| 476 | bool psbt_side_finalized(const struct wally_psbt *psbt, enum tx_role role) |
| 477 | { |
no test coverage detected