mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
psbt-finalized: hoist method to common
This commit is contained in:
@@ -567,3 +567,20 @@ psbt_to_witness_stacks(const tal_t *ctx,
|
|||||||
tal_resize(&stacks, stack_index);
|
tal_resize(&stacks, stack_index);
|
||||||
return stacks;
|
return stacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool psbt_side_finalized(const struct wally_psbt *psbt, enum tx_role role)
|
||||||
|
{
|
||||||
|
u16 serial_id;
|
||||||
|
for (size_t i = 0; i < psbt->num_inputs; i++) {
|
||||||
|
if (!psbt_get_serial_id(&psbt->inputs[i].unknowns,
|
||||||
|
&serial_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (serial_id % 2 == role) {
|
||||||
|
if (!psbt->inputs[i].final_witness ||
|
||||||
|
psbt->inputs[i].final_witness->num_items == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -179,4 +179,8 @@ const struct witness_stack **
|
|||||||
psbt_to_witness_stacks(const tal_t *ctx,
|
psbt_to_witness_stacks(const tal_t *ctx,
|
||||||
const struct wally_psbt *psbt,
|
const struct wally_psbt *psbt,
|
||||||
enum tx_role side_to_stack);
|
enum tx_role side_to_stack);
|
||||||
|
|
||||||
|
/* psbt_side_finalized - True if designated role has all signature data */
|
||||||
|
bool psbt_side_finalized(const struct wally_psbt *psbt,
|
||||||
|
enum tx_role role);
|
||||||
#endif /* LIGHTNING_COMMON_PSBT_OPEN_H */
|
#endif /* LIGHTNING_COMMON_PSBT_OPEN_H */
|
||||||
|
|||||||
@@ -38,29 +38,6 @@ struct commit_rcvd {
|
|||||||
struct uncommitted_channel *uc;
|
struct uncommitted_channel *uc;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool psbt_side_finalized(struct log *log, struct wally_psbt *psbt, enum side opener)
|
|
||||||
{
|
|
||||||
u16 serial_id;
|
|
||||||
for (size_t i = 0; i < psbt->num_inputs; i++) {
|
|
||||||
if (!psbt_get_serial_id(&psbt->inputs[i].unknowns, &serial_id)) {
|
|
||||||
log_broken(log, "dual funding PSBT must have serial_id for each "
|
|
||||||
"input, none found for input %zu", i);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/* It's our input if parity matches -- this shorthand
|
|
||||||
* works because LOCAL == 0. If the parity is even and
|
|
||||||
* we're the opener then it's ours; if the parity is odd
|
|
||||||
* and the REMOTE's the opener (opener == 1), then it's also
|
|
||||||
* ours. */
|
|
||||||
if (serial_id % 2 == opener) {
|
|
||||||
if (!psbt->inputs[i].final_witness ||
|
|
||||||
psbt->inputs[i].final_witness->num_items == 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_signed_psbt(struct lightningd *ld,
|
static void handle_signed_psbt(struct lightningd *ld,
|
||||||
const struct wally_psbt *psbt,
|
const struct wally_psbt *psbt,
|
||||||
struct commit_rcvd *rcvd)
|
struct commit_rcvd *rcvd)
|
||||||
@@ -548,9 +525,10 @@ openchannel2_sign_hook_cb(struct openchannel2_psbt_payload *payload STEALS)
|
|||||||
/* Finalize it, if not already. It shouldn't work entirely */
|
/* Finalize it, if not already. It shouldn't work entirely */
|
||||||
psbt_finalize(payload->psbt);
|
psbt_finalize(payload->psbt);
|
||||||
|
|
||||||
if (!psbt_side_finalized(payload->ld->log, payload->psbt, REMOTE))
|
if (!psbt_side_finalized(payload->psbt, TX_ACCEPTER))
|
||||||
fatal("Plugin must return a 'psbt' with signatures for their inputs"
|
fatal("Plugin must return a 'psbt' with signatures "
|
||||||
" %s", type_to_string(tmpctx, struct wally_psbt, payload->psbt));
|
"for their inputs %s",
|
||||||
|
type_to_string(tmpctx, struct wally_psbt, payload->psbt));
|
||||||
|
|
||||||
handle_signed_psbt(payload->ld, payload->psbt, payload->rcvd);
|
handle_signed_psbt(payload->ld, payload->psbt, payload->rcvd);
|
||||||
}
|
}
|
||||||
@@ -1051,7 +1029,7 @@ static struct command_result *json_open_channel_signed(struct command *cmd,
|
|||||||
psbt_finalize(psbt);
|
psbt_finalize(psbt);
|
||||||
|
|
||||||
/* Check that all of *our* outputs are finalized */
|
/* Check that all of *our* outputs are finalized */
|
||||||
if (!psbt_side_finalized(cmd->ld->log, psbt, LOCAL))
|
if (!psbt_side_finalized(psbt, TX_INITIATOR))
|
||||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||||
"Local PSBT input(s) not finalized");
|
"Local PSBT input(s) not finalized");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user