Skip to content

Commit 627d09d

Browse files
mahimna-fbma2bd
authored andcommitted
cargo fmt
1 parent c6bddce commit 627d09d

File tree

2 files changed

+75
-60
lines changed

2 files changed

+75
-60
lines changed

rust/fastpay/src/client.rs

+41-38
Original file line numberDiff line numberDiff line change
@@ -277,92 +277,89 @@ fn deserialize_response(response: &[u8]) -> Option<AccountInfoResponse> {
277277
}
278278
}
279279

280-
281280
#[derive(StructOpt)]
282-
#[structopt(name = "FastPay Client", about = "A Byzantine fault tolerant payments sidechain with low-latency finality and high throughput")]
281+
#[structopt(
282+
name = "FastPay Client",
283+
about = "A Byzantine fault tolerant payments sidechain with low-latency finality and high throughput"
284+
)]
283285
struct ClientOpt {
284286
/// Sets the file storing the state of our user accounts (an empty one will be created if missing)
285287
#[structopt(long = "accounts")]
286-
accounts: String,
288+
accounts: String,
287289

288290
/// Sets the file describing the public configurations of all authorities
289291
#[structopt(long = "committee")]
290-
committee: String,
292+
committee: String,
291293

292294
/// Timeout for sending queries (us)
293295
#[structopt(long = "send_timeout", default_value = "4000000")]
294-
send_timeout : u64,
296+
send_timeout: u64,
295297

296298
/// Timeout for receiving responses (us)
297299
#[structopt(long = "recv_timeout", default_value = "4000000")]
298-
recv_timeout : u64,
300+
recv_timeout: u64,
299301

300302
/// Maximum size of datagrams received and sent (bytes)
301303
#[structopt(long = "buffer_size", default_value = transport::DEFAULT_MAX_DATAGRAM_SIZE)]
302-
buffer_size : String,
304+
buffer_size: String,
303305

304306
/// Subcommands. Acceptable values are transfer, query_balance, benchmark, and create_accounts.
305307
#[structopt(subcommand)]
306-
cmd : ClientCommands
307-
308+
cmd: ClientCommands,
308309
}
309310

310311
#[derive(StructOpt)]
311312
enum ClientCommands {
312-
313313
/// Transfer funds
314314
#[structopt(name = "transfer")]
315315
Transfer {
316-
317316
/// Sending address (must be one of our accounts)
318317
#[structopt(long = "from")]
319-
from : String,
318+
from: String,
320319

321320
/// Recipient address
322321
#[structopt(long = "to")]
323-
to : String,
322+
to: String,
324323

325324
/// Amount to transfer
326-
amount : u64
325+
amount: u64,
327326
},
328327

329328
/// Obtain the spendable balance
330329
#[structopt(name = "query_balance")]
331330
QueryBalance {
332331
/// Address of the account
333-
address : String
332+
address: String,
334333
},
335334

336335
/// Send one transfer per account in bulk mode
337336
#[structopt(name = "benchmark")]
338337
Benchmark {
339338
/// Maximum number of requests in flight
340339
#[structopt(long = "max_in_flight", default_value = "200")]
341-
max_in_flight : u64,
340+
max_in_flight: u64,
342341

343342
/// Use a subset of the accounts to generate N transfers
344343
#[structopt(long = "max_orders", default_value = "")]
345-
max_orders : String,
344+
max_orders: String,
346345

347346
/// Use server configuration files to generate certificates (instead of aggregating received votes).
348347
#[structopt(long = "server_configs", min_values = 1)]
349-
server_configs : Vec<String>
348+
server_configs: Vec<String>,
350349
},
351350

352351
/// Create new user accounts and print the public keys
353352
#[structopt(name = "create_accounts")]
354353
CreateAccounts {
355354
/// known initial balance of the account
356355
#[structopt(long = "initial_funding", default_value = "0")]
357-
initial_funding : i128,
356+
initial_funding: i128,
358357

359358
/// Number of additional accounts to create
360-
num : u32
361-
}
362-
359+
num: u32,
360+
},
363361
}
364362

