json: add "json-to-psbt" helper

Pull a PSBT out of a json buffer
This commit is contained in:
niftynei
2020-08-06 13:18:54 -05:00
committed by Rusty Russell
parent 10237ccb8e
commit df7c122cb8
2 changed files with 13 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
#include <common/type_to_string.h> #include <common/type_to_string.h>
#include <common/wireaddr.h> #include <common/wireaddr.h>
#include <errno.h> #include <errno.h>
#include <wally_psbt.h>
bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok, bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
uint64_t *satoshi) 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)); 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, void json_add_node_id(struct json_stream *response,
const char *fieldname, const char *fieldname,
const struct node_id *id) const struct node_id *id)

View File

@@ -17,6 +17,7 @@ struct secret;
struct short_channel_id; struct short_channel_id;
struct wireaddr; struct wireaddr;
struct wireaddr_internal; struct wireaddr_internal;
struct wally_psbt;
/* Decode a hex-encoded payment preimage */ /* Decode a hex-encoded payment preimage */
bool json_to_preimage(const char *buffer, const jsmntok_t *tok, struct preimage *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. */ /* Extract a secret from this. */
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. */
bool json_to_psbt(const tal_t *ctx, const char *buffer,
const jsmntok_t *tok, struct wally_psbt **dest);
/* 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,
struct pubkey *pubkey); struct pubkey *pubkey);