json_to_psbt: fix API to match other allocating json_to functions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-01-06 16:11:19 +10:30
committed by Christian Decker
parent 70410b8ee8
commit 2b6cdfeb5a
4 changed files with 13 additions and 14 deletions

View File

@@ -140,11 +140,10 @@ bool json_to_preimage(const char *buffer, const jsmntok_t *tok, struct preimage
return hex_decode(buffer + tok->start, hexlen, preimage->r, sizeof(preimage->r));
}
bool json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok, struct wally_psbt **dest)
struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok)
{
*dest = psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start);
return dest != NULL;
return psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start);
}
void json_add_node_id(struct json_stream *response,

View File

@@ -26,8 +26,8 @@ bool json_to_preimage(const char *buffer, const jsmntok_t *tok, struct preimage
bool json_to_secret(const char *buffer, const jsmntok_t *tok, struct secret *dest);
/* Extract a psbt from this. */
bool json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok, struct wally_psbt **dest);
struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok);
/* Extract a pubkey from this */
bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,

View File

@@ -218,8 +218,6 @@ hook_extract_psbt(const tal_t *ctx, struct subd *dualopend, const char *buffer,
bool allow_empty,
struct wally_psbt **out)
{
struct wally_psbt *returned_psbt;
if (!buffer)
fatal("Plugin must return a valid response to %s", hook_name);
@@ -250,13 +248,13 @@ hook_extract_psbt(const tal_t *ctx, struct subd *dualopend, const char *buffer,
return true;
}
if (!json_to_psbt(ctx, buffer, psbt_tok, &returned_psbt))
*out = json_to_psbt(ctx, buffer, psbt_tok);
if (!*out)
fatal("Plugin must return a valid 'psbt' to a 'continue'd"
"%s %.*s", hook_name,
toks[0].end - toks[0].start,
buffer + toks[0].start);
*out = returned_psbt;
return true;
}

View File

@@ -571,8 +571,8 @@ static void json_peer_sigs(struct command *cmd,
json_tok_full_len(params),
json_tok_full(buf, params));
if (!json_to_psbt(cmd, buf, psbt_tok,
cast_const2(struct wally_psbt **, &psbt)))
psbt = json_to_psbt(cmd, buf, psbt_tok);
if (!psbt)
plugin_err(cmd->plugin,
"Unable to parse openchannel_peer_sigs.signed_psbt "
"%.*s",
@@ -705,7 +705,8 @@ openchannel_update_ok(struct command *cmd,
json_tok_full_len(result),
json_tok_full(buf, result));
if (!json_to_psbt(dest->mfc, buf, psbt_tok, &dest->updated_psbt))
dest->updated_psbt = json_to_psbt(dest->mfc, buf, psbt_tok);
if (!dest->updated_psbt)
plugin_err(cmd->plugin,
"`openchannel_update` returned invalid "
"'psbt': %.*s",
@@ -939,7 +940,8 @@ openchannel_init_ok(struct command *cmd,
"'psbt': %.*s",
json_tok_full_len(result),
json_tok_full(buf, result));
if (!json_to_psbt(dest->mfc, buf, psbt_tok, &dest->updated_psbt))
dest->updated_psbt = json_to_psbt(dest->mfc, buf, psbt_tok);
if (!dest->updated_psbt)
plugin_err(cmd->plugin,
"openchannel_init returned invalid "
"'psbt': %.*s",