Merge pull request #644 from zcash/fix-fsblockdb-cached-height
zcash_client_sqlite: Fix `FsBlockDb::get_max_cached_height`
This commit is contained in:
commit
d1f0c12c02
|
@ -12,7 +12,7 @@ use crate::{error::SqliteClientError, BlockDb};
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use {
|
use {
|
||||||
crate::{BlockHash, FsBlockDb},
|
crate::{BlockHash, FsBlockDb},
|
||||||
rusqlite::{Connection, OptionalExtension, NO_PARAMS},
|
rusqlite::{Connection, NO_PARAMS},
|
||||||
std::fs::File,
|
std::fs::File,
|
||||||
std::io::BufReader,
|
std::io::BufReader,
|
||||||
std::path::{Path, PathBuf},
|
std::path::{Path, PathBuf},
|
||||||
|
@ -149,11 +149,12 @@ pub(crate) fn blockmetadb_get_max_cached_height(
|
||||||
"SELECT MAX(height) FROM compactblocks_meta",
|
"SELECT MAX(height) FROM compactblocks_meta",
|
||||||
NO_PARAMS,
|
NO_PARAMS,
|
||||||
|row| {
|
|row| {
|
||||||
let h: u32 = row.get(0)?;
|
// `SELECT MAX(_)` will always return a row, but it will return `null` if the
|
||||||
Ok(BlockHeight::from(h))
|
// table is empty, which has no integer type. We handle the optionality here.
|
||||||
|
let h: Option<u32> = row.get(0)?;
|
||||||
|
Ok(h.map(BlockHeight::from))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.optional()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implements a traversal of `limit` blocks of the filesystem-backed
|
/// Implements a traversal of `limit` blocks of the filesystem-backed
|
||||||
|
|
Loading…
Reference in New Issue