mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
Compare commits
5 commits
d7d8b3509e
...
e2f25bd52d
Author | SHA1 | Date | |
---|---|---|---|
|
e2f25bd52d | ||
|
548639b2f6 | ||
|
d56477cd61 | ||
|
7148ba1668 | ||
|
5926f24d22 |
11 changed files with 386 additions and 69 deletions
|
@ -3,13 +3,13 @@
|
|||
use std::task::{Context, Poll};
|
||||
|
||||
use anyhow::Error;
|
||||
use cuprate_consensus::BlockChainContextService;
|
||||
use cuprate_pruning::PruningSeed;
|
||||
use futures::future::BoxFuture;
|
||||
use monero_serai::block::Block;
|
||||
use tower::Service;
|
||||
|
||||
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
|
||||
use cuprate_consensus::BlockChainContextService;
|
||||
use cuprate_pruning::PruningSeed;
|
||||
use cuprate_rpc_interface::RpcHandler;
|
||||
use cuprate_rpc_types::{
|
||||
bin::{BinRequest, BinResponse},
|
||||
|
@ -17,12 +17,12 @@ use cuprate_rpc_types::{
|
|||
other::{OtherRequest, OtherResponse},
|
||||
};
|
||||
use cuprate_txpool::service::{TxpoolReadHandle, TxpoolWriteHandle};
|
||||
use cuprate_types::{AddAuxPow, AuxPow, HardFork};
|
||||
|
||||
use crate::rpc::{bin, json, other};
|
||||
|
||||
/// TODO: use real type when public.
|
||||
#[derive(Clone)]
|
||||
#[expect(clippy::large_enum_variant)]
|
||||
pub enum BlockchainManagerRequest {
|
||||
/// Pop blocks off the top of the blockchain.
|
||||
///
|
||||
|
@ -56,6 +56,38 @@ pub enum BlockchainManagerRequest {
|
|||
|
||||
/// The height of the next block in the chain.
|
||||
TargetHeight,
|
||||
|
||||
/// Calculate proof-of-work for this block.
|
||||
CalculatePow {
|
||||
/// The hardfork of the protocol at this block height.
|
||||
hardfork: HardFork,
|
||||
/// The height of the block.
|
||||
height: usize,
|
||||
/// The block data.
|
||||
block: Block,
|
||||
/// The seed hash for the proof-of-work.
|
||||
seed_hash: [u8; 32],
|
||||
},
|
||||
|
||||
/// TODO
|
||||
AddAuxPow {
|
||||
/// TODO
|
||||
blocktemplate_blob: Vec<u8>,
|
||||
/// TODO
|
||||
aux_pow: Vec<AuxPow>,
|
||||
},
|
||||
|
||||
/// TODO
|
||||
GenerateBlocks {
|
||||
/// TODO
|
||||
amount_of_blocks: u64,
|
||||
/// TODO
|
||||
prev_block: [u8; 32],
|
||||
/// TODO
|
||||
starting_nonce: u32,
|
||||
/// TODO
|
||||
wallet_address: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// TODO: use real type when public.
|
||||
|
@ -88,6 +120,20 @@ pub enum BlockchainManagerResponse {
|
|||
|
||||
/// Response to [`BlockchainManagerRequest::TargetHeight`]
|
||||
TargetHeight { height: usize },
|
||||
|
||||
/// Response to [`BlockchainManagerRequest::CalculatePow`]
|
||||
CalculatePow([u8; 32]),
|
||||
|
||||
/// Response to [`BlockchainManagerRequest::AddAuxPow`]
|
||||
AddAuxPow(AddAuxPow),
|
||||
|
||||
/// Response to [`BlockchainManagerRequest::GenerateBlocks`]
|
||||
GenerateBlocks {
|
||||
/// TODO
|
||||
blocks: Vec<[u8; 32]>,
|
||||
/// TODO
|
||||
height: usize,
|
||||
},
|
||||
}
|
||||
|
||||
/// TODO: use real type when public.
|
||||
|
|
|
@ -40,15 +40,22 @@ use cuprate_rpc_types::{
|
|||
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
||||
SyncInfoResponse,
|
||||
},
|
||||
misc::{BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status, TxBacklogEntry},
|
||||
misc::{
|
||||
AuxPow, BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status,
|
||||
TxBacklogEntry,
|
||||
},
|
||||
CORE_RPC_VERSION,
|
||||
};
|
||||
use cuprate_types::HardFork;
|
||||
use cuprate_types::{Chain, HardFork};
|
||||
|
||||
use crate::rpc::{
|
||||
helper,
|
||||
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
||||
CupratedRpcHandler,
|
||||
use crate::{
|
||||
constants::VERSION_BUILD,
|
||||
rpc::{
|
||||
helper,
|
||||
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
||||
CupratedRpcHandler,
|
||||
},
|
||||
statics::START_INSTANT_UNIX,
|
||||
};
|
||||
|
||||
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
|
||||
|
@ -158,10 +165,29 @@ async fn generate_blocks(
|
|||
state: CupratedRpcHandler,
|
||||
request: GenerateBlocksRequest,
|
||||
) -> Result<GenerateBlocksResponse, Error> {
|
||||
if todo!("active cuprated chain") != todo!("regtest chain") {
|
||||
return Err(anyhow!("Regtest required when generating blocks"));
|
||||
}
|
||||
|
||||
// TODO: is this value only used as a local variable in the handler?
|
||||
// it may not be needed in the request type.
|
||||
let prev_block = helper::hex_to_hash(request.prev_block)?;
|
||||
|
||||
let (blocks, height) = blockchain_manager::generate_blocks(
|
||||
&mut state.blockchain_manager,
|
||||
request.amount_of_blocks,
|
||||
prev_block,
|
||||
request.starting_nonce,
|
||||
request.wallet_address,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let blocks = blocks.into_iter().map(hex::encode).collect();
|
||||
|
||||
Ok(GenerateBlocksResponse {
|
||||
base: ResponseBase::OK,
|
||||
blocks: todo!(),
|
||||
height: todo!(),
|
||||
blocks,
|
||||
height,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -331,50 +357,120 @@ async fn get_connections(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L501-L582>
|
||||
async fn get_info(
|
||||
state: CupratedRpcHandler,
|
||||
mut state: CupratedRpcHandler,
|
||||
request: GetInfoRequest,
|
||||
) -> Result<GetInfoResponse, Error> {
|
||||
let restricted = state.restricted();
|
||||
let context = blockchain_context::context(&mut state.blockchain_context).await?;
|
||||
|
||||
let c = context.unchecked_blockchain_context();
|
||||
let cumulative_difficulty = c.cumulative_difficulty;
|
||||
let adjusted_time = c.current_adjusted_timestamp_for_time_lock(); // TODO: is this correct?
|
||||
|
||||
let c = &c.context_to_verify_block;
|
||||
|
||||
let alt_blocks_count = if restricted {
|
||||
0
|
||||
} else {
|
||||
blockchain::alt_chain_count(&mut state.blockchain_read).await?
|
||||
};
|
||||
let block_weight_limit = usize_to_u64(c.effective_median_weight); // TODO: is this correct?
|
||||
let block_weight_median = usize_to_u64(c.median_weight_for_block_reward); // TODO: is this correct?
|
||||
let block_size_limit = block_weight_limit;
|
||||
let block_size_median = block_weight_median;
|
||||
let (bootstrap_daemon_address, was_bootstrap_ever_used) = if restricted {
|
||||
(String::new(), false)
|
||||
} else {
|
||||
todo!()
|
||||
};
|
||||
let busy_syncing = blockchain_manager::syncing(&mut state.blockchain_manager).await?;
|
||||
let (cumulative_difficulty, cumulative_difficulty_top64) =
|
||||
split_u128_into_low_high_bits(cumulative_difficulty);
|
||||
let (database_size, free_space) = blockchain::database_size(&mut state.blockchain_read).await?;
|
||||
let (database_size, free_space) = if restricted {
|
||||
let database_size = todo!(); // round_up(res.database_size, 5ull* 1024 * 1024 * 1024) */
|
||||
(database_size, u64::MAX)
|
||||
} else {
|
||||
(database_size, free_space)
|
||||
};
|
||||
let (difficulty, difficulty_top64) = split_u128_into_low_high_bits(c.next_difficulty);
|
||||
let height = usize_to_u64(c.chain_height);
|
||||
let height_without_bootstrap = if restricted { 0 } else { height };
|
||||
let (incoming_connections_count, outgoing_connections_count) = if restricted {
|
||||
(0, 0)
|
||||
} else {
|
||||
address_book::connection_count::<ClearNet>(&mut DummyAddressBook).await?
|
||||
};
|
||||
let mainnet = todo!();
|
||||
let nettype = todo!();
|
||||
let offline = todo!();
|
||||
let rpc_connections_count = if restricted { 0 } else { todo!() };
|
||||
let stagenet = todo!();
|
||||
let start_time = if restricted { 0 } else { *START_INSTANT_UNIX };
|
||||
let synchronized = blockchain_manager::synced(&mut state.blockchain_manager).await?;
|
||||
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
|
||||
let target = blockchain_manager::target(&mut state.blockchain_manager)
|
||||
.await?
|
||||
.as_secs();
|
||||
let testnet = todo!();
|
||||
let top_block_hash = hex::encode(c.top_hash);
|
||||
let tx_count = blockchain::total_tx_count(&mut state.blockchain_read).await?;
|
||||
let tx_pool_size = txpool::size(&mut state.txpool_read, !restricted).await?;
|
||||
let update_available = if restricted { false } else { todo!() };
|
||||
let version = if restricted {
|
||||
String::new()
|
||||
} else {
|
||||
VERSION_BUILD.to_string()
|
||||
};
|
||||
let (white_peerlist_size, grey_peerlist_size) = if restricted {
|
||||
(0, 0)
|
||||
} else {
|
||||
address_book::peerlist_size::<ClearNet>(&mut DummyAddressBook).await?
|
||||
};
|
||||
let wide_cumulative_difficulty = format!("{cumulative_difficulty:#x}");
|
||||
let wide_difficulty = format!("{:#x}", c.next_difficulty);
|
||||
|
||||
Ok(GetInfoResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
adjusted_time: todo!(),
|
||||
alt_blocks_count: todo!(),
|
||||
block_size_limit: todo!(),
|
||||
block_size_median: todo!(),
|
||||
block_weight_limit: todo!(),
|
||||
block_weight_median: todo!(),
|
||||
bootstrap_daemon_address: todo!(),
|
||||
busy_syncing: todo!(),
|
||||
cumulative_difficulty_top64: todo!(),
|
||||
cumulative_difficulty: todo!(),
|
||||
database_size: todo!(),
|
||||
difficulty_top64: todo!(),
|
||||
difficulty: todo!(),
|
||||
free_space: todo!(),
|
||||
grey_peerlist_size: todo!(),
|
||||
height: todo!(),
|
||||
height_without_bootstrap: todo!(),
|
||||
incoming_connections_count: todo!(),
|
||||
mainnet: todo!(),
|
||||
nettype: todo!(),
|
||||
offline: todo!(),
|
||||
outgoing_connections_count: todo!(),
|
||||
restricted: todo!(),
|
||||
rpc_connections_count: todo!(),
|
||||
stagenet: todo!(),
|
||||
start_time: todo!(),
|
||||
synchronized: todo!(),
|
||||
target_height: todo!(),
|
||||
target: todo!(),
|
||||
testnet: todo!(),
|
||||
top_block_hash: todo!(),
|
||||
tx_count: todo!(),
|
||||
tx_pool_size: todo!(),
|
||||
update_available: todo!(),
|
||||
version: todo!(),
|
||||
was_bootstrap_ever_used: todo!(),
|
||||
white_peerlist_size: todo!(),
|
||||
wide_cumulative_difficulty: todo!(),
|
||||
wide_difficulty: todo!(),
|
||||
adjusted_time,
|
||||
alt_blocks_count,
|
||||
block_size_limit,
|
||||
block_size_median,
|
||||
block_weight_limit,
|
||||
block_weight_median,
|
||||
bootstrap_daemon_address,
|
||||
busy_syncing,
|
||||
cumulative_difficulty_top64,
|
||||
cumulative_difficulty,
|
||||
database_size,
|
||||
difficulty_top64,
|
||||
difficulty,
|
||||
free_space,
|
||||
grey_peerlist_size,
|
||||
height,
|
||||
height_without_bootstrap,
|
||||
incoming_connections_count,
|
||||
mainnet,
|
||||
nettype,
|
||||
offline,
|
||||
outgoing_connections_count,
|
||||
restricted,
|
||||
rpc_connections_count,
|
||||
stagenet,
|
||||
start_time,
|
||||
synchronized,
|
||||
target_height,
|
||||
target,
|
||||
testnet,
|
||||
top_block_hash,
|
||||
tx_count,
|
||||
tx_pool_size,
|
||||
update_available,
|
||||
version,
|
||||
was_bootstrap_ever_used,
|
||||
white_peerlist_size,
|
||||
wide_cumulative_difficulty,
|
||||
wide_difficulty,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -734,10 +830,26 @@ async fn prune_blockchain(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2035-L2070>
|
||||
async fn calc_pow(
|
||||
state: CupratedRpcHandler,
|
||||
request: CalcPowRequest,
|
||||
mut state: CupratedRpcHandler,
|
||||
mut request: CalcPowRequest,
|
||||
) -> Result<CalcPowResponse, Error> {
|
||||
Ok(CalcPowResponse { pow_hash: todo!() })
|
||||
let hardfork = HardFork::from_version(request.major_version)?;
|
||||
let mut block_blob: Vec<u8> = hex::decode(request.block_blob)?;
|
||||
let block = Block::read(&mut block_blob.as_slice())?;
|
||||
let seed_hash = helper::hex_to_hash(request.seed_hash)?;
|
||||
|
||||
let pow_hash = blockchain_manager::calculate_pow(
|
||||
&mut state.blockchain_manager,
|
||||
hardfork,
|
||||
request.height,
|
||||
block,
|
||||
seed_hash,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let hex = hex::encode(pow_hash);
|
||||
|
||||
Ok(CalcPowResponse { pow_hash: hex })
|
||||
}
|
||||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3542-L3551>
|
||||
|
@ -745,7 +857,7 @@ async fn flush_cache(
|
|||
state: CupratedRpcHandler,
|
||||
request: FlushCacheRequest,
|
||||
) -> Result<FlushCacheResponse, Error> {
|
||||
todo!();
|
||||
// TODO: cuprated doesn't need this call; decide behavior.
|
||||
|
||||
Ok(FlushCacheResponse {
|
||||
base: ResponseBase::OK,
|
||||
|
@ -754,16 +866,43 @@ async fn flush_cache(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2072-L2207>
|
||||
async fn add_aux_pow(
|
||||
state: CupratedRpcHandler,
|
||||
mut state: CupratedRpcHandler,
|
||||
request: AddAuxPowRequest,
|
||||
) -> Result<AddAuxPowResponse, Error> {
|
||||
let blocktemplate_blob = hex::decode(request.blocktemplate_blob)?;
|
||||
let aux_pow = request
|
||||
.aux_pow
|
||||
.into_iter()
|
||||
.map(|aux| {
|
||||
let id = helper::hex_to_hash(aux.id)?;
|
||||
let hash = helper::hex_to_hash(aux.hash)?;
|
||||
Ok(cuprate_types::AuxPow { id, hash })
|
||||
})
|
||||
.collect::<Result<Vec<_>, Error>>()?;
|
||||
|
||||
let resp =
|
||||
blockchain_manager::add_aux_pow(&mut state.blockchain_manager, blocktemplate_blob, aux_pow)
|
||||
.await?;
|
||||
|
||||
let blocktemplate_blob = hex::encode(resp.blocktemplate_blob);
|
||||
let blockhashing_blob = hex::encode(resp.blockhashing_blob);
|
||||
let merkle_root = hex::encode(resp.merkle_root);
|
||||
let aux_pow = resp
|
||||
.aux_pow
|
||||
.into_iter()
|
||||
.map(|aux| AuxPow {
|
||||
id: hex::encode(aux.id),
|
||||
hash: hex::encode(aux.hash),
|
||||
})
|
||||
.collect::<Vec<AuxPow>>();
|
||||
|
||||
Ok(AddAuxPowResponse {
|
||||
base: ResponseBase::OK,
|
||||
blocktemplate_blob: todo!(),
|
||||
blockhashing_blob: todo!(),
|
||||
merkle_root: todo!(),
|
||||
merkle_tree_depth: todo!(),
|
||||
aux_pow: todo!(),
|
||||
blocktemplate_blob,
|
||||
blockhashing_blob,
|
||||
merkle_root,
|
||||
merkle_tree_depth: resp.merkle_tree_depth,
|
||||
aux_pow,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -772,6 +911,9 @@ async fn get_tx_ids_loose(
|
|||
state: CupratedRpcHandler,
|
||||
request: GetTxIdsLooseRequest,
|
||||
) -> Result<GetTxIdsLooseResponse, Error> {
|
||||
// TODO: this RPC call is not yet in the v0.18 branch.
|
||||
return Err(anyhow!("not implemented"));
|
||||
|
||||
Ok(GetTxIdsLooseResponse {
|
||||
base: ResponseBase::OK,
|
||||
txids: todo!(),
|
||||
|
|
|
@ -375,3 +375,19 @@ pub(crate) async fn alt_chains(
|
|||
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::AltChainCount`]
|
||||
pub(crate) async fn alt_chain_count(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
) -> Result<u64, Error> {
|
||||
let BlockchainResponse::AltChainCount(count) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::AltChainCount)
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(usize_to_u64(count))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Functions for [`BlockchainManagerRequest`] & [`BlockchainManagerResponse`].
|
||||
|
||||
use anyhow::Error;
|
||||
use cuprate_types::{AddAuxPow, AuxPow, HardFork};
|
||||
use monero_serai::block::Block;
|
||||
use tower::{Service, ServiceExt};
|
||||
|
||||
|
@ -142,3 +143,74 @@ pub(crate) async fn target_height(
|
|||
|
||||
Ok(usize_to_u64(height))
|
||||
}
|
||||
|
||||
/// [`BlockchainManagerRequest::CalculatePow`]
|
||||
pub(crate) async fn calculate_pow(
|
||||
blockchain_manager: &mut BlockchainManagerHandle,
|
||||
hardfork: HardFork,
|
||||
height: u64,
|
||||
block: Block,
|
||||
seed_hash: [u8; 32],
|
||||
) -> Result<[u8; 32], Error> {
|
||||
let BlockchainManagerResponse::CalculatePow(hash) = blockchain_manager
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainManagerRequest::CalculatePow {
|
||||
hardfork,
|
||||
height: u64_to_usize(height),
|
||||
block,
|
||||
seed_hash,
|
||||
})
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
/// [`BlockchainManagerRequest::AddAuxPow`]
|
||||
pub(crate) async fn add_aux_pow(
|
||||
blockchain_manager: &mut BlockchainManagerHandle,
|
||||
blocktemplate_blob: Vec<u8>,
|
||||
aux_pow: Vec<AuxPow>,
|
||||
) -> Result<AddAuxPow, Error> {
|
||||
let BlockchainManagerResponse::AddAuxPow(response) = blockchain_manager
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainManagerRequest::AddAuxPow {
|
||||
blocktemplate_blob,
|
||||
aux_pow,
|
||||
})
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
/// [`BlockchainManagerRequest::GenerateBlocks`]
|
||||
pub(crate) async fn generate_blocks(
|
||||
blockchain_manager: &mut BlockchainManagerHandle,
|
||||
amount_of_blocks: u64,
|
||||
prev_block: [u8; 32],
|
||||
starting_nonce: u32,
|
||||
wallet_address: String,
|
||||
) -> Result<(Vec<[u8; 32]>, u64), Error> {
|
||||
let BlockchainManagerResponse::GenerateBlocks { blocks, height } = blockchain_manager
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainManagerRequest::GenerateBlocks {
|
||||
amount_of_blocks,
|
||||
prev_block,
|
||||
starting_nonce,
|
||||
wallet_address,
|
||||
})
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok((blocks, usize_to_u64(height)))
|
||||
}
|
||||
|
|
|
@ -33,12 +33,17 @@ pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<Tx
|
|||
}
|
||||
|
||||
/// [`TxpoolReadRequest::Size`]
|
||||
pub(crate) async fn size(txpool_read: &mut TxpoolReadHandle) -> Result<u64, Error> {
|
||||
pub(crate) async fn size(
|
||||
txpool_read: &mut TxpoolReadHandle,
|
||||
include_sensitive_txs: bool,
|
||||
) -> Result<u64, Error> {
|
||||
let TxpoolReadResponse::Size(size) = txpool_read
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
.call(TxpoolReadRequest::Size)
|
||||
.call(TxpoolReadRequest::Size {
|
||||
include_sensitive_txs,
|
||||
})
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
else {
|
||||
|
|
|
@ -123,6 +123,7 @@ fn map_request(
|
|||
R::CoinbaseTxSum { height, count } => coinbase_tx_sum(env, height, count),
|
||||
R::HardForks => hard_forks(env),
|
||||
R::AltChains => alt_chains(env),
|
||||
R::AltChainCount => alt_chain_count(env),
|
||||
}
|
||||
|
||||
/* SOMEDAY: post-request handling, run some code for each request? */
|
||||
|
@ -660,3 +661,8 @@ fn hard_forks(env: &ConcreteEnv) -> ResponseResult {
|
|||
fn alt_chains(env: &ConcreteEnv) -> ResponseResult {
|
||||
Ok(BlockchainResponse::AltChains(todo!()))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::AltChainCount`]
|
||||
fn alt_chain_count(env: &ConcreteEnv) -> ResponseResult {
|
||||
Ok(BlockchainResponse::AltChainCount(todo!()))
|
||||
}
|
||||
|
|
|
@ -20,7 +20,10 @@ pub enum TxpoolReadRequest {
|
|||
Backlog,
|
||||
|
||||
/// Get the number of transactions in the pool.
|
||||
Size,
|
||||
Size {
|
||||
/// TODO
|
||||
include_sensitive_txs: bool,
|
||||
},
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
||||
|
|
|
@ -66,7 +66,9 @@ fn map_request(
|
|||
TxpoolReadRequest::TxBlob(tx_hash) => tx_blob(env, &tx_hash),
|
||||
TxpoolReadRequest::TxVerificationData(tx_hash) => tx_verification_data(env, &tx_hash),
|
||||
TxpoolReadRequest::Backlog => backlog(env),
|
||||
TxpoolReadRequest::Size => size(env),
|
||||
TxpoolReadRequest::Size {
|
||||
include_sensitive_txs,
|
||||
} => size(env, include_sensitive_txs),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,6 +121,6 @@ fn backlog(env: &ConcreteEnv) -> ReadResponseResult {
|
|||
|
||||
/// [`TxpoolReadRequest::Size`].
|
||||
#[inline]
|
||||
fn size(env: &ConcreteEnv) -> ReadResponseResult {
|
||||
fn size(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult {
|
||||
Ok(TxpoolReadResponse::Size(todo!()))
|
||||
}
|
||||
|
|
|
@ -135,6 +135,9 @@ pub enum BlockchainReadRequest {
|
|||
|
||||
/// TODO
|
||||
AltChains,
|
||||
|
||||
/// TODO
|
||||
AltChainCount,
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- WriteRequest
|
||||
|
@ -289,8 +292,12 @@ pub enum BlockchainResponse {
|
|||
/// - Value = hardfork version
|
||||
HardForks(BTreeMap<usize, HardFork>),
|
||||
|
||||
/// TODO
|
||||
AltChains(Vec<ChainInfo>),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::AltChainCount`].
|
||||
AltChainCount(usize),
|
||||
|
||||
//------------------------------------------------------ Writes
|
||||
/// A generic Ok response to indicate a request was successfully handled.
|
||||
///
|
||||
|
|
|
@ -20,9 +20,10 @@ pub use transaction_verification_data::{
|
|||
CachedVerificationState, TransactionVerificationData, TxVersion,
|
||||
};
|
||||
pub use types::{
|
||||
AltBlockInformation, Chain, ChainId, ChainInfo, CoinbaseTxSum, ExtendedBlockHeader,
|
||||
FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry, OutputHistogramEntry,
|
||||
OutputHistogramInput, OutputOnChain, VerifiedBlockInformation, VerifiedTransactionInformation,
|
||||
AddAuxPow, AltBlockInformation, AuxPow, Chain, ChainId, ChainInfo, CoinbaseTxSum,
|
||||
ExtendedBlockHeader, FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry,
|
||||
OutputHistogramEntry, OutputHistogramInput, OutputOnChain, VerifiedBlockInformation,
|
||||
VerifiedTransactionInformation,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Feature-gated
|
||||
|
|
|
@ -242,6 +242,23 @@ pub struct ChainInfo {
|
|||
pub main_chain_parent_block: [u8; 32],
|
||||
}
|
||||
|
||||
/// Used in RPC's `add_aux_pow`.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct AuxPow {
|
||||
pub id: [u8; 32],
|
||||
pub hash: [u8; 32],
|
||||
}
|
||||
|
||||
/// Used in RPC's `add_aux_pow`.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct AddAuxPow {
|
||||
pub blocktemplate_blob: Vec<u8>,
|
||||
pub blockhashing_blob: Vec<u8>,
|
||||
pub merkle_root: [u8; 32],
|
||||
pub merkle_tree_depth: u64,
|
||||
pub aux_pow: Vec<AuxPow>,
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
Loading…
Reference in a new issue