pay: Add timestamp of first part to listpays

Changelog-Added: JSON-RPC: The result returned by `listpays` now includes the timestamp of the first part of the payment
This commit is contained in:
Christian Decker
2020-08-06 16:52:33 +02:00
parent 01a82d38f7
commit 723b7223b7
2 changed files with 12 additions and 1 deletions

View File

@@ -1666,6 +1666,9 @@ struct pay_mpp {
* only). Null if we have any part for which we didn't know the * only). Null if we have any part for which we didn't know the
* amount. */ * amount. */
struct amount_msat *amount; struct amount_msat *amount;
/* Timestamp of the first part */
u32 timestamp;
}; };
static const struct sha256 *pay_mpp_key(const struct pay_mpp *pm) static const struct sha256 *pay_mpp_key(const struct pay_mpp *pm)
@@ -1735,6 +1738,8 @@ static void add_new_entry(struct json_stream *ret,
json_object_start(ret, NULL); json_object_start(ret, NULL);
json_add_string(ret, "bolt11", pm->b11); json_add_string(ret, "bolt11", pm->b11);
json_add_string(ret, "status", pm->status); json_add_string(ret, "status", pm->status);
json_add_u32(ret, "created_at", pm->timestamp);
if (pm->label) if (pm->label)
json_add_tok(ret, "label", pm->label, buf); json_add_tok(ret, "label", pm->label, buf);
if (pm->preimage) if (pm->preimage)
@@ -1777,15 +1782,19 @@ static struct command_result *listsendpays_done(struct command *cmd,
ret = jsonrpc_stream_success(cmd); ret = jsonrpc_stream_success(cmd);
json_array_start(ret, "pays"); json_array_start(ret, "pays");
json_for_each_arr(i, t, arr) { json_for_each_arr(i, t, arr) {
const jsmntok_t *status, *b11tok, *hashtok; const jsmntok_t *status, *b11tok, *hashtok, *createdtok;
const char *b11 = b11str; const char *b11 = b11str;
struct sha256 payment_hash; struct sha256 payment_hash;
u32 created_at;
b11tok = json_get_member(buf, t, "bolt11"); b11tok = json_get_member(buf, t, "bolt11");
hashtok = json_get_member(buf, t, "payment_hash"); hashtok = json_get_member(buf, t, "payment_hash");
createdtok = json_get_member(buf, t, "created_at");
assert(hashtok != NULL); assert(hashtok != NULL);
assert(createdtok != NULL);
json_to_sha256(buf, hashtok, &payment_hash); json_to_sha256(buf, hashtok, &payment_hash);
json_to_u32(buf, createdtok, &created_at);
if (b11tok) if (b11tok)
b11 = json_strdup(cmd, buf, b11tok); b11 = json_strdup(cmd, buf, b11tok);
@@ -1800,6 +1809,7 @@ static struct command_result *listsendpays_done(struct command *cmd,
pm->amount = talz(pm, struct amount_msat); pm->amount = talz(pm, struct amount_msat);
pm->num_nonfailed_parts = 0; pm->num_nonfailed_parts = 0;
pm->status = NULL; pm->status = NULL;
pm->timestamp = created_at;
pay_map_add(&pay_map, pm); pay_map_add(&pay_map, pm);
} }

View File

@@ -3211,6 +3211,7 @@ def test_bolt11_null_after_pay(node_factory, bitcoind):
pays = l2.rpc.listpays()["pays"] pays = l2.rpc.listpays()["pays"]
assert(pays[0]["bolt11"] == invl1) assert(pays[0]["bolt11"] == invl1)
assert('amount_msat' in pays[0] and pays[0]['amount_msat'] == amt) assert('amount_msat' in pays[0] and pays[0]['amount_msat'] == amt)
assert('created_at' in pays[0])
def test_mpp_presplit_routehint_conflict(node_factory, bitcoind): def test_mpp_presplit_routehint_conflict(node_factory, bitcoind):