Skip to content

Commit

Permalink
cli/client: refactor saving of wallet of custom and transfer tx
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Aug 3, 2023
1 parent 7614463 commit 65a07be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
23 changes: 0 additions & 23 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,7 @@ impl<IO> CliApi<IO> {
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
let dry_run = args.tx.dry_run;
tx::submit_custom(&client, &mut ctx, args).await?;
if !dry_run {
crate::wallet::save(
&ctx.borrow_chain_or_exit().wallet,
)
.unwrap_or_else(|err| eprintln!("{}", err));
} else {
println!(
"Transaction dry run. No addresses have been \
saved."
)
}
}
Sub::TxTransfer(TxTransfer(mut args)) => {
let client = client.unwrap_or_else(|| {
Expand Down Expand Up @@ -102,19 +90,8 @@ impl<IO> CliApi<IO> {
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
let dry_run = args.tx.dry_run;
tx::submit_init_account(&client, &mut ctx, args)
.await?;
if !dry_run {
let chain_ctx = ctx.borrow_chain_or_exit();
crate::wallet::save(&chain_ctx.wallet)
.unwrap_or_else(|err| eprintln!("{}", err));
} else {
println!(
"Transaction dry run. No addresses have been \
saved."
)
}
}
Sub::TxInitValidator(TxInitValidator(mut args)) => {
let client = client.unwrap_or_else(|| {
Expand Down
12 changes: 12 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ where
.await?;
signing::sign_tx(&mut chain_ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut chain_ctx.wallet, &args.tx, tx).await?;
if !args.tx.dry_run {
crate::wallet::save(&chain_ctx.wallet)
.unwrap_or_else(|err| eprintln!("{}", err));
} else {
println!("Transaction dry run. No addresses have been saved.")
}
Ok(())
}

Expand Down Expand Up @@ -127,6 +133,12 @@ where
.await?;
signing::sign_tx(&mut chain_ctx.wallet, &mut tx, &args.tx, &pk).await?;
tx::process_tx(client, &mut chain_ctx.wallet, &args.tx, tx).await?;
if !args.tx.dry_run {
crate::wallet::save(&chain_ctx.wallet)
.unwrap_or_else(|err| eprintln!("{}", err));
} else {
println!("Transaction dry run. No addresses have been saved.")
}
Ok(())
}

Expand Down

0 comments on commit 65a07be

Please sign in to comment.