mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
psbt: make psbt_from_b64 more conventional.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
c1df8d586d
commit
600d0a4a1d
3 changed files with 18 additions and 10 deletions
|
@ -361,11 +361,20 @@ struct wally_tx *psbt_finalize(struct wally_psbt *psbt, bool finalize_in_place)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psbt_from_b64(const char *b64str, struct wally_psbt **psbt)
|
struct wally_psbt *psbt_from_b64(const tal_t *ctx,
|
||||||
|
const char *b64,
|
||||||
|
size_t b64len)
|
||||||
{
|
{
|
||||||
int wally_err;
|
struct wally_psbt *psbt;
|
||||||
wally_err = wally_psbt_from_base64(b64str, psbt);
|
char *str = tal_strndup(tmpctx, b64, b64len);
|
||||||
return wally_err == WALLY_OK;
|
|
||||||
|
if (wally_psbt_from_base64(str, &psbt) != WALLY_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* We promised it would be owned by ctx: libwally uses a dummy owner */
|
||||||
|
tal_steal(ctx, psbt);
|
||||||
|
tal_add_destructor(psbt, psbt_destroy);
|
||||||
|
return psbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt)
|
char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt)
|
||||||
|
|
|
@ -74,7 +74,9 @@ bool psbt_input_set_redeemscript(struct wally_psbt *psbt, size_t in,
|
||||||
struct amount_sat psbt_input_get_amount(struct wally_psbt *psbt,
|
struct amount_sat psbt_input_get_amount(struct wally_psbt *psbt,
|
||||||
size_t in);
|
size_t in);
|
||||||
|
|
||||||
bool psbt_from_b64(const char *b64str, struct wally_psbt **psbt);
|
struct wally_psbt *psbt_from_b64(const tal_t *ctx,
|
||||||
|
const char *b64,
|
||||||
|
size_t b64len);
|
||||||
char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt);
|
char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt);
|
||||||
const u8 *psbt_get_bytes(const tal_t *ctx, const struct wally_psbt *psbt,
|
const u8 *psbt_get_bytes(const tal_t *ctx, const struct wally_psbt *psbt,
|
||||||
size_t *bytes_written);
|
size_t *bytes_written);
|
||||||
|
|
|
@ -1203,11 +1203,8 @@ struct command_result *param_psbt(struct command *cmd,
|
||||||
const jsmntok_t *tok,
|
const jsmntok_t *tok,
|
||||||
struct wally_psbt **psbt)
|
struct wally_psbt **psbt)
|
||||||
{
|
{
|
||||||
/* Pull out the token into a string, then pass to
|
*psbt = psbt_from_b64(cmd, buffer + tok->start, tok->end - tok->start);
|
||||||
* the PSBT parser; PSBT parser can't handle streaming
|
if (*psbt)
|
||||||
* atm as it doesn't accept a len value */
|
|
||||||
char *psbt_buff = json_strdup(cmd, buffer, tok);
|
|
||||||
if (psbt_from_b64(psbt_buff, psbt))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
|
Loading…
Add table
Reference in a new issue