/get_o_indexes.bin

This commit is contained in:
hinto.janai 2024-12-16 20:30:52 -05:00
parent 541302ea07
commit 8cd319cc45
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
4 changed files with 39 additions and 1 deletions

View file

@ -182,9 +182,11 @@ async fn get_output_indexes(
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),
..todo!()
o_indexes,
})
}

View file

@ -429,3 +429,20 @@ pub(crate) async fn block_complete_entries_by_height(
Ok(blocks)
}
/// [`BlockchainReadRequest::TxOutputIndexes`].
pub(crate) async fn tx_output_indexes(
blockchain_read: &mut BlockchainReadHandle,
tx_hash: [u8; 32],
) -> Result<Vec<u64>, Error> {
let BlockchainResponse::TxOutputIndexes(o_indexes) = blockchain_read
.ready()
.await?
.call(BlockchainReadRequest::TxOutputIndexes(tx_hash))
.await?
else {
unreachable!();
};
Ok(o_indexes)
}

View file

@ -54,6 +54,7 @@ use crate::{
},
tables::{
AltBlockHeights, BlockHeights, BlockInfos, OpenTables, RctOutputs, Tables, TablesIter,
TxIds, TxOutputs,
},
types::{
AltBlockHeight, Amount, AmountIndex, BlockHash, BlockHeight, KeyImage, PreRctOutputId,
@ -140,6 +141,7 @@ fn map_request(
R::AltChainCount => alt_chain_count(env),
R::Transactions { tx_hashes } => transactions(env, tx_hashes),
R::TotalRctOutputs => total_rct_outputs(env),
R::TxOutputIndexes { tx_hash } => tx_output_indexes(env, &tx_hash),
}
/* SOMEDAY: post-request handling, run some code for each request? */
@ -820,3 +822,14 @@ fn total_rct_outputs(env: &ConcreteEnv) -> ResponseResult {
Ok(BlockchainResponse::TotalRctOutputs(len))
}
/// [`BlockchainReadRequest::TxOutputIndexes`]
fn tx_output_indexes(env: &ConcreteEnv, tx_hash: &[u8; 32]) -> ResponseResult {
// Single-threaded, no `ThreadLocal` required.
let env_inner = env.env_inner();
let tx_ro = env_inner.tx_ro()?;
let tx_id = env_inner.open_db_ro::<TxIds>(&tx_ro)?.get(tx_hash)?;
let o_indexes = env_inner.open_db_ro::<TxOutputs>(&tx_ro)?.get(&tx_id)?;
Ok(BlockchainResponse::TxOutputIndexes(o_indexes.0))
}

View file

@ -171,6 +171,9 @@ pub enum BlockchainReadRequest {
/// TODO
TotalRctOutputs,
/// TODO
TxOutputIndexes { tx_hash: [u8; 32] },
}
//---------------------------------------------------------------------------------------------------- WriteRequest
@ -372,6 +375,9 @@ pub enum BlockchainResponse {
/// Response to [`BlockchainReadRequest::TotalRctOutputs`].
TotalRctOutputs(u64),
/// Response to [`BlockchainReadRequest::TxOutputIndexes`].
TxOutputIndexes(Vec<u64>),
//------------------------------------------------------ Writes
/// A generic Ok response to indicate a request was successfully handled.
///