mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
wallet: Return both min and max block heights
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
6f9c6d4258
commit
5c9c682cf7
@ -306,7 +306,7 @@ void notify_new_block(struct lightningd *ld,
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct lightningd *ld;
|
struct lightningd *ld;
|
||||||
u32 blockheight;
|
u32 blockheight, first_block;
|
||||||
|
|
||||||
setup_locale();
|
setup_locale();
|
||||||
daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit);
|
daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit);
|
||||||
@ -388,7 +388,7 @@ int main(int argc, char *argv[])
|
|||||||
/* Get the blockheight we are currently at, UINT32_MAX is used to signal
|
/* Get the blockheight we are currently at, UINT32_MAX is used to signal
|
||||||
* an unitialized wallet and that we should start off of bitcoind's
|
* an unitialized wallet and that we should start off of bitcoind's
|
||||||
* current height */
|
* current height */
|
||||||
blockheight = wallet_blocks_height(ld->wallet, UINT32_MAX);
|
wallet_blocks_heights(ld->wallet, UINT32_MAX, &first_block, &blockheight);
|
||||||
|
|
||||||
/* If we were asked to rescan from an absolute height (--rescan < 0)
|
/* If we were asked to rescan from an absolute height (--rescan < 0)
|
||||||
* then just go there. Otherwise take compute the diff to our current
|
* then just go there. Otherwise take compute the diff to our current
|
||||||
|
@ -121,9 +121,9 @@ struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED)
|
|||||||
/* Generated stub for version */
|
/* Generated stub for version */
|
||||||
const char *version(void)
|
const char *version(void)
|
||||||
{ fprintf(stderr, "version called!\n"); abort(); }
|
{ fprintf(stderr, "version called!\n"); abort(); }
|
||||||
/* Generated stub for wallet_blocks_height */
|
/* Generated stub for wallet_blocks_heights */
|
||||||
u32 wallet_blocks_height(struct wallet *w UNNEEDED, u32 def UNNEEDED)
|
void wallet_blocks_heights(struct wallet *w UNNEEDED, u32 def UNNEEDED, u32 *min UNNEEDED, u32 *max UNNEEDED)
|
||||||
{ fprintf(stderr, "wallet_blocks_height called!\n"); abort(); }
|
{ fprintf(stderr, "wallet_blocks_heights called!\n"); abort(); }
|
||||||
/* Generated stub for wallet_channels_load_active */
|
/* Generated stub for wallet_channels_load_active */
|
||||||
bool wallet_channels_load_active(const tal_t *ctx UNNEEDED, struct wallet *w UNNEEDED)
|
bool wallet_channels_load_active(const tal_t *ctx UNNEEDED, struct wallet *w UNNEEDED)
|
||||||
{ fprintf(stderr, "wallet_channels_load_active called!\n"); abort(); }
|
{ fprintf(stderr, "wallet_channels_load_active called!\n"); abort(); }
|
||||||
|
@ -769,20 +769,20 @@ void wallet_channel_stats_load(struct wallet *w,
|
|||||||
db_stmt_done(stmt);
|
db_stmt_done(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 wallet_blocks_height(struct wallet *w, u32 def)
|
void wallet_blocks_heights(struct wallet *w, u32 def, u32 *min, u32 *max)
|
||||||
{
|
{
|
||||||
u32 blockheight;
|
assert(min != NULL && max != NULL);
|
||||||
sqlite3_stmt *stmt = db_prepare(w->db, "SELECT MAX(height) FROM blocks;");
|
sqlite3_stmt *stmt = db_prepare(w->db, "SELECT MIN(height), MAX(height) FROM blocks;");
|
||||||
|
|
||||||
/* If we ever processed a block we'll get the latest block in the chain */
|
/* If we ever processed a block we'll get the latest block in the chain */
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_type(stmt, 0) != SQLITE_NULL) {
|
if (sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_type(stmt, 0) != SQLITE_NULL) {
|
||||||
blockheight = sqlite3_column_int(stmt, 0);
|
*min = sqlite3_column_int(stmt, 0);
|
||||||
db_stmt_done(stmt);
|
*max = sqlite3_column_int(stmt, 1);
|
||||||
return blockheight;
|
|
||||||
} else {
|
} else {
|
||||||
db_stmt_done(stmt);
|
*min = def;
|
||||||
return def;
|
*max = def;
|
||||||
}
|
}
|
||||||
|
db_stmt_done(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wallet_channel_config_insert(struct wallet *w,
|
static void wallet_channel_config_insert(struct wallet *w,
|
||||||
|
@ -316,13 +316,15 @@ void wallet_channel_stats_load(struct wallet *w, u64 cdbid, struct channel_stats
|
|||||||
/**
|
/**
|
||||||
* Retrieve the blockheight of the last block processed by lightningd.
|
* Retrieve the blockheight of the last block processed by lightningd.
|
||||||
*
|
*
|
||||||
* Will return either the maximal blockheight or the default value if the wallet
|
* Will set min/max either the minimal/maximal blockheight or the default value
|
||||||
* was never used before.
|
* if the wallet was never used before.
|
||||||
*
|
*
|
||||||
* @w: wallet to load from.
|
* @w: wallet to load from.
|
||||||
* @def: the default value to return if we've never used the wallet before
|
* @def: the default value to return if we've never used the wallet before
|
||||||
|
* @min(out): height of the first block we track
|
||||||
|
* @max(out): height of the last block we added
|
||||||
*/
|
*/
|
||||||
u32 wallet_blocks_height(struct wallet *w, u32 def);
|
void wallet_blocks_heights(struct wallet *w, u32 def, u32 *min, u32 *max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wallet_extract_owned_outputs - given a tx, extract all of our outputs
|
* wallet_extract_owned_outputs - given a tx, extract all of our outputs
|
||||||
|
Loading…
Reference in New Issue
Block a user