diff --git a/README.md b/README.md index 5d32b8e4dfaf0..510bd34ea5365 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ done # * Private account states are stored in one local wallet `accounts.json`. # * `initial_accounts.toml` is used to mint the corresponding initially randomly generated (for now) objects at startup on the server side. ./client --committee committee.json --accounts accounts.json create-accounts --num 100 \ ---gas-objs-per-account 10 --value-per-per-obj 2000000 initial_accounts.toml +--gas-objs-per-account 10 --value-per-obj 2000000 initial_accounts.toml # Start servers for I in 1 2 3 4 do diff --git a/fastpay/src/client.rs b/fastpay/src/client.rs index 9e5e30c792b0f..dac7293368d5b 100644 --- a/fastpay/src/client.rs +++ b/fastpay/src/client.rs @@ -282,9 +282,9 @@ fn mass_update_recipients( } } -fn deserialize_response(response: &[u8]) -> Option { +fn deserialize_response(response: &[u8]) -> Option { match deserialize_message(response) { - Ok(SerializedMessage::ObjectInfoResp(info)) => Some(*info), + Ok(SerializedMessage::OrderResp(info)) => Some(*info), Ok(SerializedMessage::Error(error)) => { error!("Received error value: {}", error); None @@ -455,8 +455,7 @@ enum ClientCommands { /// Gas value per object #[structopt(long, default_value = "1000")] - #[allow(dead_code)] - value_per_per_obj: u32, + value_per_obj: u64, /// Initial state config file path #[structopt(name = "init-state-cfg")] @@ -771,8 +770,7 @@ fn main() { let votes: Vec<_> = responses .into_iter() .filter_map(|buf| { - deserialize_response(&buf[..]) - .and_then(|info| info.object_and_lock.unwrap().lock) + deserialize_response(&buf[..]).and_then(|info| info.signed_order) }) .collect(); info!("Received {} valid votes.", votes.len()); @@ -801,11 +799,14 @@ fn main() { responses .iter() .fold(0, |acc, buf| match deserialize_response(&buf[..]) { - Some(info) => { - confirmed.insert(info.object().unwrap().id()); + Some(OrderInfoResponse { + signed_order: Some(order), + .. + }) => { + confirmed.insert(*order.order.object_id()); acc + 1 } - None => acc, + _ => acc, }); warn!( "Received {} valid confirmations for {} transfers.", @@ -828,31 +829,34 @@ fn main() { num, gas_objs_per_account, // TODO: Integrate gas logic with https://github.com/MystenLabs/fastnft/pull/97 - value_per_per_obj: _, + value_per_obj, initial_state_config_path, } => { - let num_accounts: u32 = num; + let num_of_addresses: u32 = num; let mut init_state_cfg: InitialStateConfig = InitialStateConfig::new(); - for _ in 0..num_accounts { + for _ in 0..num_of_addresses { + let (address, key) = get_key_pair(); + let mut objects = Vec::new(); let mut object_refs = Vec::new(); let mut gas_object_ids = Vec::new(); for _ in 0..gas_objs_per_account { let object = Object::with_id_owner_gas_for_testing( ObjectID::random(), SequenceNumber::default(), - FastPayAddress::random_for_testing_only(), - 100000, + address, + value_per_obj, ); object_refs.push(object.to_object_reference()); - gas_object_ids.push(object.id()) + gas_object_ids.push(object.id()); + objects.push(object) } - let account = UserAccount::new(object_refs.clone(), gas_object_ids); + let account = UserAccount::new(address, key, object_refs, gas_object_ids); init_state_cfg.config.push(InitialStateConfigEntry { address: account.address, - object_refs, + objects, }); accounts_config.insert(account); diff --git a/fastpay/src/config.rs b/fastpay/src/config.rs index 20909c1310992..f26476e4e649e 100644 --- a/fastpay/src/config.rs +++ b/fastpay/src/config.rs @@ -7,6 +7,7 @@ use fastx_types::{ messages::{CertifiedOrder, OrderKind}, }; +use fastx_types::object::Object; use move_core_types::language_storage::TypeTag; use move_core_types::{identifier::Identifier, transaction_argument::TransactionArgument}; use serde::{Deserialize, Serialize}; @@ -17,6 +18,7 @@ use std::{ io::{BufReader, BufWriter, Write}, iter::FromIterator, }; + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AuthorityConfig { #[serde( @@ -107,8 +109,12 @@ pub struct UserAccount { } impl UserAccount { - pub fn new(object_refs: Vec, gas_object_ids: Vec) -> Self { - let (address, key) = get_key_pair(); + pub fn new( + address: FastPayAddress, + key: KeyPair, + object_refs: Vec, + gas_object_ids: Vec, + ) -> Self { let object_refs = object_refs .into_iter() .map(|object_ref| (object_ref.0, object_ref)) @@ -273,7 +279,7 @@ impl AccountsConfig { #[derive(Serialize, Deserialize)] pub struct InitialStateConfigEntry { pub address: FastPayAddress, - pub object_refs: Vec, + pub objects: Vec, } #[derive(Serialize, Deserialize)] pub struct InitialStateConfig { @@ -288,11 +294,11 @@ impl InitialStateConfig { pub fn read(path: &str) -> Result { let raw_data: String = read_to_string(path)?.parse()?; - Ok(toml::from_str(&raw_data)?) + Ok(serde_json::from_str(&raw_data)?) } pub fn write(&self, path: &str) -> Result<(), std::io::Error> { - let config = toml::to_string(self).unwrap(); + let config = serde_json::to_string(self).unwrap(); fs::write(path, config).expect("Unable to write to initial config file"); Ok(()) diff --git a/fastpay/src/server.rs b/fastpay/src/server.rs index 80c27010933c7..884e7c2e773a5 100644 --- a/fastpay/src/server.rs +++ b/fastpay/src/server.rs @@ -6,7 +6,7 @@ use fastpay::config::*; use fastpay_core::{authority::*, authority_server::AuthorityServer}; use fastx_network::transport; -use fastx_types::{base_types::*, committee::Committee, object::Object}; +use fastx_types::{base_types::*, committee::Committee}; use futures::future::join_all; use std::path::Path; @@ -50,11 +50,8 @@ fn make_server( store, ) .await; - for initial_state_cfg_entry in &initial_accounts_config.config { - let address = &initial_state_cfg_entry.address; - for (object_id, _, _) in &initial_state_cfg_entry.object_refs { - let object = Object::with_id_owner_for_testing(*object_id, *address); - + for initial_state_cfg_entry in initial_accounts_config.config { + for object in initial_state_cfg_entry.objects { state.init_order_lock(object.to_object_reference()).await; state.insert_object(object).await; }