Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: derive and cache some accounts with forc-wallet import #187

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading