Skip to content

Commit

Permalink
feat: derive and cache some accounts with forc-wallet import
Browse files Browse the repository at this point in the history
  • Loading branch information
kayagokalp committed Jun 11, 2024
1 parent 2c157b1 commit 43bccb1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/import.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::utils::{
ensure_no_wallet_exists, request_new_password, write_wallet_from_mnemonic_and_password,
use crate::{
account::derive_and_cache_addresses,
utils::{
ensure_no_wallet_exists, load_wallet, request_new_password,
write_wallet_from_mnemonic_and_password,
},
DEFAULT_CACHE_ACCOUNTS,
};
use anyhow::{bail, Result};
use clap::Args;
Expand All @@ -11,6 +16,9 @@ pub struct Import {
/// Forces wallet creation, removing any existing wallet file
#[clap(short, long)]
force: bool,
/// How many accounts to cache by default (Default 10)
#[clap(short, long)]
pub cache_accounts: Option<usize>,
}

/// Check if given mnemonic is valid by trying to create a `WalletUnlocked` from it
Expand All @@ -29,6 +37,11 @@ pub fn import_wallet_cli(wallet_path: &Path, import: Import) -> Result<()> {
check_mnemonic(&mnemonic)?;
let password = request_new_password();
write_wallet_from_mnemonic_and_password(wallet_path, &mnemonic, &password)?;
derive_and_cache_addresses(
&load_wallet(wallet_path)?,
&mnemonic,
0..import.cache_accounts.unwrap_or(DEFAULT_CACHE_ACCOUNTS),
)?;
Ok(())
}

Expand Down

0 comments on commit 43bccb1

Please sign in to comment.