mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-03 13:14:22 +01:00
db: add column for first block of channel.
This determines how far we go back. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
f5c319a37e
commit
af0ed9e5cf
@@ -145,6 +145,11 @@ char *dbmigrations[] = {
|
||||
" VALUES('next_pay_index', "
|
||||
" COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1"
|
||||
" );",
|
||||
/* Create first_block field; initialize from channel id if any.
|
||||
* This fails for channels still awaiting lockin, but that only applies to
|
||||
* pre-release software, so it's forgivable. */
|
||||
"ALTER TABLE channels ADD first_blocknum INTEGER;",
|
||||
"UPDATE channels SET first_blocknum=CAST(short_channel_id AS INTEGER) WHERE short_channel_id IS NOT NULL;",
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
@@ -597,6 +597,25 @@ bool wallet_channels_load_active(struct wallet *w, struct list_head *peers)
|
||||
return ok;
|
||||
}
|
||||
|
||||
u32 wallet_channels_first_blocknum(struct wallet *w)
|
||||
{
|
||||
int err;
|
||||
u32 first_blocknum;
|
||||
sqlite3_stmt *stmt =
|
||||
db_query(__func__, w->db,
|
||||
"SELECT MIN(first_blocknum) FROM channels WHERE state >= %d AND state != %d;",
|
||||
OPENINGD, CLOSINGD_COMPLETE);
|
||||
|
||||
err = sqlite3_step(stmt);
|
||||
if (err == SQLITE_ROW && sqlite3_column_type(stmt, 1) != SQLITE_NULL)
|
||||
first_blocknum = sqlite3_column_int(stmt, 1);
|
||||
else
|
||||
first_blocknum = UINT32_MAX;
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return first_blocknum;
|
||||
}
|
||||
|
||||
void wallet_channel_config_save(struct wallet *w, struct channel_config *cc)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
@@ -242,6 +242,15 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
|
||||
*/
|
||||
bool wallet_channels_load_active(struct wallet *w, struct list_head *peers);
|
||||
|
||||
/**
|
||||
* wallet_channels_first_blocknum - get first block we're interested in.
|
||||
*
|
||||
* @w: wallet to load from.
|
||||
*
|
||||
* Returns UINT32_MAX if nothing interesting.
|
||||
*/
|
||||
u32 wallet_channels_first_blocknum(struct wallet *w);
|
||||
|
||||
/**
|
||||
* wallet_extract_owned_outputs - given a tx, extract all of our outputs
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user