mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-17 00:07:53 +00:00
blockchain: add BlockchainReadRequest::BlockExtendedHeaderByHash
This commit is contained in:
parent
1b94435952
commit
51fd017c5b
2 changed files with 26 additions and 1 deletions
|
@ -23,7 +23,8 @@ use cuprate_types::{
|
|||
use crate::{
|
||||
ops::{
|
||||
block::{
|
||||
block_exists, get_block_extended_header_from_height, get_block_height, get_block_info,
|
||||
block_exists, get_block_extended_header, get_block_extended_header_from_height,
|
||||
get_block_height, get_block_info,
|
||||
},
|
||||
blockchain::{cumulative_generated_coins, top_block_height},
|
||||
key_image::key_image_exists,
|
||||
|
@ -86,6 +87,7 @@ fn map_request(
|
|||
|
||||
match request {
|
||||
R::BlockExtendedHeader(block) => block_extended_header(env, block),
|
||||
R::BlockExtendedHeaderByHash(block) => block_extended_header_by_hash(env, block),
|
||||
R::BlockHash(block, chain) => block_hash(env, block, chain),
|
||||
R::FindBlock(_) => todo!("Add alt blocks to DB"),
|
||||
R::FilterUnknownHashes(hashes) => filter_unknown_hashes(env, hashes),
|
||||
|
@ -188,6 +190,19 @@ fn block_extended_header(env: &ConcreteEnv, block_height: BlockHeight) -> Respon
|
|||
))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::BlockExtendedHeaderByHash`].
|
||||
#[inline]
|
||||
fn block_extended_header_by_hash(env: &ConcreteEnv, block_hash: BlockHash) -> ResponseResult {
|
||||
// Single-threaded, no `ThreadLocal` required.
|
||||
let env_inner = env.env_inner();
|
||||
let tx_ro = env_inner.tx_ro()?;
|
||||
let tables = env_inner.open_tables(&tx_ro)?;
|
||||
|
||||
Ok(BlockchainResponse::BlockExtendedHeaderByHash(
|
||||
get_block_extended_header(&block_hash, &tables)?,
|
||||
))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::BlockHash`].
|
||||
#[inline]
|
||||
fn block_hash(env: &ConcreteEnv, block_height: BlockHeight, chain: Chain) -> ResponseResult {
|
||||
|
|
|
@ -27,6 +27,11 @@ pub enum BlockchainReadRequest {
|
|||
/// The input is the block's height.
|
||||
BlockExtendedHeader(usize),
|
||||
|
||||
/// Request a block's extended header.
|
||||
///
|
||||
/// The input is the block's hash.
|
||||
BlockExtendedHeaderByHash([u8; 32]),
|
||||
|
||||
/// Request a block's hash.
|
||||
///
|
||||
/// The input is the block's height and the chain it is on.
|
||||
|
@ -129,6 +134,11 @@ pub enum BlockchainResponse {
|
|||
/// Inner value is the extended headed of the requested block.
|
||||
BlockExtendedHeader(ExtendedBlockHeader),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::BlockExtendedHeaderByHash`].
|
||||
///
|
||||
/// Inner value is the extended headed of the requested block.
|
||||
BlockExtendedHeaderByHash(ExtendedBlockHeader),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::BlockHash`].
|
||||
///
|
||||
/// Inner value is the hash of the requested block.
|
||||
|
|
Loading…
Reference in a new issue