mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 11:39:30 +00:00
/get_output_distribution.bin
This commit is contained in:
parent
8cd319cc45
commit
3664e2f794
5 changed files with 94 additions and 57 deletions
|
@ -4,6 +4,7 @@ use anyhow::{anyhow, Error};
|
|||
use bytes::Bytes;
|
||||
|
||||
use cuprate_constants::rpc::{RESTRICTED_BLOCK_COUNT, RESTRICTED_TRANSACTIONS_COUNT};
|
||||
use cuprate_fixed_bytes::ByteArrayVec;
|
||||
use cuprate_rpc_interface::RpcHandler;
|
||||
use cuprate_rpc_types::{
|
||||
base::{AccessResponseBase, ResponseBase},
|
||||
|
@ -18,7 +19,11 @@ use cuprate_rpc_types::{
|
|||
};
|
||||
use cuprate_types::{rpc::PoolInfoExtent, BlockCompleteEntry};
|
||||
|
||||
use crate::rpc::{helper, request::blockchain, shared, CupratedRpcHandler};
|
||||
use crate::rpc::{
|
||||
helper,
|
||||
request::{blockchain, txpool},
|
||||
shared, CupratedRpcHandler,
|
||||
};
|
||||
|
||||
/// Map a [`BinRequest`] to the function that will lead to a [`BinResponse`].
|
||||
pub(super) async fn map_request(
|
||||
|
@ -179,14 +184,12 @@ async fn get_hashes(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L959-L977>
|
||||
async fn get_output_indexes(
|
||||
state: CupratedRpcHandler,
|
||||
mut state: CupratedRpcHandler,
|
||||
request: GetOutputIndexesRequest,
|
||||
) -> Result<GetOutputIndexesResponse, Error> {
|
||||
let o_indexes = blockchain::tx_output_indexes(&mut state.blockchain_read, request.txid).await?;
|
||||
|
||||
Ok(GetOutputIndexesResponse {
|
||||
base: helper::access_response_base(false),
|
||||
o_indexes,
|
||||
o_indexes: blockchain::tx_output_indexes(&mut state.blockchain_read, request.txid).await?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -200,12 +203,14 @@ async fn get_outs(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1689-L1711>
|
||||
async fn get_transaction_pool_hashes(
|
||||
state: CupratedRpcHandler,
|
||||
request: GetTransactionPoolHashesRequest,
|
||||
mut state: CupratedRpcHandler,
|
||||
_: GetTransactionPoolHashesRequest,
|
||||
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
||||
Ok(GetTransactionPoolHashesResponse {
|
||||
base: helper::access_response_base(false),
|
||||
..todo!()
|
||||
tx_hashes: shared::get_transaction_pool_hashes(state)
|
||||
.await
|
||||
.map(ByteArrayVec::from)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -214,8 +219,5 @@ async fn get_output_distribution(
|
|||
state: CupratedRpcHandler,
|
||||
request: GetOutputDistributionRequest,
|
||||
) -> Result<GetOutputDistributionResponse, Error> {
|
||||
Ok(GetOutputDistributionResponse {
|
||||
base: helper::access_response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
shared::get_output_distribution(state, request).await
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ use crate::{
|
|||
rpc::{
|
||||
helper,
|
||||
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
||||
CupratedRpcHandler,
|
||||
shared, CupratedRpcHandler,
|
||||
},
|
||||
statics::START_INSTANT_UNIX,
|
||||
};
|
||||
|
@ -958,35 +958,10 @@ async fn get_transaction_pool_backlog(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3352-L3398>
|
||||
async fn get_output_distribution(
|
||||
mut state: CupratedRpcHandler,
|
||||
state: CupratedRpcHandler,
|
||||
request: GetOutputDistributionRequest,
|
||||
) -> Result<GetOutputDistributionResponse, Error> {
|
||||
if state.is_restricted() && request.amounts != [1, 0] {
|
||||
return Err(anyhow!(
|
||||
"Restricted RPC can only get output distribution for RCT outputs. Use your own node."
|
||||
));
|
||||
}
|
||||
|
||||
// 0 is placeholder for the whole chain
|
||||
let req_to_height = if request.to_height == 0 {
|
||||
helper::top_height(&mut state).await?.0.saturating_sub(1)
|
||||
} else {
|
||||
request.to_height
|
||||
};
|
||||
|
||||
let distributions = request.amounts.into_iter().map(|amount| {
|
||||
fn get_output_distribution() -> Result<Distribution, Error> {
|
||||
todo!("https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/rpc/rpc_handler.cpp#L29");
|
||||
Err(anyhow!("Failed to get output distribution"))
|
||||
}
|
||||
|
||||
get_output_distribution()
|
||||
}).collect::<Result<Vec<Distribution>, _>>()?;
|
||||
|
||||
Ok(GetOutputDistributionResponse {
|
||||
base: helper::access_response_base(false),
|
||||
distributions,
|
||||
})
|
||||
shared::get_output_distribution(state, request).await
|
||||
}
|
||||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1998-L2033>
|
||||
|
|
|
@ -651,20 +651,13 @@ async fn get_transaction_pool_hashes(
|
|||
mut state: CupratedRpcHandler,
|
||||
_: GetTransactionPoolHashesRequest,
|
||||
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
||||
let include_sensitive_txs = !state.is_restricted();
|
||||
|
||||
// FIXME: this request is a bit overkill, we only need the hashes.
|
||||
// We could create a separate request for this.
|
||||
let tx_hashes = txpool::pool(&mut state.txpool_read, include_sensitive_txs)
|
||||
.await?
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|tx| tx.id_hash)
|
||||
.collect();
|
||||
|
||||
Ok(GetTransactionPoolHashesResponse {
|
||||
base: helper::response_base(false),
|
||||
tx_hashes,
|
||||
tx_hashes: shared::get_transaction_pool_hashes(state)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(Hex)
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -438,7 +438,7 @@ pub(crate) async fn tx_output_indexes(
|
|||
let BlockchainResponse::TxOutputIndexes(o_indexes) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::TxOutputIndexes(tx_hash))
|
||||
.call(BlockchainReadRequest::TxOutputIndexes { tx_hash })
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
|
|
|
@ -10,11 +10,19 @@ use cuprate_helper::cast::usize_to_u64;
|
|||
use cuprate_hex::Hex;
|
||||
use cuprate_rpc_interface::RpcHandler;
|
||||
use cuprate_rpc_types::{
|
||||
bin::{GetOutsRequest, GetOutsResponse},
|
||||
misc::OutKeyBin,
|
||||
bin::{
|
||||
GetOutsRequest, GetOutsResponse, GetTransactionPoolHashesRequest,
|
||||
GetTransactionPoolHashesResponse,
|
||||
},
|
||||
json::{GetOutputDistributionRequest, GetOutputDistributionResponse},
|
||||
misc::{Distribution, OutKeyBin},
|
||||
};
|
||||
|
||||
use crate::rpc::{helper, request::blockchain, CupratedRpcHandler};
|
||||
use crate::rpc::{
|
||||
helper,
|
||||
request::{blockchain, txpool},
|
||||
CupratedRpcHandler,
|
||||
};
|
||||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L912-L957>
|
||||
///
|
||||
|
@ -48,7 +56,7 @@ pub(super) async fn get_outs(
|
|||
.await?
|
||||
.into_iter()
|
||||
.flat_map(|(amount, index_map)| {
|
||||
index_map.into_iter().map(|(_, out)| OutKeyBin {
|
||||
index_map.into_values().map(|out| OutKeyBin {
|
||||
key: out.key.map_or([0; 32], |e| e.compress().0),
|
||||
mask: out.commitment.compress().0,
|
||||
unlocked: matches!(out.time_lock, Timelock::None),
|
||||
|
@ -63,3 +71,62 @@ pub(super) async fn get_outs(
|
|||
outs,
|
||||
})
|
||||
}
|
||||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1713-L1739>
|
||||
///
|
||||
/// Shared between:
|
||||
/// - Other JSON's `/get_transaction_pool_hashes`
|
||||
/// - Binary's `/get_transaction_pool_hashes.bin`
|
||||
///
|
||||
/// Returns transaction hashes.
|
||||
pub(super) async fn get_transaction_pool_hashes(
|
||||
mut state: CupratedRpcHandler,
|
||||
) -> Result<Vec<[u8; 32]>, Error> {
|
||||
let include_sensitive_txs = !state.is_restricted();
|
||||
|
||||
// FIXME: this request is a bit overkill, we only need the hashes.
|
||||
// We could create a separate request for this.
|
||||
Ok(txpool::pool(&mut state.txpool_read, include_sensitive_txs)
|
||||
.await?
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|tx| tx.id_hash.0)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3352-L3398>
|
||||
///
|
||||
/// Shared between:
|
||||
/// - JSON-RPC's `get_output_distribution`
|
||||
/// - Binary's `/get_output_distribution.bin`
|
||||
pub(super) async fn get_output_distribution(
|
||||
mut state: CupratedRpcHandler,
|
||||
request: GetOutputDistributionRequest,
|
||||
) -> Result<GetOutputDistributionResponse, Error> {
|
||||
if state.is_restricted() && request.amounts != [1, 0] {
|
||||
return Err(anyhow!(
|
||||
"Restricted RPC can only get output distribution for RCT outputs. Use your own node."
|
||||
));
|
||||
}
|
||||
|
||||
// 0 is placeholder for the whole chain
|
||||
let req_to_height = if request.to_height == 0 {
|
||||
helper::top_height(&mut state).await?.0.saturating_sub(1)
|
||||
} else {
|
||||
request.to_height
|
||||
};
|
||||
|
||||
let distributions = request.amounts.into_iter().map(|amount| {
|
||||
fn get_output_distribution() -> Result<Distribution, Error> {
|
||||
todo!("https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/rpc/rpc_handler.cpp#L29");
|
||||
Err(anyhow!("Failed to get output distribution"))
|
||||
}
|
||||
|
||||
get_output_distribution()
|
||||
}).collect::<Result<Vec<Distribution>, _>>()?;
|
||||
|
||||
Ok(GetOutputDistributionResponse {
|
||||
base: helper::access_response_base(false),
|
||||
distributions,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue