Skip to content

Commit

Permalink
Make fmt happy
Browse files Browse the repository at this point in the history
  • Loading branch information
George Danezis committed Feb 8, 2022
1 parent 6cccdef commit 795e7fd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 91 deletions.
69 changes: 34 additions & 35 deletions fastpay_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use typed_store::rocks::open_cf;
use typed_store::Map;

use std::path::{Path, PathBuf};
use std::time::Duration;
use std::{
collections::{BTreeMap, BTreeSet, HashSet},
pin::Pin,
};
use std::time::Duration;

/// a Trait object for `signature::Signer` that is:
/// - Pin, i.e. confined to one place in memory (we don't want to copy private keys).
Expand All @@ -29,7 +29,6 @@ use std::time::Duration;
///
pub type StableSyncSigner = Pin<Box<dyn signature::Signer<ed25519_dalek::Signature> + Send + Sync>>;


pub mod client_store;
use self::client_store::ClientStore;

Expand Down Expand Up @@ -375,47 +374,47 @@ where
cert: CertifiedOrder,
effects: OrderEffects,
) -> Result<(CertifiedOrder, OrderEffects), FastPayError> {
// The cert should be included in the response
let parent_tx_digest = cert.order.digest();
self.store.certificates.insert(&parent_tx_digest, &cert)?;
// The cert should be included in the response
let parent_tx_digest = cert.order.digest();
self.store.certificates.insert(&parent_tx_digest, &cert)?;

let mut objs_to_download = Vec::new();
let mut objs_to_download = Vec::new();

for &(object_ref, owner) in effects.all_mutated() {
let (object_id, seq, _) = object_ref;
let old_seq = self
.store
.object_sequence_numbers
.get(&object_id)?
.unwrap_or_default();
// only update if data is new
if old_seq < seq {
if owner.is_address(&self.address) {
self.insert_object_info(&object_ref, &parent_tx_digest)?;
objs_to_download.push(object_ref);
} else {
self.remove_object_info(&object_id)?;
}
} else if old_seq == seq && owner.is_address(&self.address) {
// ObjectRef can be 1 version behind because it's only updated after confirmation.
self.store.object_refs.insert(&object_id, &object_ref)?;
let (object_id, seq, _) = object_ref;
let old_seq = self
.store
.object_sequence_numbers
.get(&object_id)?
.unwrap_or_default();
// only update if data is new
if old_seq < seq {
if owner.is_address(&self.address) {
self.insert_object_info(&object_ref, &parent_tx_digest)?;
objs_to_download.push(object_ref);
} else {
self.remove_object_info(&object_id)?;
}
} else if old_seq == seq && owner.is_address(&self.address) {
// ObjectRef can be 1 version behind because it's only updated after confirmation.
self.store.object_refs.insert(&object_id, &object_ref)?;
}
}

// TODO: decide what to do with failed object downloads
// https://github.com/MystenLabs/fastnft/issues/331
let _failed = self.download_objects_not_in_db(objs_to_download).await?;
// TODO: decide what to do with failed object downloads
// https://github.com/MystenLabs/fastnft/issues/331
let _failed = self.download_objects_not_in_db(objs_to_download).await?;

for (object_id, seq, _) in &effects.deleted {
let old_seq = self
.store
.object_sequence_numbers
.get(object_id)?
.unwrap_or_default();
if old_seq < *seq {
self.remove_object_info(object_id)?;
}
let old_seq = self
.store
.object_sequence_numbers
.get(object_id)?
.unwrap_or_default();
if old_seq < *seq {
self.remove_object_info(object_id)?;
}
}
Ok((cert, effects))
}

Expand Down Expand Up @@ -505,7 +504,7 @@ where
}

Ok((certificate, effects))
}
}

