From 8cd319cc4550aa8bbb550ee5e693d3a0c6dfebf4 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 16 Dec 2024 20:30:52 -0500 Subject: [PATCH] `/get_o_indexes.bin` --- binaries/cuprated/src/rpc/bin.rs | 4 +++- binaries/cuprated/src/rpc/request/blockchain.rs | 17 +++++++++++++++++ storage/blockchain/src/service/read.rs | 13 +++++++++++++ types/types/src/blockchain.rs | 6 ++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/binaries/cuprated/src/rpc/bin.rs b/binaries/cuprated/src/rpc/bin.rs index 80bfec9..3cd4c94 100644 --- a/binaries/cuprated/src/rpc/bin.rs +++ b/binaries/cuprated/src/rpc/bin.rs @@ -182,9 +182,11 @@ async fn get_output_indexes( state: CupratedRpcHandler, request: GetOutputIndexesRequest, ) -> Result { + 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, }) } diff --git a/binaries/cuprated/src/rpc/request/blockchain.rs b/binaries/cuprated/src/rpc/request/blockchain.rs index 58ee1b5..0d9c9fd 100644 --- a/binaries/cuprated/src/rpc/request/blockchain.rs +++ b/binaries/cuprated/src/rpc/request/blockchain.rs @@ -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, Error> { + let BlockchainResponse::TxOutputIndexes(o_indexes) = blockchain_read + .ready() + .await? + .call(BlockchainReadRequest::TxOutputIndexes(tx_hash)) + .await? + else { + unreachable!(); + }; + + Ok(o_indexes) +} diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index 6ef5a85..67a0cd4 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -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::(&tx_ro)?.get(tx_hash)?; + let o_indexes = env_inner.open_db_ro::(&tx_ro)?.get(&tx_id)?; + + Ok(BlockchainResponse::TxOutputIndexes(o_indexes.0)) +} diff --git a/types/types/src/blockchain.rs b/types/types/src/blockchain.rs index 089f4df..6ae7bf2 100644 --- a/types/types/src/blockchain.rs +++ b/types/types/src/blockchain.rs @@ -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), + //------------------------------------------------------ Writes /// A generic Ok response to indicate a request was successfully handled. ///