Skip to content

Commit

Permalink
runes: Get next unique id from runes table
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahanaFarooqui authored and rustyrussell committed Oct 2, 2023
1 parent 9bcabbc commit 90824a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -5662,6 +5662,21 @@ struct wallet_htlc_iter *wallet_htlcs_next(struct wallet *w,
return iter;
}

u64 wallet_get_rune_next_unique_id(const tal_t *ctx, struct wallet *wallet)
{
struct db_stmt *stmt;
u64 next_unique_id;

stmt = db_prepare_v2(wallet->db, SQL("SELECT (COALESCE(MAX(id), -1) + 1) FROM runes"));
db_query_prepared(stmt);
db_step(stmt);

next_unique_id = db_col_u64(stmt, "(COALESCE(MAX(id), -1) + 1)");

tal_free(stmt);
return next_unique_id;
}

struct rune_blacklist *wallet_get_runes_blacklist(const tal_t *ctx, struct wallet *wallet)
{
struct db_stmt *stmt;
Expand Down
7 changes: 7 additions & 0 deletions wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,13 @@ struct rune_blacklist {
u64 start, end;
};

/**
* Load the next unique id for rune from the db.
* @ctx: tal ctx for return to be tallocated from
* @wallet: the wallet
*/
u64 wallet_get_rune_next_unique_id(const tal_t *ctx, struct wallet *wallet);

/**
* Load the blacklist from the db.
* @ctx: tal ctx for return to be tallocated from
Expand Down

0 comments on commit 90824a5

Please sign in to comment.