Skip to content

Commit

Permalink
Merge branch 'master' into v2.0-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
peilun-conflux committed Sep 16, 2022
2 parents d8c1195 + d3d5ebd commit 5aa9268
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ impl AccountProvider {
&self, account: &StoreAccountRef,
) -> Result<Password, SignError> {
let mut unlocked = self.unlocked.write();
Self::password_with_unlocked(&mut unlocked, account)
}

fn password_with_unlocked(
unlocked: &mut HashMap<StoreAccountRef, AccountData>,
account: &StoreAccountRef,
) -> Result<Password, SignError>
{
let data = unlocked.get(account).ok_or(SignError::NotUnlocked)?.clone();
if let Unlock::OneTime = data.unlock {
unlocked
Expand Down Expand Up @@ -473,14 +481,16 @@ impl AccountProvider {
&self, address: Address, password: Option<Password>, message: Message,
) -> Result<Signature, SignError> {
let account = self.sstore.account_ref(&address)?;
// unlocked must be acquired before unlocked_secrets
let mut unlocked = self.unlocked.write();
match self.unlocked_secrets.read().get(&account) {
Some(secret) => {
Ok(self.sstore.sign_with_secret(&secret, &message)?)
}
None => {
let password = password
.map(Ok)
.unwrap_or_else(|| self.password(&account))?;
let password = password.map(Ok).unwrap_or_else(|| {
Self::password_with_unlocked(&mut unlocked, &account)
})?;
Ok(self.sstore.sign(&account, &password, &message)?)
}
}
Expand Down

0 comments on commit 5aa9268

Please sign in to comment.