async fn try_complete_pending_orders(&mut self) -> Result<(), FastPayError> {
// Orders are idempotent so no need to prevent multiple executions
Expand Down
112 changes: 56 additions & 56 deletions fastpay_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,39 +978,39 @@ async fn test_move_calls_object_transfer_and_freeze() {
let (_, order_effects) = call_response.unwrap();
// Get the object created from the call
let (new_obj_ref, _) = order_effects.created[0];
// Fetch the full object
let new_obj = client1
.get_object_info(ObjectInfoRequest {
object_id: new_obj_ref.0,
request_sequence_number: None,
})
.await
.unwrap();
// Fetch the full object
let new_obj = client1
.get_object_info(ObjectInfoRequest {
object_id: new_obj_ref.0,
request_sequence_number: None,
})
.await
.unwrap();

gas_object_ref = client1
.get_object_info(ObjectInfoRequest {
object_id: gas_object_ref.0,
request_sequence_number: None,
})
.await
.unwrap()
.object()
.unwrap()
.to_object_reference();
gas_object_ref = client1
.get_object_info(ObjectInfoRequest {
object_id: gas_object_ref.0,
request_sequence_number: None,
})
.await
.unwrap()
.object()
.unwrap()
.to_object_reference();

let pure_args = vec![bcs::to_bytes(&client2.address().to_vec()).unwrap()];
let call_response = client1
.move_call(
framework_obj_ref,
ident_str!("ObjectBasics").to_owned(),
.move_call(
framework_obj_ref,
ident_str!("ObjectBasics").to_owned(),
ident_str!("transfer_and_freeze").to_owned(),
Vec::new(),
gas_object_ref,
vec![new_obj.object().unwrap().to_object_reference()],
pure_args,
GAS_VALUE_FOR_TESTING / 2,
)
.await;
Vec::new(),
gas_object_ref,
vec![new_obj.object().unwrap().to_object_reference()],
pure_args,
GAS_VALUE_FOR_TESTING / 2,
)
.await;

// Check effects are good
let (_, order_effects) = call_response.unwrap();
Expand Down Expand Up @@ -1088,38 +1088,38 @@ async fn test_move_calls_object_delete() {
let (_, order_effects) = call_response.unwrap();
// Get the object created from the call
let (new_obj_ref, _) = order_effects.created[0];
// Fetch the full object
let new_obj = client1
.get_object_info(ObjectInfoRequest {
object_id: new_obj_ref.0,
request_sequence_number: None,
})
.await
.unwrap();
// Fetch the full object
let new_obj = client1
.get_object_info(ObjectInfoRequest {
object_id: new_obj_ref.0,
request_sequence_number: None,
})
.await
.unwrap();

gas_object_ref = client1
.get_object_info(ObjectInfoRequest {
object_id: gas_object_ref.0,
request_sequence_number: None,
})
.await
.unwrap()
.object()
.unwrap()
.to_object_reference();
gas_object_ref = client1
.get_object_info(ObjectInfoRequest {
object_id: gas_object_ref.0,
request_sequence_number: None,
})
.await
.unwrap()
.object()
.unwrap()
.to_object_reference();

let call_response = client1
.move_call(
framework_obj_ref,
ident_str!("ObjectBasics").to_owned(),
.move_call(
framework_obj_ref,
ident_str!("ObjectBasics").to_owned(),
ident_str!("delete").to_owned(),
Vec::new(),
gas_object_ref,
vec![new_obj.object().unwrap().to_object_reference()],
Vec::new(),
GAS_VALUE_FOR_TESTING / 2,
)
.await;
gas_object_ref,
vec![new_obj.object().unwrap().to_object_reference()],
Vec::new(),
GAS_VALUE_FOR_TESTING / 2,
)
.await;

// Check effects are good
let (_, order_effects) = call_response.unwrap();
Expand Down Expand Up @@ -1161,7 +1161,7 @@ async fn test_module_publish_and_call_good() {
.await
.iter()
.next()
.unwrap()
.unwrap()
.1
.to_object_reference();

Expand Down

0 comments on commit 795e7fd

Please sign in to comment.