Browse Source

json_to_psbt: fix API to match other allocating json_to functions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa
Rusty Russell 4 years ago
committed by Christian Decker
parent
commit
2b6cdfeb5a
  1. 7
      common/json_helpers.c
  2. 4
      common/json_helpers.h
  3. 6
      lightningd/dual_open_control.c
  4. 10
      plugins/spender/openchannel.c

7
common/json_helpers.c

@ -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)); return hex_decode(buffer + tok->start, hexlen, preimage->r, sizeof(preimage->r));
} }
bool json_to_psbt(const tal_t *ctx, const char *buffer, struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok, struct wally_psbt **dest) const jsmntok_t *tok)
{ {
*dest = psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start); return psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start);
return dest != NULL;
} }
void json_add_node_id(struct json_stream *response, void json_add_node_id(struct json_stream *response,

4
common/json_helpers.h

@ -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); bool json_to_secret(const char *buffer, const jsmntok_t *tok, struct secret *dest);
/* Extract a psbt from this. */ /* Extract a psbt from this. */
bool json_to_psbt(const tal_t *ctx, const char *buffer, struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok, struct wally_psbt **dest); const jsmntok_t *tok);
/* Extract a pubkey from this */ /* Extract a pubkey from this */
bool json_to_pubkey(const char *buffer, const jsmntok_t *tok, bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,

6
lightningd/dual_open_control.c

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

10
plugins/spender/openchannel.c

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

Loading…
Cancel
Save