MCPcopy Create free account
hub / github.com/ElementsProject/lightning / psbt_finalize

Function psbt_finalize

bitcoin/psbt.c:779–849  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

777}
778
779bool 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,

Callers 14

bitcoin_tx_with_psbtFunction · 0.85
json_dev_finalizepsbtFunction · 0.85
json_sendpsbtFunction · 0.85
splice_accepterFunction · 0.85
handle_peer_tx_sigs_sentFunction · 0.85
handle_peer_tx_sigs_msgFunction · 0.85
json_openchannel_signedFunction · 0.85
spend_anchorFunction · 0.85
handle_update_inflightFunction · 0.85

Calls 5

tal_wally_startFunction · 0.85
is_anchor_witness_scriptFunction · 0.85
tal_wally_endFunction · 0.85
psbt_is_finalizedFunction · 0.85

Tested by

no test coverage detected