mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
param: call param() all the time
Now call param() even for commands that don't accept any parameters. This is a bugfix of sorts. For example, before you could call: bitcoin-cli getinfo blah and the blah parameter would be ignored. Now you will get an error: "too many parameters: got 1, expected 0" Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
d91b94a812
commit
30b67c0334
@ -78,6 +78,9 @@ static void json_stop(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
|
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
/* This can't have closed yet! */
|
/* This can't have closed yet! */
|
||||||
cmd->jcon->stop = true;
|
cmd->jcon->stop = true;
|
||||||
json_add_string(response, NULL, "Shutting down");
|
json_add_string(response, NULL, "Shutting down");
|
||||||
@ -121,6 +124,9 @@ AUTODATA(json_command, &dev_rhash_command);
|
|||||||
static void json_crash(struct command *cmd UNUSED,
|
static void json_crash(struct command *cmd UNUSED,
|
||||||
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
|
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
|
||||||
{
|
{
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
fatal("Crash at user request");
|
fatal("Crash at user request");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +143,9 @@ static void json_getinfo(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
|
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
json_add_pubkey(response, "id", &cmd->ld->id);
|
json_add_pubkey(response, "id", &cmd->ld->id);
|
||||||
json_add_string(response, "alias", (const char *)cmd->ld->alias);
|
json_add_string(response, "alias", (const char *)cmd->ld->alias);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <lightningd/jsonrpc_errors.h>
|
#include <lightningd/jsonrpc_errors.h>
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
|
#include <lightningd/param.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static void json_add_ptr(struct json_result *response, const char *name,
|
static void json_add_ptr(struct json_result *response, const char *name,
|
||||||
@ -57,6 +58,9 @@ static void json_memdump(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
|
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
add_memdump(response, NULL, NULL, cmd);
|
add_memdump(response, NULL, NULL, cmd);
|
||||||
|
|
||||||
command_success(cmd, response);
|
command_success(cmd, response);
|
||||||
@ -151,6 +155,9 @@ static void json_memleak(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
|
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!getenv("LIGHTNINGD_DEV_MEMLEAK")) {
|
if (!getenv("LIGHTNINGD_DEV_MEMLEAK")) {
|
||||||
command_fail(cmd, LIGHTNINGD,
|
command_fail(cmd, LIGHTNINGD,
|
||||||
"Leak detection needs $LIGHTNINGD_DEV_MEMLEAK");
|
"Leak detection needs $LIGHTNINGD_DEV_MEMLEAK");
|
||||||
|
@ -253,6 +253,16 @@ static void null_params(void)
|
|||||||
assert(*intptrs[6] == 888);
|
assert(*intptrs[6] == 888);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void no_params(void)
|
||||||
|
{
|
||||||
|
struct json *j = json_parse(cmd, "[]");
|
||||||
|
assert(param(cmd, j->buffer, j->toks, NULL));
|
||||||
|
|
||||||
|
j = json_parse(cmd, "[ 'unexpected' ]");
|
||||||
|
assert(!param(cmd, j->buffer, j->toks, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
/*
|
/*
|
||||||
* Check to make sure there are no programming mistakes.
|
* Check to make sure there are no programming mistakes.
|
||||||
@ -560,12 +570,14 @@ int main(void)
|
|||||||
setup_locale();
|
setup_locale();
|
||||||
setup_tmpctx();
|
setup_tmpctx();
|
||||||
cmd = tal(tmpctx, struct command);
|
cmd = tal(tmpctx, struct command);
|
||||||
|
cmd->mode = CMD_NORMAL;
|
||||||
fail_msg = tal_arr(cmd, char, 10000);
|
fail_msg = tal_arr(cmd, char, 10000);
|
||||||
|
|
||||||
zero_params();
|
zero_params();
|
||||||
sanity();
|
sanity();
|
||||||
tok_tok();
|
tok_tok();
|
||||||
null_params();
|
null_params();
|
||||||
|
no_params();
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
bad_programmer();
|
bad_programmer();
|
||||||
#endif
|
#endif
|
||||||
|
@ -388,6 +388,10 @@ static void json_listfunds(struct command *cmd, const char *buffer UNUSED,
|
|||||||
wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available);
|
wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available);
|
||||||
char* out;
|
char* out;
|
||||||
struct pubkey funding_pubkey;
|
struct pubkey funding_pubkey;
|
||||||
|
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
json_array_start(response, "outputs");
|
json_array_start(response, "outputs");
|
||||||
for (size_t i = 0; i < tal_count(utxos); i++) {
|
for (size_t i = 0; i < tal_count(utxos); i++) {
|
||||||
@ -505,6 +509,10 @@ static void json_dev_rescan_outputs(struct command *cmd,
|
|||||||
const jsmntok_t *params UNUSED)
|
const jsmntok_t *params UNUSED)
|
||||||
{
|
{
|
||||||
struct txo_rescan *rescan = tal(cmd, struct txo_rescan);
|
struct txo_rescan *rescan = tal(cmd, struct txo_rescan);
|
||||||
|
|
||||||
|
if (!param(cmd, buffer, params, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
rescan->response = new_json_result(cmd);
|
rescan->response = new_json_result(cmd);
|
||||||
rescan->cmd = cmd;
|
rescan->cmd = cmd;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user