aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/account_manager.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-04-07 23:00:34 +0800
committerFelix Lange <fjl@twurst.com>2016-04-12 21:59:18 +0800
commit6498df7b0290139df57629568d824dfa242900cc (patch)
tree7dce5f0d30ded2da96fc773ce53a1c1bd865d545 /accounts/account_manager.go
parent46df50be181afca503aff4a545e3f322ad04448b (diff)
downloadgo-tangerine-6498df7b0290139df57629568d824dfa242900cc.tar
go-tangerine-6498df7b0290139df57629568d824dfa242900cc.tar.gz
go-tangerine-6498df7b0290139df57629568d824dfa242900cc.tar.bz2
go-tangerine-6498df7b0290139df57629568d824dfa242900cc.tar.lz
go-tangerine-6498df7b0290139df57629568d824dfa242900cc.tar.xz
go-tangerine-6498df7b0290139df57629568d824dfa242900cc.tar.zst
go-tangerine-6498df7b0290139df57629568d824dfa242900cc.zip
accounts: ensure TimedUnlock does not override indefinite unlock timeout
Diffstat (limited to 'accounts/account_manager.go')
-rw-r--r--accounts/account_manager.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index c174eef1e..56499672e 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -164,14 +164,15 @@ func (am *Manager) Lock(addr common.Address) error {
return nil
}
-// TimedUnlock unlocks the given account with. The account
+// TimedUnlock unlocks the given account with the passphrase. The account
// stays unlocked for the duration of timeout. A timeout of 0 unlocks the account
-// until the program exits. The account must match a unique key.
+// until the program exits. The account must match a unique key file.
//
-// If the accout is already unlocked, TimedUnlock extends or shortens
-// the active unlock timeout.
-func (am *Manager) TimedUnlock(a Account, keyAuth string, timeout time.Duration) error {
- _, key, err := am.getDecryptedKey(a, keyAuth)
+// If the account address is already unlocked for a duration, TimedUnlock extends or
+// shortens the active unlock timeout. If the address was previously unlocked
+// indefinitely the timeout is not altered.
+func (am *Manager) TimedUnlock(a Account, passphrase string, timeout time.Duration) error {
+ a, key, err := am.getDecryptedKey(a, passphrase)
if err != nil {
return err
}
@@ -180,8 +181,13 @@ func (am *Manager) TimedUnlock(a Account, keyAuth string, timeout time.Duration)
defer am.mu.Unlock()
u, found := am.unlocked[a.Address]
if found {
- // terminate dropLater for this key to avoid unexpected drops.
- if u.abort != nil {
+ if u.abort == nil {
+ // The address was unlocked indefinitely, so unlocking
+ // it with a timeout would be confusing.
+ zeroKey(key.PrivateKey)
+ return nil
+ } else {
+ // Terminate the expire goroutine and replace it below.
close(u.abort)
}
}