From a069036da3b452edb35a1b2f58259510e463cc7f Mon Sep 17 00:00:00 2001 From: Bing-Yang Lin Date: Fri, 1 Nov 2024 16:39:58 +0800 Subject: [PATCH] Remove try_get_object_before_version --- crates/iota-indexer/src/apis/read_api.rs | 8 --- crates/iota-json-rpc-api/src/read.rs | 14 ---- crates/iota-json-rpc-tests/tests/read_api.rs | 71 ------------------- crates/iota-json-rpc/src/read_api.rs | 21 ------ crates/iota-replay/src/data_fetcher.rs | 6 +- crates/iota-sdk/examples/read_api/read_api.rs | 2 +- crates/iota-sdk/src/apis/read.rs | 12 ---- 7 files changed, 6 insertions(+), 128 deletions(-) diff --git a/crates/iota-indexer/src/apis/read_api.rs b/crates/iota-indexer/src/apis/read_api.rs index 8f3cc82a980..964321ce0d9 100644 --- a/crates/iota-indexer/src/apis/read_api.rs +++ b/crates/iota-indexer/src/apis/read_api.rs @@ -186,14 +186,6 @@ impl ReadApiServer for ReadApi { Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into()) } - async fn try_get_object_before_version( - &self, - _: ObjectID, - _: SequenceNumber, - ) -> RpcResult { - Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into()) - } - async fn try_multi_get_past_objects( &self, _past_objects: Vec, diff --git a/crates/iota-json-rpc-api/src/read.rs b/crates/iota-json-rpc-api/src/read.rs index 4798ae83f5d..c2ce7bd4882 100644 --- a/crates/iota-json-rpc-api/src/read.rs +++ b/crates/iota-json-rpc-api/src/read.rs @@ -83,20 +83,6 @@ pub trait ReadApi { options: Option, ) -> RpcResult; - /// Note there is no software-level guarantee/SLA that objects with past - /// versions can be retrieved by this API, even if the object and - /// version exists/existed. The result may vary across nodes depending - /// on their pruning policies. Returns the latest object information - /// with a version less than or equal to the given version - #[method(name = "tryGetObjectBeforeVersion", deprecated = "true")] - async fn try_get_object_before_version( - &self, - /// the ID of the queried object - object_id: ObjectID, - /// the version of the queried object - version: SequenceNumber, - ) -> RpcResult; - /// Note there is no software-level guarantee/SLA that objects with past versions /// can be retrieved by this API, even if the object and version exists/existed. /// The result may vary across nodes depending on their pruning policies. diff --git a/crates/iota-json-rpc-tests/tests/read_api.rs b/crates/iota-json-rpc-tests/tests/read_api.rs index ac4e8033fe9..41540c4a2c0 100644 --- a/crates/iota-json-rpc-tests/tests/read_api.rs +++ b/crates/iota-json-rpc-tests/tests/read_api.rs @@ -1557,74 +1557,3 @@ async fn try_get_past_object_deleted() { matches!(rpc_past_obj, IotaPastObjectResponse::ObjectDeleted(obj) if obj.object_id == created_object_id && obj.version == seq_num) ); } - -#[sim_test] -async fn try_get_object_before_version() { - let options = IotaObjectDataOptions::bcs_lossless(); - - let cluster = TestClusterBuilder::new().build().await; - let http_client = cluster.rpc_client(); - let address = cluster.get_address_0(); - - let fullnode_objects = cluster - .get_owned_objects(address, Some(options.clone())) - .await - .unwrap(); - - let object = fullnode_objects[0].data.as_ref().unwrap(); - - let rpc_obj_before_ver = http_client - .try_get_object_before_version(object.object_id, object.version) - .await - .unwrap(); - - assert!(rpc_obj_before_ver.matches_response_options(&options)); - assert_eq!(object, rpc_obj_before_ver.object().unwrap()); - - let (object_ids, gas) = get_objects_to_mutate(&cluster, address).await; - - let transaction = cluster - .transfer_object( - address, - address, - object_ids[0], - gas, - Some( - IotaTransactionBlockResponseOptions::default() - .with_effects() - .with_object_changes(), - ), - ) - .await - .unwrap(); - - assert_eq!(transaction.status_ok(), Some(true)); - - let (mutated_obj_id, mutated_obj_version, _) = transaction.mutated_objects().next().unwrap(); - - let rpc_obj_before_ver = http_client - .try_get_object_before_version(mutated_obj_id, mutated_obj_version) - .await - .unwrap(); - - assert!(rpc_obj_before_ver.matches_response_options(&options)); - - let rpc_obj_before_ver_obj = rpc_obj_before_ver.object().unwrap(); - assert_eq!(rpc_obj_before_ver_obj.object_id, mutated_obj_id); - assert_eq!(rpc_obj_before_ver_obj.version, mutated_obj_version); -} - -#[sim_test] -async fn try_get_object_before_version_not_exists() { - let cluster = TestClusterBuilder::new().build().await; - let http_client = cluster.rpc_client(); - - let rpc_obj_before_ver = http_client - .try_get_object_before_version(ObjectID::ZERO, SequenceNumber::from_u64(1)) - .await - .unwrap(); - - assert!( - matches!(rpc_obj_before_ver, IotaPastObjectResponse::ObjectNotExists(ref obj_id) if obj_id == &ObjectID::ZERO) - ); -} diff --git a/crates/iota-json-rpc/src/read_api.rs b/crates/iota-json-rpc/src/read_api.rs index 7fa809d3832..13af051b08f 100644 --- a/crates/iota-json-rpc/src/read_api.rs +++ b/crates/iota-json-rpc/src/read_api.rs @@ -655,27 +655,6 @@ impl ReadApiServer for ReadApi { .await } - #[instrument(skip(self))] - async fn try_get_object_before_version( - &self, - object_id: ObjectID, - version: SequenceNumber, - ) -> RpcResult { - let version = self - .state - .find_object_lt_or_eq_version(&object_id, &version) - .await - .map_err(Error::from)? - .map(|obj| obj.version()) - .unwrap_or_default(); - self.try_get_past_object( - object_id, - version, - Some(IotaObjectDataOptions::bcs_lossless()), - ) - .await - } - #[instrument(skip(self))] async fn try_multi_get_past_objects( &self, diff --git a/crates/iota-replay/src/data_fetcher.rs b/crates/iota-replay/src/data_fetcher.rs index 4bf7a73d398..76999daf40f 100644 --- a/crates/iota-replay/src/data_fetcher.rs +++ b/crates/iota-replay/src/data_fetcher.rs @@ -400,7 +400,11 @@ impl DataFetcher for RemoteFetcher { let response = self .rpc_client .read_api() - .try_get_object_before_version(*object_id, version_upper_bound) + .try_get_parsed_past_object( + *object_id, + version_upper_bound, + IotaObjectDataOptions::bcs_lossless(), + ) .await .map_err(|q| ReplayEngineError::IotaRpcError { err: q.to_string() })?; convert_past_obj_response(response) diff --git a/crates/iota-sdk/examples/read_api/read_api.rs b/crates/iota-sdk/examples/read_api/read_api.rs index 5df36996872..91df1a6d413 100644 --- a/crates/iota-sdk/examples/read_api/read_api.rs +++ b/crates/iota-sdk/examples/read_api/read_api.rs @@ -82,7 +82,7 @@ async fn main() -> Result<(), anyhow::Error> { let past_object = client .read_api() - .try_get_object_before_version(object_id, version) + .try_get_parsed_past_object(object_id, version, IotaObjectDataOptions::bcs_lossless()) .await?; println!(" *** Past Object *** "); println!("{past_object:?}"); diff --git a/crates/iota-sdk/src/apis/read.rs b/crates/iota-sdk/src/apis/read.rs index a334f457137..66a7a1b7ac1 100644 --- a/crates/iota-sdk/src/apis/read.rs +++ b/crates/iota-sdk/src/apis/read.rs @@ -717,16 +717,4 @@ impl ReadApi { ) -> IotaRpcResult { Ok(self.api.http.get_protocol_config(version.into()).await?) } - - pub async fn try_get_object_before_version( - &self, - object_id: ObjectID, - version: SequenceNumber, - ) -> IotaRpcResult { - Ok(self - .api - .http - .try_get_object_before_version(object_id, version) - .await?) - } }