| 777 | } |
| 778 | |
| 779 | bool psbt_finalize(struct wally_psbt *psbt) |
| 780 | { |
| 781 | bool ok; |
| 782 | |
| 783 | tal_wally_start(); |
| 784 | |
| 785 | /* Wally doesn't know how to finalize P2WSH; this happens with |
| 786 | * option_anchor_outputs, and finalizing those two cases is trivial. */ |
| 787 | /* FIXME: miniscript! miniscript! miniscript! */ |
| 788 | for (size_t i = 0; i < psbt->num_inputs; i++) { |
| 789 | struct wally_psbt_input *input = &psbt->inputs[i]; |
| 790 | struct wally_tx_witness_stack *stack; |
| 791 | const struct wally_map_item *iws; |
| 792 | |
| 793 | iws = wally_map_get_integer(&input->psbt_fields, /* PSBT_IN_WITNESS_SCRIPT */ 0x05); |
| 794 | if (!iws) |
| 795 | continue; |
| 796 | |
| 797 | if (!is_to_remote_anchored_witness_script(iws->value, |
| 798 | iws->value_len) |
| 799 | && !is_anchor_witness_script(iws->value, |
| 800 | iws->value_len)) { |
| 801 | continue; |
| 802 | } |
| 803 | |
| 804 | if (input->signatures.num_items != 1) |
| 805 | continue; |
| 806 | |
| 807 | /* BOLT #3: |
| 808 | * #### `to_remote` Output |
| 809 | * |
| 810 | * If `option_anchors` applies to the commitment |
| 811 | * transaction, the `to_remote` output is encumbered by a one |
| 812 | * block csv lock. |
| 813 | * |
| 814 | * <remotepubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY |
| 815 | * |
| 816 | * The output is spent by an input with `nSequence` |
| 817 | * field set to `1` and witness: |
| 818 | * |
| 819 | * <remote_sig> |
| 820 | */ |
| 821 | /* BOLT #3: |
| 822 | * #### `to_local_anchor` and `to_remote_anchor` Output (option_anchors) |
| 823 | *... |
| 824 | * <local_funding_pubkey/remote_funding_pubkey> OP_CHECKSIG OP_IFDUP |
| 825 | * OP_NOTIF |
| 826 | * OP_16 OP_CHECKSEQUENCEVERIFY |
| 827 | * OP_ENDIF |
| 828 | *... |
| 829 | * Spending of the output requires the following witness: |
| 830 | * <local_sig/remote_sig> |
| 831 | */ |
| 832 | |
| 833 | /* i.e. in both cases, this is the same thing */ |
| 834 | wally_tx_witness_stack_init_alloc(2, &stack); |
| 835 | wally_tx_witness_stack_add(stack, |
| 836 | input->signatures.items[0].value, |
no test coverage detected