Skip to content

Commit

Permalink
Remove try_get_object_before_version
Browse files Browse the repository at this point in the history
  • Loading branch information
bingyanglin committed Nov 1, 2024
1 parent 7e9e00d commit a069036
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 128 deletions.
8 changes: 0 additions & 8 deletions crates/iota-indexer/src/apis/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,6 @@ impl<T: R2D2Connection + 'static> ReadApiServer for ReadApi<T> {
Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into())
}

async fn try_get_object_before_version(
&self,
_: ObjectID,
_: SequenceNumber,
) -> RpcResult<IotaPastObjectResponse> {
Err(jsonrpsee::types::error::ErrorCode::MethodNotFound.into())
}

async fn try_multi_get_past_objects(
&self,
_past_objects: Vec<IotaGetPastObjectRequest>,
Expand Down
14 changes: 0 additions & 14 deletions crates/iota-json-rpc-api/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,6 @@ pub trait ReadApi {
options: Option<IotaObjectDataOptions>,
) -> RpcResult<IotaPastObjectResponse>;

/// 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<IotaPastObjectResponse>;

/// 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.
Expand Down
71 changes: 0 additions & 71 deletions crates/iota-json-rpc-tests/tests/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
21 changes: 0 additions & 21 deletions crates/iota-json-rpc/src/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IotaPastObjectResponse> {
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,
Expand Down
6 changes: 5 additions & 1 deletion crates/iota-replay/src/data_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/read_api/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down
12 changes: 0 additions & 12 deletions crates/iota-sdk/src/apis/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,16 +717,4 @@ impl ReadApi {
) -> IotaRpcResult<ProtocolConfigResponse> {
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<IotaPastObjectResponse> {
Ok(self
.api
.http
.try_get_object_before_version(object_id, version)
.await?)
}
}

0 comments on commit a069036

Please sign in to comment.