Browse Source

pay: Reduce nesting and fix minor type inconsistency

ppa-0.6.1
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
bc7393bb64
  1. 15
      lightningd/pay.c

15
lightningd/pay.c

@ -1123,20 +1123,19 @@ static void json_listpayments(struct command *cmd, const char *buffer,
NULL)) NULL))
return; return;
if (bolt11tok) { if (rhashtok && bolt11tok) {
struct bolt11 *b11;
char *b11str, *fail;
if (rhashtok) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Can only specify one of" "Can only specify one of"
" {bolt11} or {payment_hash}"); " {bolt11} or {payment_hash}");
return; return;
} }
if (bolt11tok) {
struct bolt11 *b11;
char *b11str, *fail;
b11str = tal_strndup(cmd, buffer + bolt11tok->start, b11str = tal_strndup(cmd, buffer + bolt11tok->start,
bolt11tok->end - bolt11tok->start); bolt11tok->end - bolt11tok->start);
b11 = bolt11_decode(cmd, b11str, NULL, &fail); b11 = bolt11_decode(cmd, b11str, NULL, &fail);
if (!b11) { if (!b11) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS, command_fail(cmd, JSONRPC2_INVALID_PARAMS,
@ -1160,13 +1159,15 @@ static void json_listpayments(struct command *cmd, const char *buffer,
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash); payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash);
json_object_start(response, NULL); json_object_start(response, NULL);
json_array_start(response, "payments"); json_array_start(response, "payments");
for (int i=0; i<tal_count(payments); i++) { for (size_t i = 0; i < tal_count(payments); i++) {
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_payment_fields(response, payments[i]); json_add_payment_fields(response, payments[i]);
json_object_end(response); json_object_end(response);
} }
json_array_end(response); json_array_end(response);
json_object_end(response); json_object_end(response);
command_success(cmd, response); command_success(cmd, response);
} }

Loading…
Cancel
Save