mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
db: add runes tables and accessors.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -956,6 +956,8 @@ static struct migration dbmigrations[] = {
|
||||
{NULL, migrate_fill_in_channel_type},
|
||||
{SQL("ALTER TABLE peers ADD feature_bits BLOB DEFAULT NULL;"), NULL},
|
||||
{NULL, migrate_normalize_invstr},
|
||||
{SQL("CREATE TABLE runes (id BIGSERIAL, rune TEXT, PRIMARY KEY (id));"), NULL},
|
||||
{SQL("CREATE TABLE runes_blacklist (start_index BIGINT, end_index BIGINT);"), NULL},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -5465,3 +5465,55 @@ struct wallet_htlc_iter *wallet_htlcs_next(struct wallet *w,
|
||||
*hstate = db_col_int(iter->stmt, "h.hstate");
|
||||
return iter;
|
||||
}
|
||||
|
||||
struct rune_blacklist *wallet_get_runes_blacklist(const tal_t *ctx, struct wallet *wallet)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
struct rune_blacklist *blist = tal_arr(ctx, struct rune_blacklist, 0);
|
||||
|
||||
stmt = db_prepare_v2(wallet->db, SQL("SELECT start_index, end_index FROM runes_blacklist"));
|
||||
db_query_prepared(stmt);
|
||||
|
||||
while (db_step(stmt)) {
|
||||
struct rune_blacklist b;
|
||||
b.start = db_col_u64(stmt, "start_index");
|
||||
b.end = db_col_u64(stmt, "end_index");
|
||||
tal_arr_expand(&blist, b);
|
||||
}
|
||||
tal_free(stmt);
|
||||
return blist;
|
||||
}
|
||||
|
||||
const char *wallet_get_rune(const tal_t *ctx, struct wallet *wallet, u64 unique_id)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
const char *runestr;
|
||||
|
||||
stmt = db_prepare_v2(wallet->db, SQL("SELECT rune FROM runes WHERE id = ?"));
|
||||
db_bind_u64(stmt, unique_id);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (db_step(stmt))
|
||||
runestr = db_col_strdup(ctx, stmt, "rune");
|
||||
else
|
||||
runestr = NULL;
|
||||
tal_free(stmt);
|
||||
return runestr;
|
||||
}
|
||||
|
||||
const char **wallet_get_runes(const tal_t *ctx, struct wallet *wallet)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
const char **strs = tal_arr(ctx, const char *, 0);
|
||||
|
||||
stmt = db_prepare_v2(wallet->db, SQL("SELECT rune FROM runes"));
|
||||
db_query_prepared(stmt);
|
||||
|
||||
while (db_step(stmt)) {
|
||||
const char *str = db_col_strdup(strs, stmt, "rune");
|
||||
tal_arr_expand(&strs, str);
|
||||
}
|
||||
tal_free(stmt);
|
||||
return strs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1524,4 +1524,34 @@ struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
|
||||
u32 nlocktime,
|
||||
u32 nsequence,
|
||||
struct wally_psbt *base);
|
||||
|
||||
/**
|
||||
* Get a particular runestring from the db
|
||||
* @ctx: tal ctx for return to be tallocated from
|
||||
* @wallet: the wallet
|
||||
* @unique_id: the id of the rune.
|
||||
*
|
||||
* Returns NULL if it's not found.
|
||||
*/
|
||||
const char *wallet_get_rune(const tal_t *ctx, struct wallet *wallet, u64 unique_id);
|
||||
|
||||
/**
|
||||
* Get every runestring from the db
|
||||
* @ctx: tal ctx for return to be tallocated from
|
||||
* @wallet: the wallet
|
||||
*/
|
||||
const char **wallet_get_runes(const tal_t *ctx, struct wallet *wallet);
|
||||
|
||||
/* Load the runes blacklist */
|
||||
struct rune_blacklist {
|
||||
u64 start, end;
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the blacklist from the db.
|
||||
* @ctx: tal ctx for return to be tallocated from
|
||||
* @wallet: the wallet
|
||||
*/
|
||||
struct rune_blacklist *wallet_get_runes_blacklist(const tal_t *ctx, struct wallet *wallet);
|
||||
|
||||
#endif /* LIGHTNING_WALLET_WALLET_H */
|
||||
|
||||
Reference in New Issue
Block a user