param: upgraded json_tok_newaddr

Made it a local static since its a one-off.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
Mark Beckwith 2018-08-14 12:52:42 -05:00 committed by Rusty Russell
parent 947752b9cc
commit 2a0c2601c0
5 changed files with 23 additions and 20 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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'"},

View File

@ -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)

View File

@ -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,