mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-23 12:09:57 +00:00
Compare commits
No commits in common. "8a3229b3699ce4bf2bbe22495c18a3659dd500df" and "fd136b23f60bcd7cb4534a53268e93456fba7729" have entirely different histories.
8a3229b369
...
fd136b23f6
4 changed files with 44 additions and 53 deletions
|
@ -277,36 +277,33 @@ async fn get_block(
|
||||||
mut state: CupratedRpcHandler,
|
mut state: CupratedRpcHandler,
|
||||||
request: GetBlockRequest,
|
request: GetBlockRequest,
|
||||||
) -> Result<GetBlockResponse, Error> {
|
) -> Result<GetBlockResponse, Error> {
|
||||||
let (block, block_header) = if request.hash.is_empty() {
|
let block = if request.hash.is_empty() {
|
||||||
helper::check_height(&mut state, request.height).await?;
|
helper::check_height(&mut state, request.height).await?;
|
||||||
let block = blockchain::block(&mut state.blockchain_read, request.height).await?;
|
blockchain::block(&mut state.blockchain_read, request.height).await?
|
||||||
let block_header =
|
|
||||||
helper::block_header(&mut state, request.height, request.fill_pow_hash).await?;
|
|
||||||
(block, block_header)
|
|
||||||
} else {
|
} else {
|
||||||
let hash = helper::hex_to_hash(request.hash)?;
|
let hash = helper::hex_to_hash(request.hash)?;
|
||||||
let block = blockchain::block_by_hash(&mut state.blockchain_read, hash).await?;
|
blockchain::block_by_hash(&mut state.blockchain_read, hash).await?
|
||||||
let block_header =
|
|
||||||
helper::block_header_by_hash(&mut state, hash, request.fill_pow_hash).await?;
|
|
||||||
(block, block_header)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let blob = hex::encode(block.serialize());
|
Ok(todo!())
|
||||||
let miner_tx_hash = hex::encode(block.miner_transaction.hash());
|
|
||||||
let tx_hashes = block.transactions.iter().map(hex::encode).collect();
|
|
||||||
let json = {
|
|
||||||
let block = cuprate_types::json::block::Block::from(block);
|
|
||||||
serde_json::to_string_pretty(&block)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(GetBlockResponse {
|
// let block_header = (&block).into();
|
||||||
base: AccessResponseBase::ok(),
|
// let blob = hex::encode(block.block_blob);
|
||||||
blob,
|
// let miner_tx_hash = hex::encode(block.block.miner_transaction.hash());
|
||||||
json,
|
// let tx_hashes = block
|
||||||
miner_tx_hash,
|
// .txs
|
||||||
tx_hashes,
|
// .into_iter()
|
||||||
block_header,
|
// .map(|tx| hex::encode(tx.tx_hash))
|
||||||
})
|
// .collect();
|
||||||
|
|
||||||
|
// Ok(GetBlockResponse {
|
||||||
|
// base: AccessResponseBase::ok(),
|
||||||
|
// blob,
|
||||||
|
// json: todo!(), // TODO: make `JSON` type in `cuprate_rpc_types`
|
||||||
|
// miner_tx_hash,
|
||||||
|
// tx_hashes,
|
||||||
|
// block_header,
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2729-L2738>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2729-L2738>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use tower::ServiceExt;
|
use tower::ServiceExt;
|
||||||
|
|
||||||
use cuprate_helper::cast::usize_to_u64;
|
use cuprate_helper::cast::usize_to_u64;
|
||||||
|
@ -11,8 +11,6 @@ use cuprate_p2p_core::{
|
||||||
AddressBook, NetworkZone,
|
AddressBook, NetworkZone,
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: use `anyhow::Error` over `tower::BoxError` in address book.
|
|
||||||
|
|
||||||
/// [`AddressBookRequest::PeerlistSize`]
|
/// [`AddressBookRequest::PeerlistSize`]
|
||||||
pub(crate) async fn peerlist_size<Z: NetworkZone>(
|
pub(crate) async fn peerlist_size<Z: NetworkZone>(
|
||||||
address_book: &mut impl AddressBook<Z>,
|
address_book: &mut impl AddressBook<Z>,
|
||||||
|
@ -20,10 +18,10 @@ pub(crate) async fn peerlist_size<Z: NetworkZone>(
|
||||||
let AddressBookResponse::PeerlistSize { white, grey } = address_book
|
let AddressBookResponse::PeerlistSize { white, grey } = address_book
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(AddressBookRequest::PeerlistSize)
|
.call(AddressBookRequest::PeerlistSize)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -38,10 +36,10 @@ pub(crate) async fn connection_count<Z: NetworkZone>(
|
||||||
let AddressBookResponse::ConnectionCount { incoming, outgoing } = address_book
|
let AddressBookResponse::ConnectionCount { incoming, outgoing } = address_book
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(AddressBookRequest::ConnectionCount)
|
.call(AddressBookRequest::ConnectionCount)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -57,10 +55,10 @@ pub(crate) async fn set_ban<Z: NetworkZone>(
|
||||||
let AddressBookResponse::Ok = address_book
|
let AddressBookResponse::Ok = address_book
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(AddressBookRequest::SetBan(peer))
|
.call(AddressBookRequest::SetBan(peer))
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -76,10 +74,10 @@ pub(crate) async fn get_ban<Z: NetworkZone>(
|
||||||
let AddressBookResponse::GetBan { unban_instant } = address_book
|
let AddressBookResponse::GetBan { unban_instant } = address_book
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(AddressBookRequest::GetBan(peer))
|
.call(AddressBookRequest::GetBan(peer))
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -94,10 +92,10 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
|
||||||
let AddressBookResponse::GetBans(bans) = address_book
|
let AddressBookResponse::GetBans(bans) = address_book
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(AddressBookRequest::GetBans)
|
.call(AddressBookRequest::GetBans)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_consensus::context::{
|
use cuprate_consensus::context::{
|
||||||
|
@ -11,8 +11,6 @@ use cuprate_consensus::context::{
|
||||||
};
|
};
|
||||||
use cuprate_types::{FeeEstimate, HardFork, HardForkInfo};
|
use cuprate_types::{FeeEstimate, HardFork, HardForkInfo};
|
||||||
|
|
||||||
// FIXME: use `anyhow::Error` over `tower::BoxError` in blockchain context.
|
|
||||||
|
|
||||||
/// [`BlockChainContextRequest::Context`].
|
/// [`BlockChainContextRequest::Context`].
|
||||||
pub(crate) async fn context(
|
pub(crate) async fn context(
|
||||||
service: &mut BlockChainContextService,
|
service: &mut BlockChainContextService,
|
||||||
|
@ -20,10 +18,10 @@ pub(crate) async fn context(
|
||||||
let BlockChainContextResponse::Context(context) = service
|
let BlockChainContextResponse::Context(context) = service
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(BlockChainContextRequest::Context)
|
.call(BlockChainContextRequest::Context)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -39,10 +37,10 @@ pub(crate) async fn hard_fork_info(
|
||||||
let BlockChainContextResponse::HardForkInfo(hf_info) = service
|
let BlockChainContextResponse::HardForkInfo(hf_info) = service
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(BlockChainContextRequest::HardForkInfo(hard_fork))
|
.call(BlockChainContextRequest::HardForkInfo(hard_fork))
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -58,10 +56,10 @@ pub(crate) async fn fee_estimate(
|
||||||
let BlockChainContextResponse::FeeEstimate(fee) = service
|
let BlockChainContextResponse::FeeEstimate(fee) = service
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(BlockChainContextRequest::FeeEstimate { grace_blocks })
|
.call(BlockChainContextRequest::FeeEstimate { grace_blocks })
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_helper::cast::usize_to_u64;
|
use cuprate_helper::cast::usize_to_u64;
|
||||||
|
@ -14,17 +14,15 @@ use cuprate_txpool::{
|
||||||
TxEntry,
|
TxEntry,
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: use `anyhow::Error` over `tower::BoxError` in txpool.
|
|
||||||
|
|
||||||
/// [`TxpoolReadRequest::Backlog`]
|
/// [`TxpoolReadRequest::Backlog`]
|
||||||
pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<TxEntry>, Error> {
|
pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<TxEntry>, Error> {
|
||||||
let TxpoolReadResponse::Backlog(tx_entries) = txpool_read
|
let TxpoolReadResponse::Backlog(tx_entries) = txpool_read
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(TxpoolReadRequest::Backlog)
|
.call(TxpoolReadRequest::Backlog)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
@ -37,10 +35,10 @@ pub(crate) async fn size(txpool_read: &mut TxpoolReadHandle) -> Result<u64, Erro
|
||||||
let TxpoolReadResponse::Size(size) = txpool_read
|
let TxpoolReadResponse::Size(size) = txpool_read
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
.call(TxpoolReadRequest::Size)
|
.call(TxpoolReadRequest::Size)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.expect("TODO")
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue