Skip to content

Commit

Permalink
Merge pull request #355 from TheWaWaR/fix-keystore-cache-inconsistent
Browse files Browse the repository at this point in the history
fix: Fix keystore cache inconsistent
  • Loading branch information
TheWaWaR authored Dec 11, 2020
2 parents 971e19c + b82c4fc commit 7a74490
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ckb-sdk/src/wallet/keystore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl KeyStore {
let abs_path = self.storage.store_key(key.filename(), &key, password)?;
let hash160 = key.hash160().clone();
self.files.insert(hash160.clone(), abs_path);
self.ckb_roots.insert(hash160.clone(), key.ckb_root());
Ok(hash160)
}
pub fn get_accounts(&mut self) -> &HashMap<H160, PathBuf> {
Expand Down Expand Up @@ -294,7 +295,7 @@ impl KeyStore {
}

// NOTE: assume refresh keystore directory is not a hot action
fn refresh_dir(&mut self) -> Result<(), Error> {
pub fn refresh_dir(&mut self) -> Result<(), Error> {
let mut files = HashMap::default();
let mut ckb_roots = HashMap::default();
for entry in fs::read_dir(&self.keys_dir)? {
Expand Down
3 changes: 3 additions & 0 deletions src/subcommands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ impl<'a> CliSubCommand for AccountSubCommand<'a> {
let only_mainnet_address = m.is_present("only-mainnet-address");
let only_testnet_address = m.is_present("only-testnet-address");
let partial_fields = only_mainnet_address || only_testnet_address;
self.key_store
.refresh_dir()
.map_err(|err| err.to_string())?;
let resp = accounts
.into_iter()
.enumerate()
Expand Down

0 comments on commit 7a74490

Please sign in to comment.