@@ -277,92 +277,89 @@ fn deserialize_response(response: &[u8]) -> Option<AccountInfoResponse> {
277
277
}
278
278
}
279
279
280
-
281
280
#[ 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
+ ) ]
283
285
struct ClientOpt {
284
286
/// Sets the file storing the state of our user accounts (an empty one will be created if missing)
285
287
#[ structopt( long = "accounts" ) ]
286
- accounts : String ,
288
+ accounts : String ,
287
289
288
290
/// Sets the file describing the public configurations of all authorities
289
291
#[ structopt( long = "committee" ) ]
290
- committee : String ,
292
+ committee : String ,
291
293
292
294
/// Timeout for sending queries (us)
293
295
#[ structopt( long = "send_timeout" , default_value = "4000000" ) ]
294
- send_timeout : u64 ,
296
+ send_timeout : u64 ,
295
297
296
298
/// Timeout for receiving responses (us)
297
299
#[ structopt( long = "recv_timeout" , default_value = "4000000" ) ]
298
- recv_timeout : u64 ,
300
+ recv_timeout : u64 ,
299
301
300
302
/// Maximum size of datagrams received and sent (bytes)
301
303
#[ structopt( long = "buffer_size" , default_value = transport:: DEFAULT_MAX_DATAGRAM_SIZE ) ]
302
- buffer_size : String ,
304
+ buffer_size : String ,
303
305
304
306
/// Subcommands. Acceptable values are transfer, query_balance, benchmark, and create_accounts.
305
307
#[ structopt( subcommand) ]
306
- cmd : ClientCommands
307
-
308
+ cmd : ClientCommands ,
308
309
}
309
310
310
311
#[ derive( StructOpt ) ]
311
312
enum ClientCommands {
312
-
313
313
/// Transfer funds
314
314
#[ structopt( name = "transfer" ) ]
315
315
Transfer {
316
-
317
316
/// Sending address (must be one of our accounts)
318
317
#[ structopt( long = "from" ) ]
319
- from : String ,
318
+ from : String ,
320
319
321
320
/// Recipient address
322
321
#[ structopt( long = "to" ) ]
323
- to : String ,
322
+ to : String ,
324
323
325
324
/// Amount to transfer
326
- amount : u64
325
+ amount : u64 ,
327
326
} ,
328
327
329
328
/// Obtain the spendable balance
330
329
#[ structopt( name = "query_balance" ) ]
331
330
QueryBalance {
332
331
/// Address of the account
333
- address : String
332
+ address : String ,
334
333
} ,
335
334
336
335
/// Send one transfer per account in bulk mode
337
336
#[ structopt( name = "benchmark" ) ]
338
337
Benchmark {
339
338
/// Maximum number of requests in flight
340
339
#[ structopt( long = "max_in_flight" , default_value = "200" ) ]
341
- max_in_flight : u64 ,
340
+ max_in_flight : u64 ,
342
341
343
342
/// Use a subset of the accounts to generate N transfers
344
343
#[ structopt( long = "max_orders" , default_value = "" ) ]
345
- max_orders : String ,
344
+ max_orders : String ,
346
345
347
346
/// Use server configuration files to generate certificates (instead of aggregating received votes).
348
347
#[ structopt( long = "server_configs" , min_values = 1 ) ]
349
- server_configs : Vec < String >
348
+ server_configs : Vec < String > ,
350
349
} ,
351
350
352
351
/// Create new user accounts and print the public keys
353
352
#[ structopt( name = "create_accounts" ) ]
354
353
CreateAccounts {
355
354
/// known initial balance of the account
356
355
#[ structopt( long = "initial_funding" , default_value = "0" ) ]
357
- initial_funding : i128 ,
356
+ initial_funding : i128 ,
358
357
359
358
/// Number of additional accounts to create
360
- num : u32
361
- }
362
-
359
+ num : u32 ,
360
+ } ,
363
361
}
364
362
365
-
366
363
fn main ( ) {
367
364
env_logger:: from_env ( env_logger:: Env :: default ( ) . default_filter_or ( "info" ) ) . init ( ) ;
368
365
let matches = ClientOpt :: from_args ( ) ;
@@ -373,11 +370,10 @@ fn main() {
373
370
let committee_config_path = & matches. committee ;
374
371
let buffer_size = matches. buffer_size . parse :: < usize > ( ) . unwrap ( ) ;
375
372
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" ) ;
381
377
382
378
match matches. cmd {
383
379
ClientCommands :: Transfer { from, to, amount } => {
@@ -424,7 +420,7 @@ fn main() {
424
420
. expect ( "Unable to write user accounts" ) ;
425
421
info ! ( "Saved user account states" ) ;
426
422
} ) ;
427
- } ,
423
+ }
428
424
429
425
ClientCommands :: QueryBalance { address } => {
430
426
let user_address = decode_address ( & address) . expect ( "Failed to decode address" ) ;
@@ -451,11 +447,17 @@ fn main() {
451
447
. expect ( "Unable to write user accounts" ) ;
452
448
info ! ( "Saved client account state" ) ;
453
449
} ) ;
454
- } ,
450
+ }
455
451
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 ( ) ;
459
461
let parsed_server_configs = Some ( files) ;
460
462
461
463
let mut rt = Runtime :: new ( ) . unwrap ( ) ;
@@ -523,10 +525,12 @@ fn main() {
523
525
. expect ( "Unable to write user accounts" ) ;
524
526
info ! ( "Saved client account state" ) ;
525
527
} ) ;
528
+ }
526
529
527
- } ,
528
-
529
- ClientCommands :: CreateAccounts { initial_funding, num } => {
530
+ ClientCommands :: CreateAccounts {
531
+ initial_funding,
532
+ num,
533
+ } => {
530
534
let num_accounts: u32 = num;
531
535
for _ in 0 ..num_accounts {
532
536
let account = UserAccount :: new ( Balance :: from ( initial_funding) ) ;
@@ -536,7 +540,6 @@ fn main() {
536
540
accounts_config
537
541
. write ( accounts_config_path)
538
542
. expect ( "Unable to write user accounts" ) ;
539
-
540
543
}
541
544
}
542
- }
545
+ }
0 commit comments