mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
param: upgraded json_tok_bool
Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
e5918f4e5a
commit
8ebc95b7b0
8 changed files with 40 additions and 38 deletions
|
@ -141,23 +141,6 @@ bool json_tok_is_null(const char *buffer, const jsmntok_t *tok)
|
||||||
return buffer[tok->start] == 'n';
|
return buffer[tok->start] == 'n';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool json_tok_bool(const char *buffer, const jsmntok_t *tok, bool *b)
|
|
||||||
{
|
|
||||||
if (tok->type != JSMN_PRIMITIVE)
|
|
||||||
return false;
|
|
||||||
if (tok->end - tok->start == strlen("true")
|
|
||||||
&& memcmp(buffer + tok->start, "true", strlen("true")) == 0) {
|
|
||||||
*b = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (tok->end - tok->start == strlen("false")
|
|
||||||
&& memcmp(buffer + tok->start, "false", strlen("false")) == 0) {
|
|
||||||
*b = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
|
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
|
||||||
struct sha256 *hash)
|
struct sha256 *hash)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,9 +42,6 @@ bool json_tok_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
|
||||||
/* Extract double in range [0.0, 100.0] */
|
/* Extract double in range [0.0, 100.0] */
|
||||||
bool json_tok_percent(const char *buffer, const jsmntok_t *tok, double *num);
|
bool json_tok_percent(const char *buffer, const jsmntok_t *tok, double *num);
|
||||||
|
|
||||||
/* Extract boolean this (must be a true or false) */
|
|
||||||
bool json_tok_bool(const char *buffer, const jsmntok_t *tok, bool *b);
|
|
||||||
|
|
||||||
/* Extract sha256 hash */
|
/* Extract sha256 hash */
|
||||||
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
|
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
|
||||||
struct sha256 *hash);
|
struct sha256 *hash);
|
||||||
|
|
|
@ -91,6 +91,29 @@ void json_add_txid(struct json_result *result, const char *fieldname,
|
||||||
json_add_string(result, fieldname, hex);
|
json_add_string(result, fieldname, hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool json_tok_bool(struct command *cmd, const char *name,
|
||||||
|
const char *buffer, const jsmntok_t *tok,
|
||||||
|
bool **b)
|
||||||
|
{
|
||||||
|
*b = tal(cmd, bool);
|
||||||
|
if (tok->type == JSMN_PRIMITIVE) {
|
||||||
|
if (tok->end - tok->start == strlen("true")
|
||||||
|
&& !memcmp(buffer + tok->start, "true", strlen("true"))) {
|
||||||
|
**b = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (tok->end - tok->start == strlen("false")
|
||||||
|
&& !memcmp(buffer + tok->start, "false", strlen("false"))) {
|
||||||
|
**b = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"'%s' should be 'true' or 'false', not '%.*s'",
|
||||||
|
name, tok->end - tok->start, buffer + tok->start);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool json_tok_double(struct command *cmd, const char *name,
|
bool json_tok_double(struct command *cmd, const char *name,
|
||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
double **num)
|
double **num)
|
||||||
|
|
|
@ -41,6 +41,11 @@ void json_add_pubkey(struct json_result *response,
|
||||||
void json_add_txid(struct json_result *result, const char *fieldname,
|
void json_add_txid(struct json_result *result, const char *fieldname,
|
||||||
const struct bitcoin_txid *txid);
|
const struct bitcoin_txid *txid);
|
||||||
|
|
||||||
|
/* Extract boolean this (must be a true or false) */
|
||||||
|
bool json_tok_bool(struct command *cmd, const char *name,
|
||||||
|
const char *buffer, const jsmntok_t *tok,
|
||||||
|
bool **b);
|
||||||
|
|
||||||
/* Extract double from this (must be a number literal) */
|
/* Extract double from this (must be a number literal) */
|
||||||
bool json_tok_double(struct command *cmd, const char *name,
|
bool json_tok_double(struct command *cmd, const char *name,
|
||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
|
|
|
@ -50,7 +50,6 @@ struct fail_format {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct fail_format fail_formats[] = {
|
static struct fail_format fail_formats[] = {
|
||||||
{json_tok_bool, "'%s' should be 'true' or 'false', not '%.*s'"},
|
|
||||||
{json_tok_percent,
|
{json_tok_percent,
|
||||||
"'%s' should be a double in range [0.0, 100.0], not '%.*s'"},
|
"'%s' should be a double in range [0.0, 100.0], not '%.*s'"},
|
||||||
{json_tok_newaddr, "'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'"},
|
{json_tok_newaddr, "'%s' should be 'bech32' or 'p2sh-segwit', not '%.*s'"},
|
||||||
|
|
|
@ -833,11 +833,11 @@ static void json_close(struct command *cmd,
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
unsigned int *timeout;
|
unsigned int *timeout;
|
||||||
bool force;
|
bool *force;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_tok, &idtok),
|
p_req_tal("id", json_tok_tok, &idtok),
|
||||||
p_opt_def("force", json_tok_bool, &force, false),
|
p_opt_def_tal("force", json_tok_bool, &force, false),
|
||||||
p_opt_def_tal("timeout", json_tok_number, &timeout, 30),
|
p_opt_def_tal("timeout", json_tok_number, &timeout, 30),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
@ -891,7 +891,7 @@ static void json_close(struct command *cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register this command for later handling. */
|
/* Register this command for later handling. */
|
||||||
register_close_command(cmd->ld, cmd, channel, *timeout, force);
|
register_close_command(cmd->ld, cmd, channel, *timeout, *force);
|
||||||
|
|
||||||
/* Wait until close drops down to chain. */
|
/* Wait until close drops down to chain. */
|
||||||
command_still_pending(cmd);
|
command_still_pending(cmd);
|
||||||
|
@ -1169,22 +1169,15 @@ static void json_dev_forget_channel(struct command *cmd, const char *buffer,
|
||||||
struct dev_forget_channel_cmd *forget = tal(cmd, struct dev_forget_channel_cmd);
|
struct dev_forget_channel_cmd *forget = tal(cmd, struct dev_forget_channel_cmd);
|
||||||
forget->cmd = cmd;
|
forget->cmd = cmd;
|
||||||
|
|
||||||
/* If &forget->force is used directly in p_opt_def() below then
|
bool *force;
|
||||||
* gcc 7.3.0 fails with:
|
|
||||||
* 'operation on ‘forget->force’ may be undefined [-Werror=sequence-point]'
|
|
||||||
*
|
|
||||||
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86584
|
|
||||||
*
|
|
||||||
* Hence this indirection.
|
|
||||||
*/
|
|
||||||
bool *force = &forget->force;
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
p_opt("short_channel_id", json_tok_short_channel_id, &scid),
|
p_opt("short_channel_id", json_tok_short_channel_id, &scid),
|
||||||
p_opt_def("force", json_tok_bool, force, false),
|
p_opt_def_tal("force", json_tok_bool, &force, false),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
forget->force = *force;
|
||||||
peer = peer_by_id(cmd->ld, &peerid);
|
peer = peer_by_id(cmd->ld, &peerid);
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
command_fail(cmd, LIGHTNINGD,
|
command_fail(cmd, LIGHTNINGD,
|
||||||
|
|
|
@ -1695,11 +1695,11 @@ static void json_dev_ignore_htlcs(struct command *cmd, const char *buffer,
|
||||||
{
|
{
|
||||||
struct pubkey peerid;
|
struct pubkey peerid;
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
bool ignore;
|
bool *ignore;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("id", json_tok_pubkey, &peerid),
|
p_req("id", json_tok_pubkey, &peerid),
|
||||||
p_req("ignore", json_tok_bool, &ignore),
|
p_req_tal("ignore", json_tok_bool, &ignore),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1709,7 +1709,7 @@ static void json_dev_ignore_htlcs(struct command *cmd, const char *buffer,
|
||||||
"Could not find channel with that peer");
|
"Could not find channel with that peer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
peer->ignore_htlcs = ignore;
|
peer->ignore_htlcs = *ignore;
|
||||||
|
|
||||||
command_success(cmd, null_response(cmd));
|
command_success(cmd, null_response(cmd));
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,9 @@ void json_object_end(struct json_result *ptr UNNEEDED)
|
||||||
void json_object_start(struct json_result *ptr UNNEEDED, const char *fieldname UNNEEDED)
|
void json_object_start(struct json_result *ptr UNNEEDED, const char *fieldname UNNEEDED)
|
||||||
{ fprintf(stderr, "json_object_start called!\n"); abort(); }
|
{ fprintf(stderr, "json_object_start called!\n"); abort(); }
|
||||||
/* Generated stub for json_tok_bool */
|
/* Generated stub for json_tok_bool */
|
||||||
bool json_tok_bool(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool *b UNNEEDED)
|
bool json_tok_bool(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||||
|
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||||
|
bool **b UNNEEDED)
|
||||||
{ fprintf(stderr, "json_tok_bool called!\n"); abort(); }
|
{ fprintf(stderr, "json_tok_bool called!\n"); abort(); }
|
||||||
/* Generated stub for json_tok_channel_id */
|
/* Generated stub for json_tok_channel_id */
|
||||||
bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||||
|
|
Loading…
Add table
Reference in a new issue