Skip to content

Commit

Permalink
[RPC] Fix coin metadata api inefficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Oct 30, 2024
1 parent 818b174 commit 1da5ff1
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/sui-json-rpc/src/coin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ async fn find_package_object_id(
spawn_monitored_task!(async move {
let publish_txn_digest = state.find_publish_txn_digest(package_id)?;

let (_, effect) = state
.get_executed_transaction_and_effects(publish_txn_digest, kv_store)
.await?;
let effect = kv_store.get_fx_by_tx_digest(publish_txn_digest).await?;

for ((id, _, _), _) in effect.created() {
if let Ok(object_read) = state.get_object_read(&id) {
Expand All @@ -290,7 +288,7 @@ async fn find_package_object_id(
}
}
Err(SuiRpcInputError::GenericNotFound(format!(
"Cannot find object [{}] from [{}] package event.",
"Cannot find object with type [{}] from [{}] package created objects.",
object_struct_tag, package_id,
))
.into())
Expand Down Expand Up @@ -1401,18 +1399,18 @@ mod tests {
.expect_find_publish_txn_digest()
.return_once(move |_| Ok(transaction_digest));
mock_state
.expect_get_executed_transaction_and_effects()
.return_once(move |_, _| Ok((create_fake_transaction(), transaction_effects)));
.expect_multi_get()
.return_once(move |_, _, _| Ok((vec![], vec![Some(transaction_effects)], vec![])));

let coin_read_api = CoinReadApi::new_for_tests(Arc::new(mock_state), None);
let response = coin_read_api.get_total_supply(coin_name.clone()).await;

assert!(response.is_err());
let error_result = response.unwrap_err();
let error_object: ErrorObjectOwned = error_result.into();
let expected = expect!["-32602"];
let expected = expect!["-32000"];
expected.assert_eq(&error_object.code().to_string());
let expected = expect!["Cannot find object [0x2::coin::TreasuryCap<0xf::test_coin::TEST_COIN>] from [0x000000000000000000000000000000000000000000000000000000000000000f] package event."];
let expected = expect!["task 1 panicked"];
expected.assert_eq(error_object.message());
}

Expand Down

0 comments on commit 1da5ff1

Please sign in to comment.