mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
lightningd: have json_stream_success start the "result" object.
"result" should always be an object (so that we can add new fields), so make that implicit in json_stream_success. This makes our primitives well-formed: we previously used NULL as our fieldname when calling the first json_object_start, which is a hack since we're actually in an object and the fieldname is 'result' (which was already written by json_object_start). There were only two cases which didn't do this: 1. dev-memdump returned an array. No API guarantees on this. 2. shutdown returned a string. I temporarily made shutdown return an empty object, which shouldn't break anything, but I want to fix that later anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
0e336ac252
commit
bb7bbd03c5
@ -143,7 +143,7 @@ static void broadcast_remainder(struct bitcoind *bitcoind,
|
||||
if (txs->cursor == tal_count(txs->txs)) {
|
||||
if (txs->cmd)
|
||||
was_pending(command_success(txs->cmd,
|
||||
null_response(txs->cmd)));
|
||||
json_stream_success(txs->cmd)));
|
||||
tal_free(txs);
|
||||
return;
|
||||
}
|
||||
@ -491,7 +491,6 @@ static struct command_result *json_feerates(struct command *cmd,
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_object_start(response, json_feerate_style_name(*style));
|
||||
for (size_t i = 0; i < ARRAY_SIZE(feerates); i++) {
|
||||
if (!feerates[i])
|
||||
@ -522,8 +521,6 @@ static struct command_result *json_feerates(struct command *cmd,
|
||||
json_object_end(response);
|
||||
}
|
||||
|
||||
json_object_end(response);
|
||||
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,7 @@ static struct command_result *connect_cmd_succeed(struct command *cmd,
|
||||
const struct node_id *id)
|
||||
{
|
||||
struct json_stream *response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_node_id(response, "id", id);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,6 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "nodes");
|
||||
|
||||
for (i = 0; i < tal_count(nodes); i++) {
|
||||
@ -229,7 +228,6 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
||||
json_object_end(response);
|
||||
}
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
was_pending(command_success(cmd, response));
|
||||
}
|
||||
|
||||
@ -274,9 +272,7 @@ static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, con
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_route(response, "route", hops, tal_count(hops));
|
||||
json_object_end(response);
|
||||
was_pending(command_success(cmd, response));
|
||||
}
|
||||
|
||||
@ -436,7 +432,6 @@ static void json_listchannels_reply(struct subd *gossip UNUSED, const u8 *reply,
|
||||
req, -1, 0, json_listchannels_reply, linfo);
|
||||
} else {
|
||||
json_array_end(linfo->response);
|
||||
json_object_end(linfo->response);
|
||||
was_pending(command_success(linfo->cmd, linfo->response));
|
||||
}
|
||||
}
|
||||
@ -462,7 +457,6 @@ static struct command_result *json_listchannels(struct command *cmd,
|
||||
|
||||
/* Start JSON response, then we stream. */
|
||||
linfo->response = json_stream_success(cmd);
|
||||
json_object_start(linfo->response, NULL);
|
||||
json_array_start(linfo->response, "channels");
|
||||
|
||||
req = towire_gossip_getchannels_request(cmd, linfo->id, linfo->source,
|
||||
@ -501,9 +495,7 @@ static void json_scids_reply(struct subd *gossip UNUSED, const u8 *reply,
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_bool(response, "complete", complete);
|
||||
json_object_end(response);
|
||||
was_pending(command_success(cmd, response));
|
||||
}
|
||||
|
||||
@ -573,7 +565,7 @@ json_dev_send_timestamp_filter(struct command *cmd,
|
||||
msg = towire_gossip_send_timestamp_filter(NULL, id, *first, *range);
|
||||
subd_send_msg(cmd->ld->gossip, take(msg));
|
||||
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command dev_send_timestamp_filter = {
|
||||
@ -609,7 +601,6 @@ static void json_channel_range_reply(struct subd *gossip UNUSED, const u8 *reply
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
/* As this is a dev interface, we don't bother saving and
|
||||
* returning all the replies, just the final one. */
|
||||
json_add_num(response, "final_first_block", final_first_block);
|
||||
@ -619,7 +610,6 @@ static void json_channel_range_reply(struct subd *gossip UNUSED, const u8 *reply
|
||||
for (size_t i = 0; i < tal_count(scids); i++)
|
||||
json_add_short_channel_id(response, NULL, &scids[i]);
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
was_pending(command_success(cmd, response));
|
||||
}
|
||||
|
||||
@ -671,7 +661,7 @@ json_dev_set_max_scids_encode_size(struct command *cmd,
|
||||
msg = towire_gossip_dev_set_max_scids_encode_size(NULL, *max);
|
||||
subd_send_msg(cmd->ld->gossip, take(msg));
|
||||
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command dev_set_max_scids_encode_size = {
|
||||
@ -692,7 +682,7 @@ static struct command_result *json_dev_suppress_gossip(struct command *cmd,
|
||||
|
||||
subd_send_msg(cmd->ld->gossip, take(towire_gossip_dev_suppress(NULL)));
|
||||
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command dev_suppress_gossip = {
|
||||
@ -720,7 +710,7 @@ static void dev_compact_gossip_store_reply(struct subd *gossip UNUSED,
|
||||
was_pending(command_fail(cmd, LIGHTNINGD,
|
||||
"gossip_compact_store failed"));
|
||||
else
|
||||
was_pending(command_success(cmd, null_response(cmd)));
|
||||
was_pending(command_success(cmd, json_stream_success(cmd)));
|
||||
}
|
||||
|
||||
static struct command_result *json_dev_compact_gossip_store(struct command *cmd,
|
||||
|
@ -46,7 +46,6 @@ static const char *invoice_status_str(const struct invoice_details *inv)
|
||||
static void json_add_invoice(struct json_stream *response,
|
||||
const struct invoice_details *inv)
|
||||
{
|
||||
json_object_start(response, NULL);
|
||||
json_add_escaped_string(response, "label", inv->label);
|
||||
json_add_string(response, "bolt11", inv->bolt11);
|
||||
json_add_hex(response, "payment_hash", &inv->rhash, sizeof(inv->rhash));
|
||||
@ -66,8 +65,6 @@ static void json_add_invoice(struct json_stream *response,
|
||||
json_add_string(response, "description", inv->description);
|
||||
|
||||
json_add_u64(response, "expires_at", inv->expiry_time);
|
||||
|
||||
json_object_end(response);
|
||||
}
|
||||
|
||||
static struct command_result *tell_waiter(struct command *cmd,
|
||||
@ -86,6 +83,7 @@ static struct command_result *tell_waiter(struct command *cmd,
|
||||
response = json_stream_fail(cmd, -2,
|
||||
"invoice expired during wait");
|
||||
json_add_invoice(response, details);
|
||||
json_object_end(response);
|
||||
return command_failed(cmd, response);
|
||||
}
|
||||
}
|
||||
@ -512,7 +510,6 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd,
|
||||
details = wallet_invoice_details(info, wallet, invoice);
|
||||
|
||||
response = json_stream_success(info->cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_hex(response, "payment_hash", details->rhash.u.u8,
|
||||
sizeof(details->rhash));
|
||||
json_add_u64(response, "expires_at", details->expiry_time);
|
||||
@ -538,7 +535,6 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd,
|
||||
"No channels have sufficient"
|
||||
" incoming capacity");
|
||||
}
|
||||
json_object_end(response);
|
||||
|
||||
was_pending(command_success(info->cmd, response));
|
||||
}
|
||||
@ -809,7 +805,9 @@ static void json_add_invoices(struct json_stream *response,
|
||||
struct invoice invoice;
|
||||
if (wallet_invoice_find_by_label(wallet, &invoice, label)) {
|
||||
details = wallet_invoice_details(response, wallet, invoice);
|
||||
json_object_start(response, NULL);
|
||||
json_add_invoice(response, details);
|
||||
json_object_end(response);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -817,7 +815,9 @@ static void json_add_invoices(struct json_stream *response,
|
||||
memset(&it, 0, sizeof(it));
|
||||
while (wallet_invoice_iterate(wallet, &it)) {
|
||||
details = wallet_invoice_iterator_deref(response, wallet, &it);
|
||||
json_object_start(response, NULL);
|
||||
json_add_invoice(response, details);
|
||||
json_object_end(response);
|
||||
}
|
||||
}
|
||||
|
||||
@ -834,11 +834,9 @@ static struct command_result *json_listinvoices(struct command *cmd,
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "invoices");
|
||||
json_add_invoices(response, wallet, label);
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -918,7 +916,7 @@ static struct command_result *json_delexpiredinvoice(struct command *cmd,
|
||||
|
||||
wallet_invoice_delete_expired(cmd->ld->wallet, *maxexpirytime);
|
||||
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
static const struct json_command delexpiredinvoice_command = {
|
||||
"delexpiredinvoice",
|
||||
@ -1069,8 +1067,6 @@ static struct command_result *json_decodepay(struct command *cmd,
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
|
||||
json_add_string(response, "currency", b11->chain->bip173_name);
|
||||
json_add_u64(response, "created_at", b11->timestamp);
|
||||
json_add_u64(response, "expiry", b11->expiry);
|
||||
@ -1151,7 +1147,6 @@ static struct command_result *json_decodepay(struct command *cmd,
|
||||
json_add_string(response, "signature",
|
||||
type_to_string(cmd, secp256k1_ecdsa_signature,
|
||||
&b11->sig));
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -182,16 +182,12 @@ static struct command_result *json_stop(struct command *cmd,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct json_stream *response;
|
||||
|
||||
if (!param(cmd, buffer, params, NULL))
|
||||
return command_param_failed();
|
||||
|
||||
/* This can't have closed yet! */
|
||||
cmd->jcon->stop = true;
|
||||
response = json_stream_success(cmd);
|
||||
json_add_string(response, NULL, "Shutting down");
|
||||
return command_success(cmd, response);
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command stop_command = {
|
||||
@ -219,9 +215,7 @@ static struct command_result *json_rhash(struct command *cmd,
|
||||
/* Hash in place. */
|
||||
sha256(secret, secret, sizeof(*secret));
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_hex(response, "rhash", secret, sizeof(*secret));
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -241,9 +235,7 @@ struct slowcmd {
|
||||
|
||||
static void slowcmd_finish(struct slowcmd *sc)
|
||||
{
|
||||
json_object_start(sc->js, NULL);
|
||||
json_add_num(sc->js, "msec", *sc->msec);
|
||||
json_object_end(sc->js);
|
||||
was_pending(command_success(sc->cmd, sc->js));
|
||||
}
|
||||
|
||||
@ -388,14 +380,12 @@ static struct command_result *json_help(struct command *cmd,
|
||||
asort(commands, tal_count(commands), compare_commands_name, NULL);
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "help");
|
||||
for (size_t i = 0; i < tal_count(commands); i++) {
|
||||
if (!one_cmd || one_cmd == commands[i])
|
||||
json_add_help_command(cmd, response, commands[i]);
|
||||
}
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
@ -412,16 +402,6 @@ static const struct json_command *find_cmd(const struct jsonrpc *rpc,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct json_stream *null_response(struct command *cmd)
|
||||
{
|
||||
struct json_stream *response;
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_object_end(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/* This can be called directly on shutdown, even with unfinished cmd */
|
||||
static void destroy_command(struct command *cmd)
|
||||
{
|
||||
@ -451,7 +431,7 @@ struct command_result *command_success(struct command *cmd,
|
||||
{
|
||||
assert(cmd);
|
||||
assert(cmd->have_json_stream);
|
||||
json_stream_append(result, " }\n\n");
|
||||
json_stream_append(result, " } }\n\n");
|
||||
|
||||
return command_raw_complete(cmd, result);
|
||||
}
|
||||
@ -543,6 +523,7 @@ struct json_stream *json_stream_success(struct command *cmd)
|
||||
{
|
||||
struct json_stream *r = json_start(cmd);
|
||||
json_stream_append(r, "\"result\" : ");
|
||||
json_object_start(r, NULL);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -568,6 +549,7 @@ struct json_stream *json_stream_fail(struct command *cmd,
|
||||
struct json_stream *r = json_stream_fail_nodata(cmd, code, errmsg);
|
||||
|
||||
json_stream_append(r, ", \"data\" : ");
|
||||
json_object_start(r, NULL);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -1169,9 +1151,7 @@ static struct command_result *json_check(struct command *cmd,
|
||||
return res;
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "command_to_check", cmd->json_cmd->name);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ struct jsonrpc_request {
|
||||
};
|
||||
|
||||
/**
|
||||
* json_stream_success - start streaming a successful json result.
|
||||
* json_stream_success - start streaming a successful json result object.
|
||||
* @cmd: the command we're running.
|
||||
*
|
||||
* The returned value should go to command_success() when done.
|
||||
@ -86,13 +86,14 @@ struct jsonrpc_request {
|
||||
struct json_stream *json_stream_success(struct command *cmd);
|
||||
|
||||
/**
|
||||
* json_stream_fail - start streaming a failed json result.
|
||||
* json_stream_fail - start streaming a failed json result, with data object.
|
||||
* @cmd: the command we're running.
|
||||
* @code: the error code from common/jsonrpc_errors.h
|
||||
* @errmsg: the error string.
|
||||
*
|
||||
* The returned value should go to command_failed() when done;
|
||||
* json_add_* will be placed into the 'data' field of the 'error' JSON reply.
|
||||
* You need to json_object_end() once you're done!
|
||||
*/
|
||||
struct json_stream *json_stream_fail(struct command *cmd,
|
||||
int code,
|
||||
@ -110,12 +111,11 @@ struct json_stream *json_stream_fail_nodata(struct command *cmd,
|
||||
int code,
|
||||
const char *errmsg);
|
||||
|
||||
struct json_stream *null_response(struct command *cmd);
|
||||
|
||||
/* These returned values are never NULL. */
|
||||
struct command_result *command_success(struct command *cmd,
|
||||
struct json_stream *response)
|
||||
WARN_UNUSED_RESULT;
|
||||
|
||||
struct command_result *command_failed(struct command *cmd,
|
||||
struct json_stream *result)
|
||||
WARN_UNUSED_RESULT;
|
||||
|
@ -732,12 +732,10 @@ static struct command_result *json_getlog(struct command *cmd,
|
||||
response = json_stream_success(cmd);
|
||||
/* Suppress logging for this stream, to not bloat io logs */
|
||||
json_stream_log_suppress_for_cmd(response, cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_time(response, "created_at", log_init_time(lr)->ts);
|
||||
json_add_num(response, "bytes_used", (unsigned int) log_used(lr));
|
||||
json_add_num(response, "bytes_max", (unsigned int) log_max_mem(lr));
|
||||
json_add_log(response, lr, *minlevel);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ static struct command_result *json_memdump(struct command *cmd,
|
||||
return command_param_failed();
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
add_memdump(response, NULL, NULL, cmd);
|
||||
add_memdump(response, "memdump", NULL, cmd);
|
||||
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
@ -196,9 +196,7 @@ static void report_leak_info2(struct leak_info *leak_info)
|
||||
{
|
||||
struct json_stream *response = json_stream_success(leak_info->cmd);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
scan_mem(leak_info->cmd, response, leak_info->cmd->ld, leak_info->leaker);
|
||||
json_object_end(response);
|
||||
|
||||
was_pending(command_success(leak_info->cmd, response));
|
||||
}
|
||||
|
@ -261,12 +261,10 @@ static void funding_broadcast_success(struct channel *channel)
|
||||
struct command *cmd = fc->cmd;
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "tx", fc->hextx);
|
||||
json_add_txid(response, "txid", &channel->funding_txid);
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id, &fc->cid));
|
||||
json_object_end(response);
|
||||
was_pending(command_success(cmd, response));
|
||||
|
||||
/* Frees fc too */
|
||||
|
@ -1066,7 +1066,6 @@ static struct command_result *json_listconfigs(struct command *cmd,
|
||||
|
||||
if (!configtok) {
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "# version", version());
|
||||
}
|
||||
|
||||
@ -1091,10 +1090,8 @@ static struct command_result *json_listconfigs(struct command *cmd,
|
||||
name + 1, len - 1))
|
||||
continue;
|
||||
|
||||
if (!response) {
|
||||
if (!response)
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
}
|
||||
add_config(cmd->ld, response, &opt_table[i],
|
||||
name+1, len-1);
|
||||
}
|
||||
@ -1106,7 +1103,6 @@ static struct command_result *json_listconfigs(struct command *cmd,
|
||||
json_tok_full_len(configtok),
|
||||
json_tok_full(buffer, configtok));
|
||||
}
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -116,9 +116,7 @@ static struct command_result *sendpay_success(struct command *cmd,
|
||||
assert(payment->status == PAYMENT_COMPLETE);
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_payment_fields(response, payment);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -132,7 +130,6 @@ json_add_routefail_info(struct json_stream *js,
|
||||
{
|
||||
const char *failcodename = onion_type_name(failcode);
|
||||
|
||||
json_object_start(js, NULL);
|
||||
json_add_num(js, "erring_index", erring_index);
|
||||
json_add_num(js, "failcode", failcode);
|
||||
/* FIXME: Better way to detect this? */
|
||||
@ -141,7 +138,6 @@ json_add_routefail_info(struct json_stream *js,
|
||||
json_add_node_id(js, "erring_node", erring_node);
|
||||
json_add_short_channel_id(js, "erring_channel", erring_channel);
|
||||
json_add_num(js, "erring_direction", channel_dir);
|
||||
json_object_end(js);
|
||||
}
|
||||
|
||||
/* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */
|
||||
@ -157,7 +153,6 @@ sendpay_fail(struct command *cmd,
|
||||
if (pay_errcode == PAY_UNPARSEABLE_ONION) {
|
||||
data = json_stream_fail(cmd, PAY_UNPARSEABLE_ONION,
|
||||
"Malformed error reply");
|
||||
json_object_start(data, NULL);
|
||||
json_add_hex_talarr(data, "onionreply", onionreply);
|
||||
json_object_end(data);
|
||||
return command_failed(cmd, data);
|
||||
@ -174,6 +169,7 @@ sendpay_fail(struct command *cmd,
|
||||
&fail->erring_node,
|
||||
&fail->erring_channel,
|
||||
fail->channel_dir);
|
||||
json_object_end(data);
|
||||
return command_failed(cmd, data);
|
||||
}
|
||||
|
||||
@ -183,11 +179,9 @@ json_sendpay_in_progress(struct command *cmd,
|
||||
const struct wallet_payment *payment)
|
||||
{
|
||||
struct json_stream *response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "message",
|
||||
"Monitor status with listpayments or waitsendpay");
|
||||
json_add_payment_fields(response, payment);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -678,6 +672,7 @@ send_payment(struct lightningd *ld,
|
||||
json_add_routefail_info(data, 0, WIRE_UNKNOWN_NEXT_PEER,
|
||||
&ld->id, &route[0].channel_id,
|
||||
node_id_idx(&ld->id, &route[0].nodeid));
|
||||
json_object_end(data);
|
||||
return command_failed(cmd, data);
|
||||
}
|
||||
|
||||
@ -977,7 +972,6 @@ static struct command_result *json_listsendpays(struct command *cmd,
|
||||
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash);
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
|
||||
json_array_start(response, "payments");
|
||||
for (size_t i = 0; i < tal_count(payments); i++) {
|
||||
@ -987,7 +981,6 @@ static struct command_result *json_listsendpays(struct command *cmd,
|
||||
}
|
||||
json_array_end(response);
|
||||
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
@ -242,14 +242,12 @@ resolve_one_close_command(struct close_command *cc, bool cooperative)
|
||||
|
||||
bitcoin_txid(cc->channel->last_tx, &txid);
|
||||
|
||||
json_object_start(result, NULL);
|
||||
json_add_tx(result, "tx", cc->channel->last_tx);
|
||||
json_add_txid(result, "txid", &txid);
|
||||
if (cooperative)
|
||||
json_add_string(result, "type", "mutual");
|
||||
else
|
||||
json_add_string(result, "type", "unilateral");
|
||||
json_object_end(result);
|
||||
|
||||
was_pending(command_success(cc->cmd, result));
|
||||
}
|
||||
@ -1085,7 +1083,6 @@ static struct command_result *json_listpeers(struct command *cmd,
|
||||
return command_param_failed();
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "peers");
|
||||
if (specific_id) {
|
||||
peer = peer_by_id(cmd->ld, specific_id);
|
||||
@ -1096,7 +1093,7 @@ static struct command_result *json_listpeers(struct command *cmd,
|
||||
json_add_peer(cmd->ld, response, peer, ll);
|
||||
}
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -1192,7 +1189,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
/* Easy case: peer can simply be forgotten. */
|
||||
kill_uncommitted_channel(uc, "close command called");
|
||||
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Peer has no active channel");
|
||||
@ -1326,7 +1323,7 @@ static struct command_result *json_disconnect(struct command *cmd,
|
||||
if (*force) {
|
||||
channel_fail_transient(channel,
|
||||
"disconnect command force=true");
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
return command_fail(cmd, LIGHTNINGD, "Peer is in state %s",
|
||||
channel_state_name(channel));
|
||||
@ -1336,7 +1333,7 @@ static struct command_result *json_disconnect(struct command *cmd,
|
||||
}
|
||||
kill_uncommitted_channel(peer->uncommitted_channel,
|
||||
"disconnect command");
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command disconnect_command = {
|
||||
@ -1362,7 +1359,6 @@ static struct command_result *json_getinfo(struct command *cmd,
|
||||
return command_param_failed();
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_node_id(response, "id", &cmd->ld->id);
|
||||
json_add_string(response, "alias", (const char *)cmd->ld->alias);
|
||||
json_add_hex_talarr(response, "color", cmd->ld->rgb);
|
||||
@ -1408,7 +1404,6 @@ static struct command_result *json_getinfo(struct command *cmd,
|
||||
wallet_total_forward_fees(cmd->ld->wallet),
|
||||
"msatoshi_fees_collected",
|
||||
"fees_collected_msat");
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -1535,7 +1530,6 @@ static struct command_result *json_setchannelfee(struct command *cmd,
|
||||
|
||||
/* Open JSON response object for later iteration */
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_num(response, "base", *base);
|
||||
json_add_num(response, "ppm", *ppm);
|
||||
json_array_start(response, "channels");
|
||||
@ -1565,7 +1559,6 @@ static struct command_result *json_setchannelfee(struct command *cmd,
|
||||
|
||||
/* Close and return response */
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -1615,9 +1608,7 @@ static struct command_result *json_sign_last_tx(struct command *cmd,
|
||||
channel->last_tx->wtx->num_outputs);
|
||||
|
||||
sign_last_tx(channel);
|
||||
json_object_start(response, NULL);
|
||||
json_add_tx(response, "tx", channel->last_tx);
|
||||
json_object_end(response);
|
||||
remove_sig(channel->last_tx);
|
||||
|
||||
return command_success(cmd, response);
|
||||
@ -1658,7 +1649,7 @@ static struct command_result *json_dev_fail(struct command *cmd,
|
||||
}
|
||||
|
||||
channel_internal_error(channel, "Failing due to dev-fail command");
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command dev_fail_command = {
|
||||
@ -1674,7 +1665,7 @@ static void dev_reenable_commit_finished(struct subd *channeld UNUSED,
|
||||
const int *fds UNUSED,
|
||||
struct command *cmd)
|
||||
{
|
||||
was_pending(command_success(cmd, null_response(cmd)));
|
||||
was_pending(command_success(cmd, json_stream_success(cmd)));
|
||||
}
|
||||
|
||||
static struct command_result *json_dev_reenable_commit(struct command *cmd,
|
||||
@ -1752,11 +1743,9 @@ static void process_dev_forget_channel(struct bitcoind *bitcoind UNUSED,
|
||||
return;
|
||||
}
|
||||
response = json_stream_success(forget->cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_bool(response, "forced", forget->force);
|
||||
json_add_bool(response, "funding_unspent", txout != NULL);
|
||||
json_add_txid(response, "funding_txid", &forget->channel->funding_txid);
|
||||
json_object_end(response);
|
||||
|
||||
/* Set error so we don't try to reconnect. */
|
||||
forget->channel->error = towire_errorfmt(forget->channel, NULL,
|
||||
|
@ -2075,7 +2075,7 @@ static struct command_result *json_dev_ignore_htlcs(struct command *cmd,
|
||||
}
|
||||
peer->ignore_htlcs = *ignore;
|
||||
|
||||
return command_success(cmd, null_response(cmd));
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static const struct json_command dev_ignore_htlcs = {
|
||||
@ -2148,9 +2148,7 @@ static struct command_result *json_listforwards(struct command *cmd,
|
||||
return command_param_failed();
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
listforwardings_add_forwardings(response, cmd->ld->wallet);
|
||||
json_object_end(response);
|
||||
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
@ -73,9 +73,7 @@ void ping_reply(struct subd *subd, const u8 *msg)
|
||||
else {
|
||||
struct json_stream *response = json_stream_success(pc->cmd);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_num(response, "totlen", totlen);
|
||||
json_object_end(response);
|
||||
was_pending(command_success(pc->cmd, response));
|
||||
}
|
||||
}
|
||||
|
@ -291,9 +291,6 @@ void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEE
|
||||
/* Generated stub for notify_disconnect */
|
||||
void notify_disconnect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED)
|
||||
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for null_response */
|
||||
struct json_stream *null_response(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "null_response called!\n"); abort(); }
|
||||
/* Generated stub for onchaind_funding_spent */
|
||||
enum watch_result onchaind_funding_spent(struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_tx *tx UNNEEDED,
|
||||
|
@ -371,9 +371,6 @@ void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEE
|
||||
/* Generated stub for notify_disconnect */
|
||||
void notify_disconnect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED)
|
||||
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for null_response */
|
||||
struct json_stream *null_response(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "null_response called!\n"); abort(); }
|
||||
/* Generated stub for onchaind_funding_spent */
|
||||
enum watch_result onchaind_funding_spent(struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_tx *tx UNNEEDED,
|
||||
|
@ -68,10 +68,8 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED,
|
||||
assert(amount_sat_greater_eq(change, utx->wtx->change));
|
||||
|
||||
struct json_stream *response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_tx(response, "tx", utx->tx);
|
||||
json_add_string(response, "txid", output);
|
||||
json_object_end(response);
|
||||
was_pending(command_success(cmd, response));
|
||||
} else {
|
||||
was_pending(command_fail(cmd, LIGHTNINGD,
|
||||
@ -228,10 +226,8 @@ static struct command_result *json_txprepare(struct command *cmd,
|
||||
add_unreleased_tx(cmd->ld->wallet, utx);
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_tx(response, "unsigned_tx", utx->tx);
|
||||
json_add_txid(response, "txid", &utx->txid);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
static const struct json_command txprepare_command = {
|
||||
@ -314,10 +310,8 @@ static struct command_result *json_txdiscard(struct command *cmd,
|
||||
tal_steal(cmd, utx);
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_tx(response, "unsigned_tx", utx->tx);
|
||||
json_add_txid(response, "txid", &utx->txid);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -512,7 +506,6 @@ static struct command_result *json_newaddr(struct command *cmd,
|
||||
}
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
if (deprecated_apis && *addrtype != ADDR_ALL)
|
||||
json_add_string(response, "address",
|
||||
*addrtype & ADDR_BECH32 ? bech32 : p2sh);
|
||||
@ -520,7 +513,6 @@ static struct command_result *json_newaddr(struct command *cmd,
|
||||
json_add_string(response, "bech32", bech32);
|
||||
if (*addrtype & ADDR_P2SH_SEGWIT)
|
||||
json_add_string(response, "p2sh-segwit", p2sh);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -553,7 +545,6 @@ static struct command_result *json_listaddrs(struct command *cmd,
|
||||
"bip32_max_index", 0);
|
||||
}
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "addresses");
|
||||
|
||||
for (s64 keyidx = 0; keyidx <= *bip32_max_index; keyidx++) {
|
||||
@ -595,7 +586,6 @@ static struct command_result *json_listaddrs(struct command *cmd,
|
||||
json_object_end(response);
|
||||
}
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@ -625,7 +615,6 @@ static struct command_result *json_listfunds(struct command *cmd,
|
||||
|
||||
utxos = wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available);
|
||||
response = json_stream_success(cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "outputs");
|
||||
for (size_t i = 0; i < tal_count(utxos); i++) {
|
||||
json_object_start(response, NULL);
|
||||
@ -690,7 +679,6 @@ static struct command_result *json_listfunds(struct command *cmd,
|
||||
}
|
||||
}
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
@ -737,7 +725,6 @@ static void process_utxo_result(struct bitcoind *bitcoind,
|
||||
if (tal_count(rescan->utxos) == 0) {
|
||||
/* Complete the response */
|
||||
json_array_end(rescan->response);
|
||||
json_object_end(rescan->response);
|
||||
was_pending(command_success(rescan->cmd, rescan->response));
|
||||
} else {
|
||||
bitcoind_gettxout(
|
||||
@ -759,13 +746,11 @@ static struct command_result *json_dev_rescan_outputs(struct command *cmd,
|
||||
rescan->response = json_stream_success(cmd);
|
||||
rescan->cmd = cmd;
|
||||
|
||||
/* Open the result structure so we can incrementally add results */
|
||||
json_object_start(rescan->response, NULL);
|
||||
/* Open the outputs structure so we can incrementally add results */
|
||||
json_array_start(rescan->response, "outputs");
|
||||
rescan->utxos = wallet_get_utxos(rescan, cmd->ld->wallet, output_state_any);
|
||||
if (tal_count(rescan->utxos) == 0) {
|
||||
json_array_end(rescan->response);
|
||||
json_object_end(rescan->response);
|
||||
return command_success(cmd, rescan->response);
|
||||
}
|
||||
bitcoind_gettxout(cmd->ld->topology->bitcoind, &rescan->utxos[0]->txid,
|
||||
|
Loading…
Reference in New Issue
Block a user