365-
366363
fn main() {
367364
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
368365
let matches = ClientOpt::from_args();
@@ -373,11 +370,10 @@ fn main() {
373370
let committee_config_path = &matches.committee;
374371
let buffer_size = matches.buffer_size.parse::<usize>().unwrap();
375372

376-
let mut accounts_config =
377-
AccountsConfig::read_or_create(&accounts_config_path).expect("Unable to read user accounts");
378-
let committee_config =
379-
CommitteeConfig::read(&committee_config_path).expect("Unable to read committee config file");
380-
373+
let mut accounts_config = AccountsConfig::read_or_create(&accounts_config_path)
374+
.expect("Unable to read user accounts");
375+
let committee_config = CommitteeConfig::read(&committee_config_path)
376+
.expect("Unable to read committee config file");
381377

382378
match matches.cmd {
383379
ClientCommands::Transfer { from, to, amount } => {
@@ -424,7 +420,7 @@ fn main() {
424420
.expect("Unable to write user accounts");
425421
info!("Saved user account states");
426422
});
427-
},
423+
}
428424

429425
ClientCommands::QueryBalance { address } => {
430426
let user_address = decode_address(&address).expect("Failed to decode address");
@@ -451,11 +447,17 @@ fn main() {
451447
.expect("Unable to write user accounts");
452448
info!("Saved client account state");
453449
});
454-
},
450+
}
455451

456-
ClientCommands::Benchmark { max_in_flight, max_orders, server_configs} => {
457-
let max_orders: usize = max_orders.parse().unwrap_or_else(|_| accounts_config.num_accounts());
458-
let files : Vec<_> = server_configs.iter().map(AsRef::as_ref).collect();
452+
ClientCommands::Benchmark {
453+
max_in_flight,
454+
max_orders,
455+
server_configs,
456+
} => {
457+
let max_orders: usize = max_orders
458+
.parse()
459+
.unwrap_or_else(|_| accounts_config.num_accounts());
460+
let files: Vec<_> = server_configs.iter().map(AsRef::as_ref).collect();
459461
let parsed_server_configs = Some(files);
460462

461463
let mut rt = Runtime::new().unwrap();
@@ -523,10 +525,12 @@ fn main() {
523525
.expect("Unable to write user accounts");
524526
info!("Saved client account state");
525527
});
528+
}
526529

527-
},
528-
529-
ClientCommands::CreateAccounts { initial_funding, num } => {
530+
ClientCommands::CreateAccounts {
531+
initial_funding,
532+
num,
533+
} => {
530534
let num_accounts: u32 = num;
531535
for _ in 0..num_accounts {
532536
let account = UserAccount::new(Balance::from(initial_funding));
@@ -536,7 +540,6 @@ fn main() {
536540
accounts_config
537541
.write(accounts_config_path)
538542
.expect("Unable to write user accounts");
539-
540543
}
541544
}
542-
}
545+
}

rust/fastpay/src/server.rs

+34-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#![deny(warnings)]
55

6-
extern crate clap;
76
extern crate env_logger;
87
extern crate fastpay;
98
extern crate fastpay_core;
@@ -104,17 +103,19 @@ fn make_servers(
104103
servers
105104
}
106105

107-
108106
#[derive(StructOpt)]
109-
#[structopt(name = "FastPay Server", about = "A byzantine fault tolerant payments sidechain with low-latency finality and high throughput")]
107+
#[structopt(
108+
name = "FastPay Server",
109+
about = "A byzantine fault tolerant payments sidechain with low-latency finality and high throughput"
110+
)]
110111
struct ServerOpt {
111112
/// Path to the file containing the server configuration of this FastPay authority (including its secret key)
112113
#[structopt(long = "server")]
113-
server : String,
114+
server: String,
114115

115116
/// Subcommands. Acceptable values are run and generate.
116117
#[structopt(subcommand)]
117-
cmd : ServerCommands
118+
cmd: ServerCommands,
118119
}
119120

