mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-27 12:55:59 +00:00
key_image_spent
This commit is contained in:
parent
1aca03d319
commit
0ab7fe1c46
4 changed files with 63 additions and 9 deletions
|
@ -130,6 +130,24 @@ pub(super) async fn block_hash(
|
|||
Ok(hash)
|
||||
}
|
||||
|
||||
/// [`BlockchainResponse::KeyImageSpent`]
|
||||
pub(super) async fn key_image_spent(
|
||||
state: &mut CupratedRpcHandlerState,
|
||||
key_image: [u8; 32],
|
||||
) -> Result<bool, Error> {
|
||||
let BlockchainResponse::KeyImageSpent(is_spent) = state
|
||||
.blockchain
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::KeyImageSpent(key_image))
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(is_spent)
|
||||
}
|
||||
|
||||
// FindBlock([u8; 32]),
|
||||
// FilterUnknownHashes(HashSet<[u8; 32]>),
|
||||
// BlockExtendedHeaderInRange(Range<usize>, Chain),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use cuprate_rpc_types::misc::BlockHeader;
|
||||
use cuprate_rpc_types::misc::{BlockHeader, KeyImageSpentStatus};
|
||||
use futures::StreamExt;
|
||||
use tower::{Service, ServiceExt};
|
||||
|
||||
|
@ -97,3 +97,17 @@ pub(super) async fn top_height(
|
|||
let height = chain_height.saturating_sub(1);
|
||||
Ok((height, hash))
|
||||
}
|
||||
|
||||
/// TODO
|
||||
pub(super) async fn key_image_spent(
|
||||
state: &mut CupratedRpcHandlerState,
|
||||
key_image: [u8; 32],
|
||||
) -> Result<KeyImageSpentStatus, Error> {
|
||||
if blockchain::key_image_spent(state, key_image).await? {
|
||||
Ok(KeyImageSpentStatus::SpentInBlockchain)
|
||||
} else if todo!("key image is spent in tx pool") {
|
||||
Ok(KeyImageSpentStatus::SpentInPool)
|
||||
} else {
|
||||
Ok(KeyImageSpentStatus::Unspent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -486,7 +486,8 @@ async fn relay_tx(
|
|||
state: CupratedRpcHandlerState,
|
||||
request: RelayTxRequest,
|
||||
) -> Result<RelayTxResponse, Error> {
|
||||
Ok(RelayTxResponse { status: todo!() })
|
||||
todo!();
|
||||
Ok(RelayTxResponse { status: Status::Ok })
|
||||
}
|
||||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3306-L3330>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use anyhow::Error;
|
||||
use anyhow::{anyhow, Error};
|
||||
|
||||
use cuprate_rpc_types::{
|
||||
base::{AccessResponseBase, ResponseBase},
|
||||
misc::Status,
|
||||
misc::{KeyImageSpentStatus, Status},
|
||||
other::{
|
||||
GetAltBlocksHashesRequest, GetAltBlocksHashesResponse, GetHeightRequest, GetHeightResponse,
|
||||
GetLimitRequest, GetLimitResponse, GetNetStatsRequest, GetNetStatsResponse, GetOutsRequest,
|
||||
|
@ -22,7 +22,12 @@ use cuprate_rpc_types::{
|
|||
},
|
||||
};
|
||||
|
||||
use crate::rpc::CupratedRpcHandlerState;
|
||||
use crate::{
|
||||
rpc::CupratedRpcHandlerState,
|
||||
rpc::{blockchain, helper},
|
||||
};
|
||||
|
||||
use super::RESTRICTED_SPENT_KEY_IMAGES_COUNT;
|
||||
|
||||
/// Map a [`OtherRequest`] to the function that will lead to a [`OtherResponse`].
|
||||
pub(super) async fn map_request(
|
||||
|
@ -77,12 +82,16 @@ pub(super) async fn map_request(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L486-L499>
|
||||
async fn get_height(
|
||||
state: CupratedRpcHandlerState,
|
||||
mut state: CupratedRpcHandlerState,
|
||||
request: GetHeightRequest,
|
||||
) -> Result<GetHeightResponse, Error> {
|
||||
let (height, hash) = helper::top_height(&mut state).await?;
|
||||
let hash = hex::encode(hash);
|
||||
|
||||
Ok(GetHeightResponse {
|
||||
base: ResponseBase::ok(),
|
||||
..todo!()
|
||||
height,
|
||||
hash,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -110,12 +119,24 @@ async fn get_alt_blocks_hashes(
|
|||
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1229-L1305>
|
||||
async fn is_key_image_spent(
|
||||
state: CupratedRpcHandlerState,
|
||||
mut state: CupratedRpcHandlerState,
|
||||
request: IsKeyImageSpentRequest,
|
||||
) -> Result<IsKeyImageSpentResponse, Error> {
|
||||
if state.restricted && request.key_images.len() > RESTRICTED_SPENT_KEY_IMAGES_COUNT {
|
||||
return Err(anyhow!("Too many key images queried in restricted mode"));
|
||||
}
|
||||
|
||||
let mut spent_status = Vec::with_capacity(request.key_images.len());
|
||||
|
||||
for hex in request.key_images {
|
||||
let key_image = helper::hex_to_hash(hex)?;
|
||||
let status = helper::key_image_spent(&mut state, key_image).await?;
|
||||
spent_status.push(status.to_u8());
|
||||
}
|
||||
|
||||
Ok(IsKeyImageSpentResponse {
|
||||
base: AccessResponseBase::ok(),
|
||||
..todo!()
|
||||
spent_status,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue