mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
json: json_add_hex_talarr for common case of dumping a tal object in hex.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
d752a0099c
commit
eae9b81099
@@ -419,6 +419,13 @@ void json_add_hex(struct json_result *result, const char *fieldname,
|
|||||||
tal_free(hex);
|
tal_free(hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void json_add_hex_talarr(struct json_result *result,
|
||||||
|
const char *fieldname,
|
||||||
|
const tal_t *data)
|
||||||
|
{
|
||||||
|
json_add_hex(result, fieldname, data, tal_len(data));
|
||||||
|
}
|
||||||
|
|
||||||
void json_add_object(struct json_result *result, ...)
|
void json_add_object(struct json_result *result, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ void json_add_bool(struct json_result *result, const char *fieldname,
|
|||||||
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
|
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
|
||||||
void json_add_hex(struct json_result *result, const char *fieldname,
|
void json_add_hex(struct json_result *result, const char *fieldname,
|
||||||
const void *data, size_t len);
|
const void *data, size_t len);
|
||||||
|
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
|
||||||
|
void json_add_hex_talarr(struct json_result *result,
|
||||||
|
const char *fieldname,
|
||||||
|
const tal_t *data);
|
||||||
void json_add_object(struct json_result *result, ...);
|
void json_add_object(struct json_result *result, ...);
|
||||||
|
|
||||||
const char *json_result_string(const struct json_result *result);
|
const char *json_result_string(const struct json_result *result);
|
||||||
|
|||||||
@@ -212,9 +212,8 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
|||||||
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
|
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
|
||||||
json_add_u64(response, "last_timestamp",
|
json_add_u64(response, "last_timestamp",
|
||||||
nodes[i]->last_timestamp);
|
nodes[i]->last_timestamp);
|
||||||
json_add_hex(response, "global_features",
|
json_add_hex_talarr(response, "global_features",
|
||||||
nodes[i]->global_features,
|
nodes[i]->global_features);
|
||||||
tal_len(nodes[i]->global_features));
|
|
||||||
json_array_start(response, "addresses");
|
json_array_start(response, "addresses");
|
||||||
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
|
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
|
||||||
json_add_address(response, NULL, &nodes[i]->addresses[j]);
|
json_add_address(response, NULL, &nodes[i]->addresses[j]);
|
||||||
|
|||||||
@@ -638,7 +638,7 @@ static void json_add_fallback(struct json_result *response,
|
|||||||
(const u8 *)&wsh, sizeof(wsh)))
|
(const u8 *)&wsh, sizeof(wsh)))
|
||||||
json_add_string(response, "addr", out);
|
json_add_string(response, "addr", out);
|
||||||
}
|
}
|
||||||
json_add_hex(response, "hex", fallback, tal_len(fallback));
|
json_add_hex_talarr(response, "hex", fallback);
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ static void json_getinfo(struct command *cmd,
|
|||||||
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);
|
||||||
json_add_hex(response, "color", (const void *)cmd->ld->rgb, tal_len(cmd->ld->rgb));
|
json_add_hex_talarr(response, "color", cmd->ld->rgb);
|
||||||
if (cmd->ld->listen) {
|
if (cmd->ld->listen) {
|
||||||
/* These are the addresses we're announcing */
|
/* These are the addresses we're announcing */
|
||||||
json_array_start(response, "address");
|
json_array_start(response, "address");
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ static void log_to_json(unsigned int skipped,
|
|||||||
json_add_string(info->response, "source", prefix);
|
json_add_string(info->response, "source", prefix);
|
||||||
json_add_string(info->response, "log", log);
|
json_add_string(info->response, "log", log);
|
||||||
if (io)
|
if (io)
|
||||||
json_add_hex(info->response, "data", io, tal_count(io));
|
json_add_hex_talarr(info->response, "data", io);
|
||||||
|
|
||||||
json_object_end(info->response);
|
json_object_end(info->response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
|||||||
response = new_json_result(fc->cmd);
|
response = new_json_result(fc->cmd);
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
linear = linearize_tx(response, fundingtx);
|
linear = linearize_tx(response, fundingtx);
|
||||||
json_add_hex(response, "tx", linear, tal_len(linear));
|
json_add_hex_talarr(response, "tx", linear);
|
||||||
json_add_txid(response, "txid", &channel->funding_txid);
|
json_add_txid(response, "txid", &channel->funding_txid);
|
||||||
derive_channel_id(&cid, &channel->funding_txid, funding_outnum);
|
derive_channel_id(&cid, &channel->funding_txid, funding_outnum);
|
||||||
json_add_string(response, "channel_id",
|
json_add_string(response, "channel_id",
|
||||||
|
|||||||
@@ -852,8 +852,7 @@ static void json_waitsendpay_on_resolve(const struct sendpay_result *r,
|
|||||||
case PAY_UNPARSEABLE_ONION:
|
case PAY_UNPARSEABLE_ONION:
|
||||||
data = new_json_result(cmd);
|
data = new_json_result(cmd);
|
||||||
json_object_start(data, NULL);
|
json_object_start(data, NULL);
|
||||||
json_add_hex(data, "onionreply",
|
json_add_hex_talarr(data, "onionreply", r->onionreply);
|
||||||
r->onionreply, tal_len(r->onionreply));
|
|
||||||
json_object_end(data);
|
json_object_end(data);
|
||||||
|
|
||||||
assert(r->details != NULL);
|
assert(r->details != NULL);
|
||||||
@@ -878,9 +877,8 @@ static void json_waitsendpay_on_resolve(const struct sendpay_result *r,
|
|||||||
json_add_short_channel_id(data, "erring_channel",
|
json_add_short_channel_id(data, "erring_channel",
|
||||||
&fail->erring_channel);
|
&fail->erring_channel);
|
||||||
if (fail->channel_update)
|
if (fail->channel_update)
|
||||||
json_add_hex(data, "channel_update",
|
json_add_hex_talarr(data, "channel_update",
|
||||||
fail->channel_update,
|
fail->channel_update);
|
||||||
tal_len(fail->channel_update));
|
|
||||||
json_object_end(data);
|
json_object_end(data);
|
||||||
|
|
||||||
assert(r->details != NULL);
|
assert(r->details != NULL);
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ json_add_failure(struct json_result *r, char const *n,
|
|||||||
switch (f->type) {
|
switch (f->type) {
|
||||||
case FAIL_UNPARSEABLE_ONION:
|
case FAIL_UNPARSEABLE_ONION:
|
||||||
json_add_string(r, "type", "FAIL_UNPARSEABLE_ONION");
|
json_add_string(r, "type", "FAIL_UNPARSEABLE_ONION");
|
||||||
json_add_hex(r, "onionreply", f->onionreply,
|
json_add_hex_talarr(r, "onionreply", f->onionreply);
|
||||||
tal_len(f->onionreply));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAIL_PAYMENT_REPLY:
|
case FAIL_PAYMENT_REPLY:
|
||||||
@@ -69,9 +68,8 @@ json_add_failure(struct json_result *r, char const *n,
|
|||||||
json_add_short_channel_id(r, "erring_channel",
|
json_add_short_channel_id(r, "erring_channel",
|
||||||
&rf->erring_channel);
|
&rf->erring_channel);
|
||||||
if (rf->channel_update)
|
if (rf->channel_update)
|
||||||
json_add_hex(r, "channel_update",
|
json_add_hex_talarr(r, "channel_update",
|
||||||
rf->channel_update,
|
rf->channel_update);
|
||||||
tal_len(rf->channel_update));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
json_add_route(r, "route", f->route, tal_count(f->route));
|
json_add_route(r, "route", f->route, tal_count(f->route));
|
||||||
@@ -259,9 +257,8 @@ static void json_pay_failure(struct pay *pay,
|
|||||||
json_add_short_channel_id(data, "erring_channel",
|
json_add_short_channel_id(data, "erring_channel",
|
||||||
&fail->erring_channel);
|
&fail->erring_channel);
|
||||||
if (fail->channel_update)
|
if (fail->channel_update)
|
||||||
json_add_hex(data, "channel_update",
|
json_add_hex_talarr(data, "channel_update",
|
||||||
fail->channel_update,
|
fail->channel_update);
|
||||||
tal_len(fail->channel_update));
|
|
||||||
json_add_failures(data, "failures", &pay->pay_failures);
|
json_add_failures(data, "failures", &pay->pay_failures);
|
||||||
json_object_end(data);
|
json_object_end(data);
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ resolve_one_close_command(struct close_command *cc, bool cooperative)
|
|||||||
bitcoin_txid(cc->channel->last_tx, &txid);
|
bitcoin_txid(cc->channel->last_tx, &txid);
|
||||||
|
|
||||||
json_object_start(result, NULL);
|
json_object_start(result, NULL);
|
||||||
json_add_hex(result, "tx", tx, tal_len(tx));
|
json_add_hex_talarr(result, "tx", tx);
|
||||||
json_add_txid(result, "txid", &txid);
|
json_add_txid(result, "txid", &txid);
|
||||||
if (cooperative)
|
if (cooperative)
|
||||||
json_add_string(result, "type", "mutual");
|
json_add_string(result, "type", "mutual");
|
||||||
@@ -761,13 +761,11 @@ static void connectd_getpeers_complete(struct subd *connectd, const u8 *msg,
|
|||||||
struct wireaddr_internal,
|
struct wireaddr_internal,
|
||||||
&p->addr));
|
&p->addr));
|
||||||
json_array_end(response);
|
json_array_end(response);
|
||||||
json_add_hex(response, "global_features",
|
json_add_hex_talarr(response, "global_features",
|
||||||
p->global_features,
|
p->global_features);
|
||||||
tal_len(p->global_features));
|
|
||||||
|
|
||||||
json_add_hex(response, "local_features",
|
json_add_hex_talarr(response, "local_features",
|
||||||
p->local_features,
|
p->local_features);
|
||||||
tal_len(p->local_features));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json_array_start(response, "channels");
|
json_array_start(response, "channels");
|
||||||
@@ -894,13 +892,11 @@ static void connectd_getpeers_complete(struct subd *connectd, const u8 *msg,
|
|||||||
/* Fake state. */
|
/* Fake state. */
|
||||||
json_add_string(response, "state", "GOSSIPING");
|
json_add_string(response, "state", "GOSSIPING");
|
||||||
json_add_pubkey(response, "id", ids+i);
|
json_add_pubkey(response, "id", ids+i);
|
||||||
json_add_hex(response, "global_features",
|
json_add_hex_talarr(response, "global_features",
|
||||||
pf[i]->global_features,
|
pf[i]->global_features);
|
||||||
tal_len(pf[i]->global_features));
|
|
||||||
|
|
||||||
json_add_hex(response, "local_features",
|
json_add_hex_talarr(response, "local_features",
|
||||||
pf[i]->local_features,
|
pf[i]->local_features);
|
||||||
tal_len(pf[i]->local_features));
|
|
||||||
json_array_start(response, "netaddr");
|
json_array_start(response, "netaddr");
|
||||||
if (addrs[i].itype != ADDR_INTERNAL_WIREADDR
|
if (addrs[i].itype != ADDR_INTERNAL_WIREADDR
|
||||||
|| addrs[i].u.wireaddr.type != ADDR_TYPE_PADDING)
|
|| addrs[i].u.wireaddr.type != ADDR_TYPE_PADDING)
|
||||||
@@ -1190,7 +1186,7 @@ static void json_sign_last_tx(struct command *cmd,
|
|||||||
remove_sig(channel->last_tx);
|
remove_sig(channel->last_tx);
|
||||||
|
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
json_add_hex(response, "tx", linear, tal_len(linear));
|
json_add_hex_talarr(response, "tx", linear);
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
command_success(cmd, response);
|
command_success(cmd, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,10 +182,11 @@ void invoices_waitone(const tal_t *ctx UNNEEDED,
|
|||||||
void json_add_bool(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED,
|
void json_add_bool(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED,
|
||||||
bool value UNNEEDED)
|
bool value UNNEEDED)
|
||||||
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
|
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
|
||||||
/* Generated stub for json_add_hex */
|
/* Generated stub for json_add_hex_talarr */
|
||||||
void json_add_hex(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED,
|
void json_add_hex_talarr(struct json_result *result UNNEEDED,
|
||||||
const void *data UNNEEDED, size_t len UNNEEDED)
|
const char *fieldname UNNEEDED,
|
||||||
{ fprintf(stderr, "json_add_hex called!\n"); abort(); }
|
const tal_t *data UNNEEDED)
|
||||||
|
{ fprintf(stderr, "json_add_hex_talarr called!\n"); abort(); }
|
||||||
/* Generated stub for json_add_log */
|
/* Generated stub for json_add_log */
|
||||||
void json_add_log(struct json_result *result UNNEEDED,
|
void json_add_log(struct json_result *result UNNEEDED,
|
||||||
const struct log_book *lr UNNEEDED, enum log_level minlevel UNNEEDED)
|
const struct log_book *lr UNNEEDED, enum log_level minlevel UNNEEDED)
|
||||||
|
|||||||
@@ -334,11 +334,11 @@ static void json_listaddrs(struct command *cmd,
|
|||||||
json_add_u64(response, "keyidx", keyidx);
|
json_add_u64(response, "keyidx", keyidx);
|
||||||
json_add_pubkey(response, "pubkey", &pubkey);
|
json_add_pubkey(response, "pubkey", &pubkey);
|
||||||
json_add_string(response, "p2sh", out_p2sh);
|
json_add_string(response, "p2sh", out_p2sh);
|
||||||
json_add_hex(response, "p2sh_redeemscript",
|
json_add_hex_talarr(response, "p2sh_redeemscript",
|
||||||
redeemscript_p2sh, tal_count(redeemscript_p2sh));
|
redeemscript_p2sh);
|
||||||
json_add_string(response, "bech32", out_p2wpkh);
|
json_add_string(response, "bech32", out_p2wpkh);
|
||||||
json_add_hex(response, "bech32_redeemscript",
|
json_add_hex_talarr(response, "bech32_redeemscript",
|
||||||
redeemscript_p2wpkh, tal_count(redeemscript_p2wpkh));
|
redeemscript_p2wpkh);
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
}
|
}
|
||||||
json_array_end(response);
|
json_array_end(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user