mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
lightningd/runes: update last_used timestamp when a rune successfully used
This commit is contained in:
parent
eacf0b502c
commit
db55deae2a
3 changed files with 32 additions and 1 deletions
|
@ -786,6 +786,12 @@ static const char *check_condition(const tal_t *ctx,
|
|||
ptok->end - ptok->start);
|
||||
}
|
||||
|
||||
static void update_rune_usage_time(struct runes *runes,
|
||||
struct rune *rune)
|
||||
{
|
||||
wallet_rune_update_last_used(runes->ld->wallet, rune, time_now());
|
||||
}
|
||||
|
||||
static struct command_result *json_checkrune(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
|
@ -835,6 +841,7 @@ static struct command_result *json_checkrune(struct command *cmd,
|
|||
/* If it succeeded, *now* we increment any associated usage counter. */
|
||||
if (cinfo.usage)
|
||||
cinfo.usage->counter++;
|
||||
update_rune_usage_time(cmd->ld->runes, ras->rune);
|
||||
|
||||
js = json_stream_success(cmd);
|
||||
json_add_bool(js, "valid", true);
|
||||
|
|
|
@ -5753,6 +5753,20 @@ void wallet_rune_insert(struct wallet *wallet, const struct rune *rune)
|
|||
db_rune_insert(wallet->db, rune);
|
||||
}
|
||||
|
||||
void wallet_rune_update_last_used(struct wallet *wallet, const struct rune *rune, struct timeabs last_used)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
struct timerel t;
|
||||
|
||||
t.ts = last_used.ts;
|
||||
stmt = db_prepare_v2(wallet->db,
|
||||
SQL("UPDATE runes SET last_used_nsec = ? WHERE id = ?;"));
|
||||
db_bind_u64(stmt, time_to_nsec(t));
|
||||
db_bind_u64(stmt, rune_unique_id(rune));
|
||||
db_exec_prepared_v2(stmt);
|
||||
tal_free(stmt);
|
||||
}
|
||||
|
||||
static void db_insert_blacklist(struct db *db,
|
||||
const struct rune_blacklist *entry)
|
||||
{
|
||||
|
@ -5852,7 +5866,8 @@ void migrate_datastore_commando_runes(struct lightningd *ld, struct db *db)
|
|||
void migrate_runes_idfix(struct lightningd *ld, struct db *db)
|
||||
{
|
||||
/* ID fields were wrong. Pull them all out and put them back */
|
||||
const char **runes = db_get_runes(tmpctx, db, NULL);
|
||||
struct timeabs *last_used;
|
||||
const char **runes = db_get_runes(tmpctx, db, &last_used);
|
||||
struct db_stmt *stmt;
|
||||
|
||||
stmt = db_prepare_v2(db, SQL("DELETE FROM runes;"));
|
||||
|
|
|
@ -1607,6 +1607,15 @@ const char **wallet_get_runes(const tal_t *ctx, struct wallet *wallet, struct ti
|
|||
*/
|
||||
void wallet_rune_insert(struct wallet *wallet, const struct rune *rune);
|
||||
|
||||
/**
|
||||
* wallet_rune_update_last_used -- Update the timestamp on an existing rune
|
||||
*
|
||||
* @wallet: the wallet to save into
|
||||
* @rune: the instance to store
|
||||
* @last_used: now
|
||||
*/
|
||||
void wallet_rune_update_last_used(struct wallet *wallet, const struct rune *rune, struct timeabs last_used);
|
||||
|
||||
/* Load the runes blacklist */
|
||||
struct rune_blacklist {
|
||||
u64 start, end;
|
||||
|
|
Loading…
Add table
Reference in a new issue