zcash_client_sqlite: Add `FsBlockDb::find_block`
This commit is contained in:
parent
5d62b68d70
commit
e37f458a70
|
@ -6,19 +6,16 @@ and this library adheres to Rust's notion of
|
|||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- `zcash_client_sqlite::FsBlockDb::rewind_to_height` rewinds the BlockMeta Db
|
||||
to the specified height following the same logic as homonymous functions on
|
||||
`WalletDb`. This function does not delete the files referenced by the rows
|
||||
that might be present and are deleted by this function call.
|
||||
- `zcash_client_sqlite::chain::blockmetadb_rewind_to_height` implementation
|
||||
of the function above.
|
||||
- `zcash_client_sqlite::FsBlockDb::find_block`
|
||||
|
||||
### Changed
|
||||
- MSRV is now 1.60.0.
|
||||
|
||||
|
||||
## [0.4.2] - 2022-12-13
|
||||
### Fixed
|
||||
- `zcash_client_sqlite::WalletDb::get_transparent_balances` no longer returns an
|
||||
|
|
|
@ -161,6 +161,32 @@ pub(crate) fn blockmetadb_get_max_cached_height(
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns the metadata for the block with the given height, if it exists in the database.
|
||||
#[cfg(feature = "unstable")]
|
||||
pub(crate) fn blockmetadb_find_block(
|
||||
conn: &Connection,
|
||||
height: BlockHeight,
|
||||
) -> Result<Option<BlockMeta>, rusqlite::Error> {
|
||||
use rusqlite::OptionalExtension;
|
||||
|
||||
conn.query_row(
|
||||
"SELECT blockhash, time, sapling_outputs_count, orchard_actions_count
|
||||
FROM compactblocks_meta
|
||||
WHERE height = ?",
|
||||
[u32::from(height)],
|
||||
|row| {
|
||||
Ok(BlockMeta {
|
||||
height,
|
||||
block_hash: BlockHash::from_slice(&row.get::<_, Vec<_>>(0)?),
|
||||
block_time: row.get(1)?,
|
||||
sapling_outputs_count: row.get(2)?,
|
||||
orchard_actions_count: row.get(3)?,
|
||||
})
|
||||
},
|
||||
)
|
||||
.optional()
|
||||
}
|
||||
|
||||
/// Implements a traversal of `limit` blocks of the filesystem-backed
|
||||
/// block cache.
|
||||
///
|
||||
|
|
|
@ -929,6 +929,13 @@ impl FsBlockDb {
|
|||
|
||||
Ok(chain::blockmetadb_insert(&self.conn, block_meta)?)
|
||||
}
|
||||
|
||||
/// Returns the metadata for the block with the given height, if it exists in the
|
||||
/// database.
|
||||
pub fn find_block(&self, height: BlockHeight) -> Result<Option<BlockMeta>, FsBlockDbError> {
|
||||
Ok(chain::blockmetadb_find_block(&self.conn, height)?)
|
||||
}
|
||||
|
||||
/// Rewinds the BlockMeta Db to the `block_height` provided.
|
||||
///
|
||||
/// This doesn't delete any files referenced by the records
|
||||
|
|
Loading…
Reference in New Issue