mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
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:
parent
bcec6bb6cc
commit
a449a91ae2
2 changed files with 54 additions and 38 deletions
|
@ -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,
|
||||
|
@ -2151,6 +2149,18 @@ static void listforwardings_add_forwardings(struct json_stream *response, struct
|
|||
#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);
|
||||
|
||||
tal_free(forwardings);
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue