Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
6498df7b
Commit
6498df7b
authored
9 years ago
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts: ensure TimedUnlock does not override indefinite unlock timeout
parent
46df50be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
account_manager.go
accounts/account_manager.go
+14
-8
accounts_test.go
accounts/accounts_test.go
+2
-2
No files found.
accounts/account_manager.go
View file @
6498df7b
...
...
@@ -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
)
}
}
...
...
This diff is collapsed.
Click to expand it.
accounts/accounts_test.go
View file @
6498df7b
...
...
@@ -120,8 +120,8 @@ func TestOverrideUnlock(t *testing.T) {
pass
:=
"foo"
a1
,
err
:=
am
.
NewAccount
(
pass
)
// Unlock indefinitely
if
err
=
am
.
Unlock
(
a1
,
pass
);
err
!=
nil
{
// Unlock indefinitely
.
if
err
=
am
.
TimedUnlock
(
a1
,
pass
,
5
*
time
.
Minute
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment