Skip to content

Commit 7bb5c50

Browse files
hook: passing the psbt inside the json hook
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent b699a62 commit 7bb5c50

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lightningd/opening_control.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ static void onfunding_channel_tx_hook_serialize(struct onfunding_channel_tx_hook
883883
json_object_start(stream, "onfunding_channel_tx");
884884
json_add_tx(stream, "tx", payload->tx);
885885
json_add_txid(stream, "txid", &txid);
886+
json_add_psbt(stream, "psbt", payload->tx->psbt);
886887
json_add_channel_id(stream, "channel_id", payload->cid);
887888
json_object_end(stream);
888889
}
@@ -891,9 +892,9 @@ static bool onfunding_channel_tx_hook_deserialize(struct onfunding_channel_tx_ho
891892
const char *buffer,
892893
const jsmntok_t *toks)
893894
{
894-
const jsmntok_t *result_tok, *error_tok, *tx_tok;
895+
const jsmntok_t *result_tok, *error_tok,
896+
*tx_tok, *psbt_tok;
895897

896-
log_info(payload->openingd->log, "buffer %s", buffer);
897898
if ((error_tok = json_get_member(buffer, toks, "error")) != NULL)
898899
fatal("Plugin returned an error inside the response to the"
899900
" onfunding_channel_tx hook: %.*s",
@@ -909,12 +910,17 @@ static bool onfunding_channel_tx_hook_deserialize(struct onfunding_channel_tx_ho
909910
" onfunding_channel_tx hook: %.*s",
910911
toks[0].end - toks[0].start, buffer + toks[0].start);
911912

912-
payload->tx = NULL;
913+
if ((psbt_tok = json_get_member(buffer, result_tok, "psbt")) == NULL)
914+
fatal("Plugin returned an invalid response (missing psbt) to the"
915+
" onfunding_channel_tx hook: %.*s",
916+
toks[0].end - toks[0].start, buffer + toks[0].start);
917+
913918
if (!json_to_tx(buffer, tx_tok, &payload->tx))
914919
fatal("Plugin returned an invalid (json to tx) response to the"
915920
" onfunding_channel_tx hook: %.*s",
916921
tx_tok[0].end - tx_tok[0].start, buffer + tx_tok[0].start);
917-
log_info(payload->openingd->log, "hook return the following tx: %s", fmt_bitcoin_tx(tmpctx, payload->tx));
922+
923+
payload->tx->psbt = json_to_psbt(buffer, buffer, psbt_tok);
918924
return true;
919925
}
920926

0 commit comments

Comments
 (0)