mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
plugins/pay: sort output payments in listpays
Changelog-Changed: `listpays` output is now ordered by the `created_at` timestamp.
This commit is contained in:
parent
a88a6e604c
commit
23fada090c
1 changed files with 26 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <bitcoin/chainparams.h>
|
#include <bitcoin/chainparams.h>
|
||||||
#include <ccan/array_size/array_size.h>
|
#include <ccan/array_size/array_size.h>
|
||||||
|
#include <ccan/asort/asort.h>
|
||||||
#include <ccan/cast/cast.h>
|
#include <ccan/cast/cast.h>
|
||||||
#include <ccan/crypto/siphash24/siphash24.h>
|
#include <ccan/crypto/siphash24/siphash24.h>
|
||||||
#include <ccan/htable/htable_type.h>
|
#include <ccan/htable/htable_type.h>
|
||||||
|
@ -1701,6 +1702,17 @@ static bool pay_mpp_eq(const struct pay_mpp *pm, const struct sha256 *payment_ha
|
||||||
return memcmp(pm->payment_hash, payment_hash, sizeof(struct sha256)) == 0;
|
return memcmp(pm->payment_hash, payment_hash, sizeof(struct sha256)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cmp_pay_mpp(const struct pay_mpp *a,
|
||||||
|
const struct pay_mpp *b,
|
||||||
|
void *unused UNUSED)
|
||||||
|
{
|
||||||
|
if (a->timestamp < b->timestamp)
|
||||||
|
return -1;
|
||||||
|
if (a->timestamp == b->timestamp)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
HTABLE_DEFINE_TYPE(struct pay_mpp, pay_mpp_key, pay_mpp_hash, pay_mpp_eq,
|
HTABLE_DEFINE_TYPE(struct pay_mpp, pay_mpp_key, pay_mpp_hash, pay_mpp_eq,
|
||||||
pay_map);
|
pay_map);
|
||||||
|
|
||||||
|
@ -1796,6 +1808,7 @@ static struct command_result *listsendpays_done(struct command *cmd,
|
||||||
struct pay_map pay_map;
|
struct pay_map pay_map;
|
||||||
struct pay_map_iter it;
|
struct pay_map_iter it;
|
||||||
struct pay_mpp *pm;
|
struct pay_mpp *pm;
|
||||||
|
struct pay_mpp *pays;
|
||||||
|
|
||||||
pay_map_init(&pay_map);
|
pay_map_init(&pay_map);
|
||||||
|
|
||||||
|
@ -1864,17 +1877,26 @@ static struct command_result *listsendpays_done(struct command *cmd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now we've collapsed them, provide summary. */
|
|
||||||
ret = jsonrpc_stream_success(cmd);
|
|
||||||
json_array_start(ret, "pays");
|
|
||||||
|
|
||||||
|
pays = tal_arr(NULL, struct pay_mpp, pay_map_count(&pay_map));
|
||||||
|
i = 0;
|
||||||
for (pm = pay_map_first(&pay_map, &it);
|
for (pm = pay_map_first(&pay_map, &it);
|
||||||
pm;
|
pm;
|
||||||
pm = pay_map_next(&pay_map, &it)) {
|
pm = pay_map_next(&pay_map, &it)) {
|
||||||
add_new_entry(ret, buf, pm);
|
pays[i++] = *pm;
|
||||||
}
|
}
|
||||||
pay_map_clear(&pay_map);
|
pay_map_clear(&pay_map);
|
||||||
|
|
||||||
|
asort(pays, tal_count(pays), cmp_pay_mpp, NULL);
|
||||||
|
|
||||||
|
/* Now we've collapsed and sorted them, provide summary. */
|
||||||
|
ret = jsonrpc_stream_success(cmd);
|
||||||
|
json_array_start(ret, "pays");
|
||||||
|
|
||||||
|
for (i = 0; i < tal_count(pays); i++)
|
||||||
|
add_new_entry(ret, buf, &pays[i]);
|
||||||
|
tal_free(pays);
|
||||||
|
|
||||||
json_array_end(ret);
|
json_array_end(ret);
|
||||||
return command_finished(cmd, ret);
|
return command_finished(cmd, ret);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue