JSON: Warp the process of forward payment json object

Warp this process as a new function: 'void json_format_forwarding_object()'. This function will be used in 'forward_event' next, and can ensure the consistent json object structure for forward_payment between 'listforwards' API and 'forward_event' notification.
This commit is contained in:
trueptolemy 2019-07-08 19:36:47 +08:00 committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent bcec6bb6cc
commit a449a91ae2
2 changed files with 54 additions and 38 deletions

View File

@ -2104,15 +2104,13 @@ static const struct json_command dev_ignore_htlcs = {
AUTODATA(json_command, &dev_ignore_htlcs);
#endif /* DEVELOPER */
static void listforwardings_add_forwardings(struct json_stream *response, struct wallet *wallet)
/* Warp this process to ensure the consistent json object structure
* between 'listforwards' API and 'forward_event' notification. */
void json_format_forwarding_object(struct json_stream *response,
const char *fieldname,
const struct forwarding *cur)
{
const struct forwarding *forwardings;
forwardings = wallet_forwarded_payments_get(wallet, tmpctx);
json_array_start(response, "forwards");
for (size_t i=0; i<tal_count(forwardings); i++) {
const struct forwarding *cur = &forwardings[i];
json_object_start(response, NULL);
json_object_start(response, fieldname);
json_add_hex(response, "payment_hash",
cur->payment_hash,
@ -2150,6 +2148,18 @@ static void listforwardings_add_forwardings(struct json_stream *response, struct
json_add_timeabs(response, "resolved_time", *cur->resolved_time);
#endif
json_object_end(response);
}
static void listforwardings_add_forwardings(struct json_stream *response, struct wallet *wallet)
{
const struct forwarding *forwardings;
forwardings = wallet_forwarded_payments_get(wallet, tmpctx);
json_array_start(response, "forwards");
for (size_t i=0; i<tal_count(forwardings); i++) {
const struct forwarding *cur = &forwardings[i];
json_format_forwarding_object(response, NULL, cur);
}
json_array_end(response);

View File

@ -14,6 +14,8 @@ struct htlc_out;
struct htlc_out_map;
struct htlc_stub;
struct lightningd;
struct forwarding;
struct json_stream;
/* FIXME: Define serialization primitive for this? */
struct channel_info {
@ -69,4 +71,8 @@ void htlcs_reconnect(struct lightningd *ld,
void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage);
void fail_htlc(struct htlc_in *hin, enum onion_type failcode);
/* This json process will be both used in 'notify_forward_event()'
* and 'listforwardings_add_forwardings()'*/
void json_format_forwarding_object(struct json_stream *response, const char *fieldname,
const struct forwarding *cur);
#endif /* LIGHTNING_LIGHTNINGD_PEER_HTLCS_H */