diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index ab3d8f698..5d31d8f03 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -752,17 +752,6 @@ json_tok_address_scriptpubkey(const tal_t *cxt, return ADDRESS_PARSE_UNRECOGNIZED; } -bool json_tok_newaddr(const char *buffer, const jsmntok_t *tok, bool *is_p2wpkh) -{ - if (json_tok_streq(buffer, tok, "p2sh-segwit")) - *is_p2wpkh = false; - else if (json_tok_streq(buffer, tok, "bech32")) - *is_p2wpkh = true; - else - return false; - return true; -} - bool json_tok_wtx(struct wallet_tx * tx, const char * buffer, const jsmntok_t *sattok, u64 max) { diff --git a/lightningd/jsonrpc.h b/lightningd/jsonrpc.h index 1960cb472..9f36b8010 100644 --- a/lightningd/jsonrpc.h +++ b/lightningd/jsonrpc.h @@ -95,8 +95,6 @@ json_tok_address_scriptpubkey(const tal_t *ctx, const char *buffer, const jsmntok_t *tok, const u8 **scriptpubkey); -bool json_tok_newaddr(const char *buffer, const jsmntok_t *tok, bool *is_p2wpkh); - /* Parse the satoshi token in wallet_tx. */ bool json_tok_wtx(struct wallet_tx * tx, const char * buffer, const jsmntok_t * sattok, u64 max); diff --git a/lightningd/param.c b/lightningd/param.c index d51fe9c83..73852bf9d 100644 --- a/lightningd/param.c +++ b/lightningd/param.c @@ -50,7 +50,6 @@ struct fail_format { }; static struct fail_format fail_formats[] = { - {json_tok_newaddr, "'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'"}, {json_tok_wtx, "'%s' should be 'all' or a positive integer greater than " "545, not '%.*s'"}, diff --git a/lightningd/test/run-param.c b/lightningd/test/run-param.c index 6cf8f6c21..1dbafa56a 100644 --- a/lightningd/test/run-param.c +++ b/lightningd/test/run-param.c @@ -48,9 +48,6 @@ void command_fail_detailed(struct command *cmd, int code, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } -/* Generated stub for json_tok_newaddr */ -bool json_tok_newaddr(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool *is_p2wpkh UNNEEDED) -{ fprintf(stderr, "json_tok_newaddr called!\n"); abort(); } /* Generated stub for json_tok_wtx */ bool json_tok_wtx(struct wallet_tx * tx UNNEEDED, const char * buffer UNNEEDED, const jsmntok_t * sattok UNNEEDED, u64 max UNNEEDED) diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 6ea56bc5c..715d48358 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -215,18 +215,38 @@ encode_pubkey_to_addr(const tal_t *ctx, return out; } +/* Extract a bool indicating "p2sh-segwit" or "bech32" */ +static bool json_tok_newaddr(struct command *cmd, const char *name, + const char *buffer, const jsmntok_t *tok, + bool **is_p2wpkh) +{ + *is_p2wpkh = tal(cmd, bool); + if (json_tok_streq(buffer, tok, "p2sh-segwit")) { + **is_p2wpkh = false; + return true; + } + if (json_tok_streq(buffer, tok, "bech32")) { + **is_p2wpkh = true; + return true; + } + command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'", + name, tok->end - tok->start, buffer + tok->start); + return false; +} + static void json_newaddr(struct command *cmd, const char *buffer UNUSED, const jsmntok_t *params UNUSED) { struct json_result *response = new_json_result(cmd); struct ext_key ext; struct pubkey pubkey; - bool is_p2wpkh; + bool *is_p2wpkh; s64 keyidx; char *out; if (!param(cmd, buffer, params, - p_opt_def("addresstype", json_tok_newaddr, &is_p2wpkh, true), + p_opt_def_tal("addresstype", json_tok_newaddr, &is_p2wpkh, true), NULL)) return; @@ -251,7 +271,7 @@ static void json_newaddr(struct command *cmd, const char *buffer UNUSED, txfilter_add_derkey(cmd->ld->owned_txfilter, ext.pub_key); out = encode_pubkey_to_addr(cmd, cmd->ld, - &pubkey, !is_p2wpkh, + &pubkey, !*is_p2wpkh, NULL); if (!out) { command_fail(cmd, LIGHTNINGD,