Make accounts refresh time configurable. (#7345)
* Configurable accounts refresh time. * Fix tests.
This commit is contained in:
committed by
Svyatoslav Nikolsky
parent
276496fb4b
commit
83447c201b
@@ -335,6 +335,10 @@ usage! {
|
||||
"--keys-iterations=[NUM]",
|
||||
"Specify the number of iterations to use when deriving key from the password (bigger is more secure)",
|
||||
|
||||
ARG arg_accounts_refresh: (u64) = 5u64, or |c: &Config| otry!(c.account).refresh_time.clone(),
|
||||
"--accounts-refresh=[TIME]",
|
||||
"Specify the cache time of accounts read from disk. If you manage thousands of accounts set this to 0 to disable refresh.",
|
||||
|
||||
ARG arg_unlock: (Option<String>) = None, or |c: &Config| otry!(c.account).unlock.as_ref().map(|vec| vec.join(",")),
|
||||
"--unlock=[ACCOUNTS]",
|
||||
"Unlock ACCOUNTS for the duration of the execution. ACCOUNTS is a comma-delimited list of addresses. Implies --no-ui.",
|
||||
@@ -1009,6 +1013,7 @@ struct Account {
|
||||
unlock: Option<Vec<String>>,
|
||||
password: Option<Vec<String>>,
|
||||
keys_iterations: Option<u32>,
|
||||
refresh_time: Option<u64>,
|
||||
disable_hardware: Option<bool>,
|
||||
fast_unlock: Option<bool>,
|
||||
}
|
||||
@@ -1428,6 +1433,7 @@ mod tests {
|
||||
arg_unlock: Some("0xdeadbeefcafe0000000000000000000000000000".into()),
|
||||
arg_password: vec!["~/.safe/password.file".into()],
|
||||
arg_keys_iterations: 10240u32,
|
||||
arg_accounts_refresh: 5u64,
|
||||
flag_no_hardware_wallets: false,
|
||||
flag_fast_unlock: false,
|
||||
|
||||
@@ -1665,6 +1671,7 @@ mod tests {
|
||||
unlock: Some(vec!["0x1".into(), "0x2".into(), "0x3".into()]),
|
||||
password: Some(vec!["passwdfile path".into()]),
|
||||
keys_iterations: None,
|
||||
refresh_time: None,
|
||||
disable_hardware: None,
|
||||
fast_unlock: None,
|
||||
}),
|
||||
|
||||
@@ -484,6 +484,7 @@ impl Configuration {
|
||||
fn accounts_config(&self) -> Result<AccountsConfig, String> {
|
||||
let cfg = AccountsConfig {
|
||||
iterations: self.args.arg_keys_iterations,
|
||||
refresh_time: self.args.arg_accounts_refresh,
|
||||
testnet: self.args.flag_testnet,
|
||||
password_files: self.args.arg_password.clone(),
|
||||
unlocked_accounts: to_addresses(&self.args.arg_unlock)?,
|
||||
|
||||
@@ -188,6 +188,7 @@ impl str::FromStr for ResealPolicy {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct AccountsConfig {
|
||||
pub iterations: u32,
|
||||
pub refresh_time: u64,
|
||||
pub testnet: bool,
|
||||
pub password_files: Vec<String>,
|
||||
pub unlocked_accounts: Vec<Address>,
|
||||
@@ -199,6 +200,7 @@ impl Default for AccountsConfig {
|
||||
fn default() -> Self {
|
||||
AccountsConfig {
|
||||
iterations: 10240,
|
||||
refresh_time: 5,
|
||||
testnet: false,
|
||||
password_files: Vec::new(),
|
||||
unlocked_accounts: Vec::new(),
|
||||
|
||||
@@ -909,9 +909,15 @@ fn prepare_account_provider(spec: &SpecType, dirs: &Directories, data_dir: &str,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
let ethstore = EthStore::open_with_iterations(dir, cfg.iterations).map_err(|e| format!("Could not open keys directory: {}", e))?;
|
||||
if cfg.refresh_time > 0 {
|
||||
ethstore.set_refresh_time(::std::time::Duration::from_secs(cfg.refresh_time));
|
||||
}
|
||||
let account_provider = AccountProvider::new(
|
||||
Box::new(EthStore::open_with_iterations(dir, cfg.iterations).map_err(|e| format!("Could not open keys directory: {}", e))?),
|
||||
account_settings);
|
||||
Box::new(ethstore),
|
||||
account_settings,
|
||||
);
|
||||
|
||||
for a in cfg.unlocked_accounts {
|
||||
// Check if the account exists
|
||||
|
||||
Reference in New Issue
Block a user