| 596 | } |
| 597 | |
| 598 | bool psbt_finalize(struct wally_psbt *psbt) |
| 599 | { |
| 600 | bool ok; |
| 601 | |
| 602 | tal_wally_start(); |
| 603 | |
| 604 | /* Wally doesn't know how to finalize P2WSH; this happens with |
| 605 | * option_anchor_outputs, and finalizing is trivial. */ |
| 606 | /* FIXME: miniscript! miniscript! miniscript! */ |
| 607 | for (size_t i = 0; i < psbt->num_inputs; i++) { |
| 608 | struct wally_psbt_input *input = &psbt->inputs[i]; |
| 609 | struct wally_tx_witness_stack *stack; |
| 610 | |
| 611 | if (!is_anchor_witness_script(input->witness_script, |
| 612 | input->witness_script_len)) |
| 613 | continue; |
| 614 | |
| 615 | if (input->signatures.num_items != 1) |
| 616 | continue; |
| 617 | |
| 618 | /* BOLT #3: |
| 619 | * #### `to_remote` Output |
| 620 | * |
| 621 | * If `option_anchors` applies to the commitment |
| 622 | * transaction, the `to_remote` output is encumbered by a one |
| 623 | * block csv lock. |
| 624 | * |
| 625 | * <remotepubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY |
| 626 | * |
| 627 | * The output is spent by an input with `nSequence` |
| 628 | * field set to `1` and witness: |
| 629 | * |
| 630 | * <remote_sig> |
| 631 | */ |
| 632 | wally_tx_witness_stack_init_alloc(2, &stack); |
| 633 | wally_tx_witness_stack_add(stack, |
| 634 | input->signatures.items[0].value, |
| 635 | input->signatures.items[0].value_len); |
| 636 | wally_tx_witness_stack_add(stack, |
| 637 | input->witness_script, |
| 638 | input->witness_script_len); |
| 639 | wally_psbt_input_set_final_witness(input, stack); |
| 640 | } |
| 641 | |
| 642 | ok = (wally_psbt_finalize(psbt) == WALLY_OK); |
| 643 | tal_wally_end(psbt); |
| 644 | |
| 645 | return ok && psbt_is_finalized(psbt); |
| 646 | } |
| 647 | |
| 648 | struct wally_tx *psbt_final_tx(const tal_t *ctx, const struct wally_psbt *psbt) |
| 649 | { |
no test coverage detected