Browse Source

json: json_add_hex_talarr for common case of dumping a tal object in hex.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
eae9b81099
  1. 7
      common/json.c
  2. 4
      common/json.h
  3. 5
      lightningd/gossip_control.c
  4. 2
      lightningd/invoice.c
  5. 2
      lightningd/jsonrpc.c
  6. 2
      lightningd/log.c
  7. 2
      lightningd/opening_control.c
  8. 8
      lightningd/pay.c
  9. 13
      lightningd/payalgo.c
  10. 24
      lightningd/peer_control.c
  11. 9
      wallet/test/run-wallet.c
  12. 8
      wallet/walletrpc.c

7
common/json.c

@ -419,6 +419,13 @@ void json_add_hex(struct json_result *result, const char *fieldname,
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, ...)
{
va_list ap;

4
common/json.h

@ -110,6 +110,10 @@ void json_add_bool(struct json_result *result, const char *fieldname,
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
void json_add_hex(struct json_result *result, const char *fieldname,
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, ...);
const char *json_result_string(const struct json_result *result);

5
lightningd/gossip_control.c

@ -212,9 +212,8 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
json_add_u64(response, "last_timestamp",
nodes[i]->last_timestamp);
json_add_hex(response, "global_features",
nodes[i]->global_features,
tal_len(nodes[i]->global_features));
json_add_hex_talarr(response, "global_features",
nodes[i]->global_features);
json_array_start(response, "addresses");
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
json_add_address(response, NULL, &nodes[i]->addresses[j]);

2
lightningd/invoice.c

@ -638,7 +638,7 @@ static void json_add_fallback(struct json_result *response,
(const u8 *)&wsh, sizeof(wsh)))
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);
}

2
lightningd/jsonrpc.c

@ -151,7 +151,7 @@ static void json_getinfo(struct command *cmd,
json_object_start(response, NULL);
json_add_pubkey(response, "id", &cmd->ld->id);
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) {
/* These are the addresses we're announcing */
json_array_start(response, "address");

2
lightningd/log.c

@ -615,7 +615,7 @@ static void log_to_json(unsigned int skipped,
json_add_string(info->response, "source", prefix);
json_add_string(info->response, "log", log);
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);
}

2
lightningd/opening_control.c

@ -439,7 +439,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
response = new_json_result(fc->cmd);
json_object_start(response, NULL);
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);
derive_channel_id(&cid, &channel->funding_txid, funding_outnum);
json_add_string(response, "channel_id",

8
lightningd/pay.c

@ -852,8 +852,7 @@ static void json_waitsendpay_on_resolve(const struct sendpay_result *r,
case PAY_UNPARSEABLE_ONION:
data = new_json_result(cmd);
json_object_start(data, NULL);
json_add_hex(data, "onionreply",
r->onionreply, tal_len(r->onionreply));
json_add_hex_talarr(data, "onionreply", r->onionreply);
json_object_end(data);
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",
&fail->erring_channel);
if (fail->channel_update)
json_add_hex(data, "channel_update",
fail->channel_update,
tal_len(fail->channel_update));
json_add_hex_talarr(data, "channel_update",
fail->channel_update);
json_object_end(data);
assert(r->details != NULL);

13
lightningd/payalgo.c

@ -56,8 +56,7 @@ json_add_failure(struct json_result *r, char const *n,
switch (f->type) {
case FAIL_UNPARSEABLE_ONION:
json_add_string(r, "type", "FAIL_UNPARSEABLE_ONION");
json_add_hex(r, "onionreply", f->onionreply,
tal_len(f->onionreply));
json_add_hex_talarr(r, "onionreply", f->onionreply);
break;
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",
&rf->erring_channel);
if (rf->channel_update)
json_add_hex(r, "channel_update",
rf->channel_update,
tal_len(rf->channel_update));
json_add_hex_talarr(r, "channel_update",
rf->channel_update);
break;
}
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",
&fail->erring_channel);
if (fail->channel_update)
json_add_hex(data, "channel_update",
fail->channel_update,
tal_len(fail->channel_update));
json_add_hex_talarr(data, "channel_update",
fail->channel_update);
json_add_failures(data, "failures", &pay->pay_failures);
json_object_end(data);

24
lightningd/peer_control.c

@ -248,7 +248,7 @@ resolve_one_close_command(struct close_command *cc, bool cooperative)
bitcoin_txid(cc->channel->last_tx, &txid);
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);
if (cooperative)
json_add_string(result, "type", "mutual");
@ -761,13 +761,11 @@ static void connectd_getpeers_complete(struct subd *connectd, const u8 *msg,
struct wireaddr_internal,
&p->addr));
json_array_end(response);
json_add_hex(response, "global_features",
p->global_features,
tal_len(p->global_features));
json_add_hex_talarr(response, "global_features",
p->global_features);
json_add_hex(response, "local_features",
p->local_features,
tal_len(p->local_features));
json_add_hex_talarr(response, "local_features",
p->local_features);
}
json_array_start(response, "channels");
@ -894,13 +892,11 @@ static void connectd_getpeers_complete(struct subd *connectd, const u8 *msg,
/* Fake state. */
json_add_string(response, "state", "GOSSIPING");
json_add_pubkey(response, "id", ids+i);
json_add_hex(response, "global_features",
pf[i]->global_features,
tal_len(pf[i]->global_features));
json_add_hex_talarr(response, "global_features",
pf[i]->global_features);
json_add_hex(response, "local_features",
pf[i]->local_features,
tal_len(pf[i]->local_features));
json_add_hex_talarr(response, "local_features",
pf[i]->local_features);
json_array_start(response, "netaddr");
if (addrs[i].itype != ADDR_INTERNAL_WIREADDR
|| 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);
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);
command_success(cmd, response);
}

9
wallet/test/run-wallet.c

@ -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,
bool value UNNEEDED)
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
/* Generated stub for json_add_hex */
void json_add_hex(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED,
const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_add_hex called!\n"); abort(); }
/* Generated stub for json_add_hex_talarr */
void json_add_hex_talarr(struct json_result *result UNNEEDED,
const char *fieldname UNNEEDED,
const tal_t *data UNNEEDED)
{ fprintf(stderr, "json_add_hex_talarr called!\n"); abort(); }
/* Generated stub for json_add_log */
void json_add_log(struct json_result *result UNNEEDED,
const struct log_book *lr UNNEEDED, enum log_level minlevel UNNEEDED)

8
wallet/walletrpc.c

@ -334,11 +334,11 @@ static void json_listaddrs(struct command *cmd,
json_add_u64(response, "keyidx", keyidx);
json_add_pubkey(response, "pubkey", &pubkey);
json_add_string(response, "p2sh", out_p2sh);
json_add_hex(response, "p2sh_redeemscript",
redeemscript_p2sh, tal_count(redeemscript_p2sh));
json_add_hex_talarr(response, "p2sh_redeemscript",
redeemscript_p2sh);
json_add_string(response, "bech32", out_p2wpkh);
json_add_hex(response, "bech32_redeemscript",
redeemscript_p2wpkh, tal_count(redeemscript_p2wpkh));
json_add_hex_talarr(response, "bech32_redeemscript",
redeemscript_p2wpkh);
json_object_end(response);
}
json_array_end(response);

Loading…
Cancel
Save