From df7c122cb84fb6fd6bebd99ffbbcaa5684c27c67 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 6 Aug 2020 13:18:54 -0500 Subject: [PATCH] json: add "json-to-psbt" helper Pull a PSBT out of a json buffer --- common/json_helpers.c | 8 ++++++++ common/json_helpers.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/common/json_helpers.c b/common/json_helpers.c index 35304b65a..25737b01f 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -12,6 +12,7 @@ #include #include #include +#include bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok, uint64_t *satoshi) @@ -127,6 +128,13 @@ 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) +{ + *dest = psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start); + return dest != NULL; +} + void json_add_node_id(struct json_stream *response, const char *fieldname, const struct node_id *id) diff --git a/common/json_helpers.h b/common/json_helpers.h index ac28575aa..801e08ec3 100644 --- a/common/json_helpers.h +++ b/common/json_helpers.h @@ -17,6 +17,7 @@ struct secret; struct short_channel_id; struct wireaddr; struct wireaddr_internal; +struct wally_psbt; /* Decode a hex-encoded payment preimage */ bool json_to_preimage(const char *buffer, const jsmntok_t *tok, struct preimage *preimage); @@ -24,6 +25,10 @@ bool json_to_preimage(const char *buffer, const jsmntok_t *tok, struct preimage /* Extract a secret from this. */ 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); + /* Extract a pubkey from this */ bool json_to_pubkey(const char *buffer, const jsmntok_t *tok, struct pubkey *pubkey);