mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
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:
parent
947752b9cc
commit
2a0c2601c0
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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'"},
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user