Browse Source

param: added json_tok_string

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 6 years ago
committed by Rusty Russell
parent
commit
47510a8e74
  1. 12
      lightningd/connect_control.c
  2. 22
      lightningd/invoice.c
  3. 9
      lightningd/json.c
  4. 5
      lightningd/json.h
  5. 13
      lightningd/pay.c
  6. 16
      lightningd/payalgo.c

12
lightningd/connect_control.c

@ -74,7 +74,6 @@ static void connect_cmd_succeed(struct command *cmd, const struct pubkey *id)
static void json_connect(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
const jsmntok_t *hosttok;
u32 *port;
jsmntok_t *idtok;
struct pubkey id;
@ -89,7 +88,7 @@ static void json_connect(struct command *cmd,
if (!param(cmd, buffer, params,
p_req("id", json_tok_tok, (const jsmntok_t **) &idtok),
p_opt("host", json_tok_tok, &hosttok),
p_opt("host", json_tok_string, &name),
p_opt("port", json_tok_number, &port),
NULL))
return;
@ -113,7 +112,7 @@ static void json_connect(struct command *cmd,
return;
}
if (hosttok && ataddr) {
if (name && ataddr) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Can't specify host as both xxx@yyy "
"and separate argument");
@ -121,13 +120,8 @@ static void json_connect(struct command *cmd,
}
/* Get parseable host if provided somehow */
if (hosttok)
name = tal_strndup(cmd, buffer + hosttok->start,
hosttok->end - hosttok->start);
else if (ataddr)
if (!name && ataddr)
name = ataddr;
else
name = NULL;
/* Port without host name? */
if (port && !name) {

22
lightningd/invoice.c

@ -325,7 +325,6 @@ static void json_delinvoice(struct command *cmd,
{
struct invoice i;
const struct invoice_details *details;
const jsmntok_t *statustok;
struct json_result *response = new_json_result(cmd);
const char *status, *actual_status;
struct json_escaped *label;
@ -333,7 +332,7 @@ static void json_delinvoice(struct command *cmd,
if (!param(cmd, buffer, params,
p_req("label", json_tok_label, &label),
p_req("status", json_tok_tok, &statustok),
p_req("status", json_tok_string, &status),
NULL))
return;
@ -344,8 +343,6 @@ static void json_delinvoice(struct command *cmd,
details = wallet_invoice_details(cmd, cmd->ld->wallet, i);
status = tal_strndup(cmd, buffer + statustok->start,
statustok->end - statustok->start);
/* This is time-sensitive, so only call once; otherwise error msg
* might not make sense if it changed! */
actual_status = invoice_status_str(details);
@ -543,26 +540,17 @@ static void json_add_fallback(struct json_result *response,
static void json_decodepay(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
const jsmntok_t *bolt11tok, *desctok;
struct bolt11 *b11;
struct json_result *response;
char *str, *desc, *fail;
const char *str, *desc;
char *fail;
if (!param(cmd, buffer, params,
p_req("bolt11", json_tok_tok, &bolt11tok),
p_opt("description", json_tok_tok, &desctok),
p_req("bolt11", json_tok_string, &str),
p_opt("description", json_tok_string, &desc),
NULL))
return;
str = tal_strndup(cmd, buffer + bolt11tok->start,
bolt11tok->end - bolt11tok->start);
if (desctok)
desc = tal_strndup(cmd, buffer + desctok->start,
desctok->end - desctok->start);
else
desc = NULL;
b11 = bolt11_decode(cmd, str, desc, &fail);
if (!b11) {

9
lightningd/json.c

@ -159,6 +159,15 @@ bool json_tok_escaped_string(struct command *cmd, const char *name,
return false;
}
bool json_tok_string(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok,
const char **str)
{
*str = tal_strndup(cmd, buffer + tok->start,
tok->end - tok->start);
return true;
}
bool json_tok_label(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok,
struct json_escaped **label)

5
lightningd/json.h

@ -64,6 +64,11 @@ bool json_tok_escaped_string(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok,
const char **str);
/* Extract a string */
bool json_tok_string(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok,
const char **str);
/* Extract a label. It is either an escaped string or a number. */
bool json_tok_label(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok,

13
lightningd/pay.c

@ -1061,28 +1061,27 @@ static void json_listpayments(struct command *cmd, const char *buffer,
{
const struct wallet_payment **payments;
struct json_result *response = new_json_result(cmd);
const jsmntok_t *bolt11tok, *rhashtok;
const jsmntok_t *rhashtok;
struct sha256 *rhash = NULL;
const char *b11str;
if (!param(cmd, buffer, params,
p_opt("bolt11", json_tok_tok, &bolt11tok),
p_opt("bolt11", json_tok_string, &b11str),
p_opt("payment_hash", json_tok_tok, &rhashtok),
NULL))
return;
if (rhashtok && bolt11tok) {
if (rhashtok && b11str) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Can only specify one of"
" {bolt11} or {payment_hash}");
return;
}
if (bolt11tok) {
if (b11str) {
struct bolt11 *b11;
char *b11str, *fail;
char *fail;
b11str = tal_strndup(cmd, buffer + bolt11tok->start,
bolt11tok->end - bolt11tok->start);
b11 = bolt11_decode(cmd, b11str, NULL, &fail);
if (!b11) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,

16
lightningd/payalgo.c

@ -599,21 +599,21 @@ static void json_pay_stop_retrying(struct pay *pay)
static void json_pay(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
const jsmntok_t *bolt11tok, *desctok;
double *riskfactor;
double *maxfeepercent;
u64 *msatoshi;
struct pay *pay = tal(cmd, struct pay);
struct bolt11 *b11;
char *fail, *b11str, *desc;
const char *b11str, *desc;
char *fail;
unsigned int *retryfor;
unsigned int *maxdelay;
unsigned int *exemptfee;
if (!param(cmd, buffer, params,
p_req("bolt11", json_tok_tok, &bolt11tok),
p_req("bolt11", json_tok_string, &b11str),
p_opt("msatoshi", json_tok_u64, &msatoshi),
p_opt("description", json_tok_tok, &desctok),
p_opt("description", json_tok_string, &desc),
p_opt_def("riskfactor", json_tok_double, &riskfactor, 1.0),
p_opt_def("maxfeepercent", json_tok_percent, &maxfeepercent, 0.5),
p_opt_def("retry_for", json_tok_number, &retryfor, 60),
@ -623,14 +623,6 @@ static void json_pay(struct command *cmd,
NULL))
return;
b11str = tal_strndup(cmd, buffer + bolt11tok->start,
bolt11tok->end - bolt11tok->start);
if (desctok)
desc = tal_strndup(cmd, buffer + desctok->start,
desctok->end - desctok->start);
else
desc = NULL;
b11 = bolt11_decode(pay, b11str, desc, &fail);
if (!b11) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,

Loading…
Cancel
Save