mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-11 05:15:24 +00:00
get_version
This commit is contained in:
parent
1d435cc1f8
commit
d7fef15cd6
4 changed files with 62 additions and 11 deletions
|
@ -14,7 +14,10 @@ use cuprate_constants::{
|
|||
build::RELEASE,
|
||||
rpc::{RESTRICTED_BLOCK_COUNT, RESTRICTED_BLOCK_HEADER_RANGE},
|
||||
};
|
||||
use cuprate_helper::{cast::u64_to_usize, map::split_u128_into_low_high_bits};
|
||||
use cuprate_helper::{
|
||||
cast::{u64_to_usize, usize_to_u64},
|
||||
map::split_u128_into_low_high_bits,
|
||||
};
|
||||
use cuprate_rpc_interface::RpcHandler;
|
||||
use cuprate_rpc_types::{
|
||||
base::{AccessResponseBase, ResponseBase},
|
||||
|
@ -38,7 +41,7 @@ use cuprate_rpc_types::{
|
|||
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
||||
SyncInfoResponse,
|
||||
},
|
||||
misc::{BlockHeader, GetBan, HistogramEntry, Status},
|
||||
misc::{BlockHeader, GetBan, HardforkEntry, HistogramEntry, Status},
|
||||
CORE_RPC_VERSION,
|
||||
};
|
||||
|
||||
|
@ -573,13 +576,25 @@ async fn get_version(
|
|||
mut state: CupratedRpcHandler,
|
||||
request: GetVersionRequest,
|
||||
) -> Result<GetVersionResponse, Error> {
|
||||
let current_height = helper::top_height(&mut state).await?.0;
|
||||
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
|
||||
|
||||
let hard_forks = blockchain::hard_forks(&mut state.blockchain_read)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|(height, hf)| HardforkEntry {
|
||||
height: usize_to_u64(height),
|
||||
hf_version: hf.as_u8(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(GetVersionResponse {
|
||||
base: ResponseBase::ok(),
|
||||
version: CORE_RPC_VERSION,
|
||||
release: RELEASE,
|
||||
current_height: helper::top_height(&mut state).await?.0,
|
||||
target_height: todo!(),
|
||||
hard_forks: todo!(),
|
||||
current_height,
|
||||
target_height,
|
||||
hard_forks,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Functions for [`BlockchainReadRequest`].
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
ops::Range,
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,7 @@ use cuprate_blockchain::service::BlockchainReadHandle;
|
|||
use cuprate_helper::cast::{u64_to_usize, usize_to_u64};
|
||||
use cuprate_types::{
|
||||
blockchain::{BlockchainReadRequest, BlockchainResponse},
|
||||
Chain, CoinbaseTxSum, ExtendedBlockHeader, MinerData, OutputHistogramEntry,
|
||||
Chain, CoinbaseTxSum, ExtendedBlockHeader, HardFork, MinerData, OutputHistogramEntry,
|
||||
OutputHistogramInput, OutputOnChain,
|
||||
};
|
||||
|
||||
|
@ -343,3 +343,19 @@ pub(crate) async fn coinbase_tx_sum(
|
|||
|
||||
Ok(sum)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::HardForks`]
|
||||
pub(crate) async fn hard_forks(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
) -> Result<BTreeMap<usize, HardFork>, Error> {
|
||||
let BlockchainResponse::HardForks(hfs) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::HardForks)
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(hfs)
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ fn map_request(
|
|||
R::DatabaseSize => database_size(env),
|
||||
R::OutputHistogram(input) => output_histogram(env, input),
|
||||
R::CoinbaseTxSum { height, count } => coinbase_tx_sum(env, height, count),
|
||||
R::HardForks => hard_forks(env),
|
||||
}
|
||||
|
||||
/* SOMEDAY: post-request handling, run some code for each request? */
|
||||
|
@ -648,3 +649,8 @@ fn output_histogram(env: &ConcreteEnv, input: OutputHistogramInput) -> ResponseR
|
|||
fn coinbase_tx_sum(env: &ConcreteEnv, height: usize, count: u64) -> ResponseResult {
|
||||
Ok(BlockchainResponse::CoinbaseTxSum(todo!()))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::HardForks`]
|
||||
fn hard_forks(env: &ConcreteEnv) -> ResponseResult {
|
||||
Ok(BlockchainResponse::HardForks(todo!()))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! responses are also tested in Cuprate's blockchain database crate.
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
ops::Range,
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,8 @@ use monero_serai::block::Block;
|
|||
|
||||
use crate::{
|
||||
types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation},
|
||||
AltBlockInformation, ChainId, CoinbaseTxSum, OutputHistogramEntry, OutputHistogramInput,
|
||||
AltBlockInformation, ChainId, CoinbaseTxSum, HardFork, OutputHistogramEntry,
|
||||
OutputHistogramInput,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- ReadRequest
|
||||
|
@ -107,7 +108,9 @@ pub enum BlockchainReadRequest {
|
|||
AltBlocksInChain(ChainId),
|
||||
|
||||
/// Get a [`Block`] by its height.
|
||||
Block { height: usize },
|
||||
Block {
|
||||
height: usize,
|
||||
},
|
||||
|
||||
/// Get a [`Block`] by its hash.
|
||||
BlockByHash([u8; 32]),
|
||||
|
@ -127,7 +130,12 @@ pub enum BlockchainReadRequest {
|
|||
/// `N` last blocks starting at particular height.
|
||||
///
|
||||
/// TODO: document fields after impl.
|
||||
CoinbaseTxSum { height: usize, count: u64 },
|
||||
CoinbaseTxSum {
|
||||
height: usize,
|
||||
count: u64,
|
||||
},
|
||||
|
||||
HardForks,
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- WriteRequest
|
||||
|
@ -276,6 +284,12 @@ pub enum BlockchainResponse {
|
|||
/// Response to [`BlockchainReadRequest::CoinbaseTxSum`].
|
||||
CoinbaseTxSum(CoinbaseTxSum),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::HardForks`].
|
||||
///
|
||||
/// - Key = height at which the hardfork activated
|
||||
/// - Value = hardfork version
|
||||
HardForks(BTreeMap<usize, HardFork>),
|
||||
|
||||
//------------------------------------------------------ Writes
|
||||
/// A generic Ok response to indicate a request was successfully handled.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue