Skip to content

Commit

Permalink
format: rustfmt for incorrect sdk-wallet-force commits
Browse files Browse the repository at this point in the history
  • Loading branch information
juped committed May 18, 2023
1 parent 2bf55e4 commit dc5e8c3
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 22 deletions.
13 changes: 11 additions & 2 deletions apps/src/bin/namada-wallet/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,12 @@ fn address_key_add(
let password = read_and_confirm_pwd(unsafe_dont_encrypt);
let alias = ctx
.wallet
.encrypt_insert_spending_key(alias, spending_key, password, alias_force)
.encrypt_insert_spending_key(
alias,
spending_key,
password,
alias_force,
)
.unwrap_or_else(|| {
eprintln!("Spending key not added");
cli::safe_exit(1);
Expand Down Expand Up @@ -492,7 +497,11 @@ fn address_or_alias_find(ctx: Context, args: args::AddressOrAliasFind) {
fn address_add(ctx: Context, args: args::AddressAdd) {
let mut wallet = ctx.wallet;
if wallet
.add_address(args.alias.clone().to_lowercase(), args.address, args.alias_force)
.add_address(
args.alias.clone().to_lowercase(),
args.address,
args.alias_force,
)
.is_none()
{
eprintln!("Address not added");
Expand Down
6 changes: 5 additions & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3573,7 +3573,11 @@ pub mod args {
let alias = ALIAS.parse(matches);
let alias_force = ALIAS_FORCE.parse(matches);
let address = RAW_ADDRESS.parse(matches);
Self { alias, alias_force, address }
Self {
alias,
alias_force,
address,
}
}

fn def(app: App) -> App {
Expand Down
7 changes: 6 additions & 1 deletion apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ pub async fn submit_init_validator<
println!("Generating validator account key...");
let password = read_and_confirm_pwd(unsafe_dont_encrypt);
ctx.wallet
.gen_key(scheme, Some(validator_key_alias.clone()), password, tx_args.wallet_alias_force)
.gen_key(
scheme,
Some(validator_key_alias.clone()),
password,
tx_args.wallet_alias_force,
)
.1
.ref_to()
});
Expand Down
24 changes: 18 additions & 6 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,12 @@ pub fn init_network(
let alias = format!("{}-consensus-key", name);
println!("Generating validator {} consensus key...", name);
let password = read_and_confirm_pwd(unsafe_dont_encrypt);
let (_alias, keypair) =
wallet.gen_key(SchemeType::Ed25519, Some(alias), password, true);
let (_alias, keypair) = wallet.gen_key(
SchemeType::Ed25519,
Some(alias),
password,
true,
);

// Write consensus key for Tendermint
tendermint_node::write_validator_key(&tm_home_dir, &keypair);
Expand All @@ -519,8 +523,12 @@ pub fn init_network(
let alias = format!("{}-account-key", name);
println!("Generating validator {} account key...", name);
let password = read_and_confirm_pwd(unsafe_dont_encrypt);
let (_alias, keypair) =
wallet.gen_key(SchemeType::Ed25519, Some(alias), password, true);
let (_alias, keypair) = wallet.gen_key(
SchemeType::Ed25519,
Some(alias),
password,
true,
);
keypair.ref_to()
});

Expand All @@ -532,8 +540,12 @@ pub fn init_network(
let alias = format!("{}-protocol-key", name);
println!("Generating validator {} protocol signing key...", name);
let password = read_and_confirm_pwd(unsafe_dont_encrypt);
let (_alias, keypair) =
wallet.gen_key(SchemeType::Ed25519, Some(alias), password, true);
let (_alias, keypair) = wallet.gen_key(
SchemeType::Ed25519,
Some(alias),
password,
true,
);
keypair.ref_to()
});

Expand Down
3 changes: 2 additions & 1 deletion shared/src/ledger/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ pub struct Tx<C: NamadaTypes = SdkTypes> {
/// If any new account is initialized by the tx, use the given alias to
/// save it in the wallet.
pub initialized_account_alias: Option<String>,
/// Whether to force overwrite the above alias, if it is provided, in the wallet.
/// Whether to force overwrite the above alias, if it is provided, in the
/// wallet.
pub wallet_alias_force: bool,
/// The amount being payed to include the transaction
pub fee_amount: token::Amount,
Expand Down
6 changes: 5 additions & 1 deletion shared/src/ledger/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,11 @@ pub async fn save_initialized_accounts<U: WalletUtils>(
None => U::read_alias(&encoded).into(),
};
let alias = alias.into_owned();
let added = wallet.add_address(alias.clone(), address.clone(), args.wallet_alias_force);
let added = wallet.add_address(
alias.clone(),
address.clone(),
args.wallet_alias_force,
);
match added {
Some(new_alias) if new_alias != encoded => {
println!(
Expand Down
15 changes: 12 additions & 3 deletions shared/src/ledger/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ impl<U: WalletUtils> Wallet<U> {
password: Option<String>,
force_alias: bool,
) -> (String, common::SecretKey) {
let (alias, key) = self.store.gen_key::<U>(scheme, alias, password, force_alias);
let (alias, key) =
self.store
.gen_key::<U>(scheme, alias, password, force_alias);
// Cache the newly added key
self.decrypted_key_cache.insert(alias.clone(), key.clone());
(alias.into(), key)
Expand All @@ -125,7 +127,9 @@ impl<U: WalletUtils> Wallet<U> {
password: Option<String>,
force_alias: bool,
) -> (String, ExtendedSpendingKey) {
let (alias, key) = self.store.gen_spending_key::<U>(alias, password, force_alias);
let (alias, key) =
self.store
.gen_spending_key::<U>(alias, password, force_alias);
// Cache the newly added key
self.decrypted_spendkey_cache.insert(alias.clone(), key);
(alias.into(), key)
Expand Down Expand Up @@ -436,7 +440,12 @@ impl<U: WalletUtils> Wallet<U> {
force_alias: bool,
) -> Option<String> {
self.store
.insert_spending_key::<U>(alias.into(), spend_key, viewkey, force_alias)
.insert_spending_key::<U>(
alias.into(),
spend_key,
viewkey,
force_alias,
)
.map(Into::into)
}

Expand Down
32 changes: 25 additions & 7 deletions shared/src/ledger/wallet/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,20 @@ impl Store {
let address = Address::Implicit(ImplicitAddress(pkh.clone()));
let alias: Alias = alias.unwrap_or_else(|| pkh.clone().into()).into();
if self
.insert_keypair::<U>(alias.clone(), keypair_to_store, pkh, force_alias)
.insert_keypair::<U>(
alias.clone(),
keypair_to_store,
pkh,
force_alias,
)
.is_none()
{
panic!("Action cancelled, no changes persisted.");
}
if self.insert_address::<U>(alias.clone(), address, force_alias).is_none() {
if self
.insert_address::<U>(alias.clone(), address, force_alias)
.is_none()
{
panic!("Action cancelled, no changes persisted.");
}
(alias, raw_keypair)
Expand All @@ -263,7 +271,12 @@ impl Store {
StoredKeypair::new(spendkey, password);
let alias = Alias::from(alias);
if self
.insert_spending_key::<U>(alias.clone(), spendkey_to_store, viewkey, force_alias)
.insert_spending_key::<U>(
alias.clone(),
spendkey_to_store,
viewkey,
force_alias,
)
.is_none()
{
panic!("Action cancelled, no changes persisted.");
Expand Down Expand Up @@ -319,7 +332,8 @@ impl Store {
// terminates with a cancellation
counterpart_address
.map(|x| self.addresses.insert(alias.clone(), x.1));
return self.insert_keypair::<U>(new_alias, keypair, pkh, false);
return self
.insert_keypair::<U>(new_alias, keypair, pkh, false);
}
ConfirmationResponse::Skip => {
// Restore the removed address since this insertion action
Expand Down Expand Up @@ -384,7 +398,8 @@ impl Store {
match U::show_overwrite_confirmation(&alias, "a viewing key") {
ConfirmationResponse::Replace => {}
ConfirmationResponse::Reselect(new_alias) => {
return self.insert_viewing_key::<U>(new_alias, viewkey, false);
return self
.insert_viewing_key::<U>(new_alias, viewkey, false);
}
ConfirmationResponse::Skip => return None,
}
Expand Down Expand Up @@ -428,8 +443,11 @@ impl Store {
match U::show_overwrite_confirmation(&alias, "a payment address") {
ConfirmationResponse::Replace => {}
ConfirmationResponse::Reselect(new_alias) => {
return self
.insert_payment_addr::<U>(new_alias, payment_addr, false);
return self.insert_payment_addr::<U>(
new_alias,
payment_addr,
false,
);
}
ConfirmationResponse::Skip => return None,
}
Expand Down

0 comments on commit dc5e8c3

Please sign in to comment.