120121
#[derive(StructOpt)]
@@ -124,59 +125,65 @@ enum ServerCommands {
124125
Run {
125126
/// Maximum size of datagrams received and sent (bytes)
126127
#[structopt(long = "buffer_size", default_value = transport::DEFAULT_MAX_DATAGRAM_SIZE)]
127-
buffer_size : String,
128+
buffer_size: String,
128129

129130
/// Number of cross shards messages allowed before blocking the main server loop
130131
#[structopt(long = "cross_shard_queue_size", default_value = "1000")]
131-
cross_shard_queue_size : usize,
132+
cross_shard_queue_size: usize,
132133

133134
/// Path to the file containing the public description of all authorities in this FastPay committee
134135
#[structopt(long = "committee")]
135-
committee: String,
136+
committee: String,
136137

137138
/// Path to the file describing the initial user accounts
138139
#[structopt(long = "initial_accounts")]
139-
initial_accounts: String,
140+
initial_accounts: String,
140141

141142
/// Path to the file describing the initial balance of user accounts
142143
#[structopt(long = "initial_balance")]
143-
initial_balance: String,
144+
initial_balance: String,
144145

145146
/// Runs a specific shard (from 0 to shards-1)
146147
#[structopt(long = "shard")]
147-
shard: String,
148+
shard: String,
148149
},
149150

150151
/// Generate a new server configuration and output its public description
151152
#[structopt(name = "generate")]
152153
Generate {
153154
/// Chooses a network protocol between Udp and Tcp
154155
#[structopt(long = "protocol", default_value = "Udp")]
155-
protocol : String,
156+
protocol: String,
156157

157158
/// Sets the public name of the host
158159
#[structopt(long = "host")]
159-
host: String,
160+
host: String,
160161

161162
/// Sets the base port, i.e. the port on which the server listens for the first shard
162163
#[structopt(long = "port")]
163-
port: u32,
164+
port: u32,
164165

165166
/// Number of shards for this authority
166167
#[structopt(long = "shards")]
167-
shards: u32,
168-
169-
}
168+
shards: u32,
169+
},
170170
}
171171

172172
fn main() {
173173
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
174174
let matches = ServerOpt::from_args();
175-
175+
176176
let server_config_path = &matches.server;
177177

178178
match matches.cmd {
179-
ServerCommands::Run { buffer_size, cross_shard_queue_size, committee, initial_accounts, initial_balance, shard } => {
179+
ServerCommands::Run {
180+
buffer_size,
181+
cross_shard_queue_size,
182+
committee,
183+
initial_accounts,
184+
initial_balance,
185+
shard,
186+
} => {
180187
let committee_config_path = &committee;
181188
let initial_accounts_config_path = &initial_accounts;
182189
let initial_balance = Balance::from(initial_balance.parse::<i128>().unwrap());
@@ -228,9 +235,14 @@ fn main() {
228235
});
229236
}
230237
rt.block_on(join_all(handles));
231-
},
238+
}
232239

233-
ServerCommands::Generate { protocol, host, port, shards } => {
240+
ServerCommands::Generate {
241+
protocol,
242+
host,
243+
port,
244+
shards,
245+
} => {
234246
let network_protocol = protocol.parse().unwrap();
235247
let (address, key) = get_key_pair();
236248
let authority = AuthorityConfig {
@@ -245,7 +257,7 @@ fn main() {
245257
.write(server_config_path)
246258
.expect("Unable to write server config file");
247259
info!("Wrote server config file");
248-
server.authority.print();
260+
server.authority.print();
249261
}
250262
}
251263
}

0 commit comments

Comments
 (0)