Skip to content

Commit

Permalink
hook: passing the psbt inside the json hook
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed May 13, 2024
1 parent c94c407 commit 7e16272
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ static void onfunding_channel_tx_hook_serialize(struct onfunding_channel_tx_hook
json_object_start(stream, "onfunding_channel_tx");
json_add_tx(stream, "tx", payload->tx);
json_add_txid(stream, "txid", &txid);
json_add_psbt(stream, "psbt", payload->tx->psbt);
json_add_channel_id(stream, "channel_id", payload->cid);
json_object_end(stream);
}
Expand All @@ -893,9 +894,9 @@ static bool onfunding_channel_tx_hook_deserialize(struct onfunding_channel_tx_ho
const char *buffer,
const jsmntok_t *toks)
{
const jsmntok_t *result_tok, *error_tok, *tx_tok;
const jsmntok_t *result_tok, *error_tok,
*tx_tok, *psbt_tok;

log_info(payload->openingd->log, "buffer %s", buffer);
if ((error_tok = json_get_member(buffer, toks, "error")) != NULL)
fatal("Plugin returned an error inside the response to the"
" onfunding_channel_tx hook: %.*s",
Expand All @@ -911,12 +912,17 @@ static bool onfunding_channel_tx_hook_deserialize(struct onfunding_channel_tx_ho
" onfunding_channel_tx hook: %.*s",
toks[0].end - toks[0].start, buffer + toks[0].start);

payload->tx = NULL;
if ((psbt_tok = json_get_member(buffer, result_tok, "psbt")) == NULL)
fatal("Plugin returned an invalid response (missing psbt) to the"
" onfunding_channel_tx hook: %.*s",
toks[0].end - toks[0].start, buffer + toks[0].start);

if (!json_to_tx(buffer, tx_tok, &payload->tx))
fatal("Plugin returned an invalid (json to tx) response to the"
" onfunding_channel_tx hook: %.*s",
tx_tok[0].end - tx_tok[0].start, buffer + tx_tok[0].start);
log_info(payload->openingd->log, "hook return the following tx: %s", fmt_bitcoin_tx(tmpctx, payload->tx));

payload->tx->psbt = json_to_psbt(buffer, buffer, psbt_tok);
return true;
}

Expand Down

0 comments on commit 7e16272

Please sign in to comment.