Skip to content

Commit

Permalink
sync to main
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Mar 1, 2022
1 parent 839c81e commit 13c69dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
47 changes: 24 additions & 23 deletions sui/src/rest_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,20 +522,20 @@ async fn get_objects(
)
})?;

let client_state = match wallet_context.get_or_create_client_state(address) {
Ok(client_state) => client_state,
Err(error) => {
return Err(custom_http_error(
wallet_context
.create_account_state(address)
.map_err(|error| {
custom_http_error(
StatusCode::FAILED_DEPENDENCY,
format!("Could not get or create client state: {error}"),
));
}
};
let object_refs = client_state.object_refs();
)
})?;
let object_refs = wallet_context.address_manager.get_owned_objects(*address);

Ok(HttpResponseOk(GetObjectsResponse {
objects: object_refs
.map(|(_, (object_id, sequence_number, object_digest))| Object {
.iter()
.map(|(object_id, sequence_number, object_digest)| Object {
object_id: object_id.to_string(),
version: format!("{:?}", sequence_number),
object_digest: format!("{:?}", object_digest),
Expand Down Expand Up @@ -629,21 +629,22 @@ async fn object_info(
};

// Fetch the object ref
let client_state = match wallet_context.get_or_create_client_state(&owner) {
Ok(client_state) => client_state,
Err(error) => {
*server_context.wallet_context.lock().unwrap() = Some(wallet_context);
return Err(custom_http_error(
StatusCode::FAILED_DEPENDENCY,
format!(
"Could not get client state for account {:?}: {error}",
owner
),
));
}
};
if let Err(error) = wallet_context.create_account_state(&owner) {
*server_context.wallet_context.lock().unwrap() = Some(wallet_context);
return Err(custom_http_error(
StatusCode::FAILED_DEPENDENCY,
format!(
"Could not get client state for account {:?}: {error}",
owner
),
));
}

let (object, layout) = match client_state.get_object_info(object_id).await {
let (object, layout) = match wallet_context
.address_manager
.get_object_info(object_id)
.await
{
Ok(ObjectRead::Exists(_, object, layout)) => (object, layout),
Ok(ObjectRead::Deleted(_)) => {
*server_context.wallet_context.lock().unwrap() = Some(wallet_context);
Expand Down
4 changes: 2 additions & 2 deletions sui/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ impl WalletCommands {

// TODO: We should ideally fetch the objects from local cache
let mut coins = Vec::new();
for obj in object_refs {
match context.address_manager.get_object_info(obj.0).await? {
for (id, _, _) in object_refs {
match context.address_manager.get_object_info(id).await? {
Exists(_, o, _) => {
if matches!( o.type_(), Some(v) if *v == GasCoin::type_()) {
// Okay to unwrap() since we already checked type
Expand Down

0 comments on commit 13c69dc

Please sign in to comment.