mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +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 bytes::Bytes;
|
||||||
|
|
||||||
use cuprate_constants::rpc::{RESTRICTED_BLOCK_COUNT, RESTRICTED_TRANSACTIONS_COUNT};
|
use cuprate_constants::rpc::{RESTRICTED_BLOCK_COUNT, RESTRICTED_TRANSACTIONS_COUNT};
|
||||||
|
use cuprate_fixed_bytes::ByteArrayVec;
|
||||||
use cuprate_rpc_interface::RpcHandler;
|
use cuprate_rpc_interface::RpcHandler;
|
||||||
use cuprate_rpc_types::{
|
use cuprate_rpc_types::{
|
||||||
base::{AccessResponseBase, ResponseBase},
|
base::{AccessResponseBase, ResponseBase},
|
||||||
|
@ -18,7 +19,11 @@ use cuprate_rpc_types::{
|
||||||
};
|
};
|
||||||
use cuprate_types::{rpc::PoolInfoExtent, BlockCompleteEntry};
|
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`].
|
/// Map a [`BinRequest`] to the function that will lead to a [`BinResponse`].
|
||||||
pub(super) async fn map_request(
|
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>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L959-L977>
|
||||||
async fn get_output_indexes(
|
async fn get_output_indexes(
|
||||||
state: CupratedRpcHandler,
|
mut state: CupratedRpcHandler,
|
||||||
request: GetOutputIndexesRequest,
|
request: GetOutputIndexesRequest,
|
||||||
) -> Result<GetOutputIndexesResponse, Error> {
|
) -> Result<GetOutputIndexesResponse, Error> {
|
||||||
let o_indexes = blockchain::tx_output_indexes(&mut state.blockchain_read, request.txid).await?;
|
|
||||||
|
|
||||||
Ok(GetOutputIndexesResponse {
|
Ok(GetOutputIndexesResponse {
|
||||||
base: helper::access_response_base(false),
|
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>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1689-L1711>
|
||||||
async fn get_transaction_pool_hashes(
|
async fn get_transaction_pool_hashes(
|
||||||
state: CupratedRpcHandler,
|
mut state: CupratedRpcHandler,
|
||||||
request: GetTransactionPoolHashesRequest,
|
_: GetTransactionPoolHashesRequest,
|
||||||
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
||||||
Ok(GetTransactionPoolHashesResponse {
|
Ok(GetTransactionPoolHashesResponse {
|
||||||
base: helper::access_response_base(false),
|
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,
|
state: CupratedRpcHandler,
|
||||||
request: GetOutputDistributionRequest,
|
request: GetOutputDistributionRequest,
|
||||||
) -> Result<GetOutputDistributionResponse, Error> {
|
) -> Result<GetOutputDistributionResponse, Error> {
|
||||||
Ok(GetOutputDistributionResponse {
|
shared::get_output_distribution(state, request).await
|
||||||
base: helper::access_response_base(false),
|
|
||||||
..todo!()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ use crate::{
|
||||||
rpc::{
|
rpc::{
|
||||||
helper,
|
helper,
|
||||||
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
||||||
CupratedRpcHandler,
|
shared, CupratedRpcHandler,
|
||||||
},
|
},
|
||||||
statics::START_INSTANT_UNIX,
|
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>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3352-L3398>
|
||||||
async fn get_output_distribution(
|
async fn get_output_distribution(
|
||||||
mut state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: GetOutputDistributionRequest,
|
request: GetOutputDistributionRequest,
|
||||||
) -> Result<GetOutputDistributionResponse, Error> {
|
) -> Result<GetOutputDistributionResponse, Error> {
|
||||||
if state.is_restricted() && request.amounts != [1, 0] {
|
shared::get_output_distribution(state, request).await
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1998-L2033>
|
/// <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,
|
mut state: CupratedRpcHandler,
|
||||||
_: GetTransactionPoolHashesRequest,
|
_: GetTransactionPoolHashesRequest,
|
||||||
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
) -> 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 {
|
Ok(GetTransactionPoolHashesResponse {
|
||||||
base: helper::response_base(false),
|
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
|
let BlockchainResponse::TxOutputIndexes(o_indexes) = blockchain_read
|
||||||
.ready()
|
.ready()
|
||||||
.await?
|
.await?
|
||||||
.call(BlockchainReadRequest::TxOutputIndexes(tx_hash))
|
.call(BlockchainReadRequest::TxOutputIndexes { tx_hash })
|
||||||
.await?
|
.await?
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
|
|
@ -10,11 +10,19 @@ use cuprate_helper::cast::usize_to_u64;
|
||||||
use cuprate_hex::Hex;
|
use cuprate_hex::Hex;
|
||||||
use cuprate_rpc_interface::RpcHandler;
|
use cuprate_rpc_interface::RpcHandler;
|
||||||
use cuprate_rpc_types::{
|
use cuprate_rpc_types::{
|
||||||
bin::{GetOutsRequest, GetOutsResponse},
|
bin::{
|
||||||
misc::OutKeyBin,
|
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>
|
/// <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?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|(amount, index_map)| {
|
.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),
|
key: out.key.map_or([0; 32], |e| e.compress().0),
|
||||||
mask: out.commitment.compress().0,
|
mask: out.commitment.compress().0,
|
||||||
unlocked: matches!(out.time_lock, Timelock::None),
|
unlocked: matches!(out.time_lock, Timelock::None),
|
||||||
|
@ -63,3 +71,62 @@ pub(super) async fn get_outs(
|
||||||
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