mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
sendpays: add to wait subsystem.
Adding an index means: 1. Add the new subsystem, and new updated_index field to the db, and create xxx_index_deleted/created/updated APIs. 2. Hook up these functions to the points they need to be called. 3. Add index, start and limit fields to the list command. 4. Add created_index and updated_index into the list command. This does #1. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
34692ec3c8
commit
ccb8d4b687
@ -1690,6 +1690,52 @@ static const struct json_command waitsendpay_command = {
|
||||
};
|
||||
AUTODATA(json_command, &waitsendpay_command);
|
||||
|
||||
static u64 sendpay_index_inc(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status,
|
||||
enum wait_index idx)
|
||||
{
|
||||
return wait_index_increment(ld, WAIT_SUBSYSTEM_SENDPAY, idx,
|
||||
"status", payment_status_to_string(status),
|
||||
"=partid", tal_fmt(tmpctx, "%"PRIu64, partid),
|
||||
"=groupid", tal_fmt(tmpctx, "%"PRIu64, groupid),
|
||||
"payment_hash",
|
||||
type_to_string(tmpctx, struct sha256, payment_hash),
|
||||
NULL);
|
||||
}
|
||||
|
||||
void sendpay_index_deleted(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status)
|
||||
{
|
||||
sendpay_index_inc(ld, payment_hash, partid, groupid, status, WAIT_INDEX_DELETED);
|
||||
}
|
||||
|
||||
/* Fortuntely, dbids start at 1, not 0! */
|
||||
u64 sendpay_index_created(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status)
|
||||
{
|
||||
return sendpay_index_inc(ld, payment_hash, partid, groupid, status,
|
||||
WAIT_INDEX_CREATED);
|
||||
}
|
||||
|
||||
u64 sendpay_index_update_status(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status)
|
||||
{
|
||||
return sendpay_index_inc(ld, payment_hash, partid, groupid, status,
|
||||
WAIT_INDEX_UPDATED);
|
||||
}
|
||||
|
||||
static struct command_result *param_payment_status(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define LIGHTNING_LIGHTNINGD_PAY_H
|
||||
#include "config.h"
|
||||
#include <common/errcode.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
struct htlc_out;
|
||||
struct lightningd;
|
||||
@ -35,4 +36,20 @@ void json_sendpay_fail_fields(struct json_stream *js,
|
||||
const struct onionreply *onionreply,
|
||||
const struct routing_failure *fail);
|
||||
|
||||
/* wait() hooks in here */
|
||||
void sendpay_index_deleted(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status);
|
||||
u64 sendpay_index_created(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status);
|
||||
u64 sendpay_index_update_status(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
u64 partid,
|
||||
u64 groupid,
|
||||
enum payment_status status);
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PAY_H */
|
||||
|
@ -20,6 +20,7 @@ struct waiter {
|
||||
|
||||
|
||||
static const char *subsystem_names[] = {
|
||||
"sendpays",
|
||||
"invoices",
|
||||
};
|
||||
|
||||
@ -44,6 +45,8 @@ const char *wait_index_name(enum wait_index index)
|
||||
const char *wait_subsystem_name(enum wait_subsystem subsystem)
|
||||
{
|
||||
switch (subsystem) {
|
||||
case WAIT_SUBSYSTEM_SENDPAY:
|
||||
return subsystem_names[subsystem];
|
||||
case WAIT_SUBSYSTEM_INVOICE:
|
||||
return subsystem_names[subsystem];
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ struct lightningd;
|
||||
|
||||
/* This WAIT_SUBSYSTEM_X corresponds to listX */
|
||||
enum wait_subsystem {
|
||||
WAIT_SUBSYSTEM_INVOICE
|
||||
WAIT_SUBSYSTEM_SENDPAY,
|
||||
WAIT_SUBSYSTEM_INVOICE,
|
||||
};
|
||||
#define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_INVOICE+1)
|
||||
|
||||
|
@ -994,6 +994,8 @@ static struct migration dbmigrations[] = {
|
||||
" commitment_fee BIGINT,"
|
||||
" commitment_weight INTEGER)"), NULL},
|
||||
{SQL("CREATE INDEX local_anchors_idx ON local_anchors (channel_id)"), NULL},
|
||||
{SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL},
|
||||
{SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL},
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user