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
311b742c
Unverified
Commit
311b742c
authored
Jun 19, 2023
by
Dan Laine
Committed by
GitHub
Jun 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/keystore: use slices package for sorting (#27485)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
f0b5af74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
11 deletions
+11
-11
account_cache.go
accounts/keystore/account_cache.go
+7
-7
account_cache_test.go
accounts/keystore/account_cache_test.go
+2
-2
keystore_test.go
accounts/keystore/keystore_test.go
+2
-2
No files found.
accounts/keystore/account_cache.go
View file @
311b742c
...
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/exp/slices"
)
// Minimum amount of time between cache reloads. This limit applies if the platform does
...
...
@@ -38,11 +39,10 @@ import (
// exist yet, the code will attempt to create a watcher at most this often.
const
minReloadInterval
=
2
*
time
.
Second
type
accountsByURL
[]
accounts
.
Account
func
(
s
accountsByURL
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
accountsByURL
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
.
URL
.
Cmp
(
s
[
j
]
.
URL
)
<
0
}
func
(
s
accountsByURL
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
// byURL defines the sorting order for accounts.
func
byURL
(
a
,
b
accounts
.
Account
)
bool
{
return
a
.
URL
.
Cmp
(
b
.
URL
)
<
0
}
// AmbiguousAddrError is returned when attempting to unlock
// an address for which more than one file exists.
...
...
@@ -67,7 +67,7 @@ type accountCache struct {
keydir
string
watcher
*
watcher
mu
sync
.
Mutex
all
accountsByURL
all
[]
accounts
.
Account
byAddr
map
[
common
.
Address
][]
accounts
.
Account
throttle
*
time
.
Timer
notify
chan
struct
{}
...
...
@@ -194,7 +194,7 @@ func (ac *accountCache) find(a accounts.Account) (accounts.Account, error) {
default
:
err
:=
&
AmbiguousAddrError
{
Addr
:
a
.
Address
,
Matches
:
make
([]
accounts
.
Account
,
len
(
matches
))}
copy
(
err
.
Matches
,
matches
)
s
ort
.
Sort
(
accountsByURL
(
err
.
Matches
)
)
s
lices
.
SortFunc
(
err
.
Matches
,
byURL
)
return
accounts
.
Account
{},
err
}
}
...
...
accounts/keystore/account_cache_test.go
View file @
311b742c
...
...
@@ -23,7 +23,6 @@ import (
"os"
"path/filepath"
"reflect"
"sort"
"testing"
"time"
...
...
@@ -31,6 +30,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/exp/slices"
)
var
(
...
...
@@ -203,7 +203,7 @@ func TestCacheAddDeleteOrder(t *testing.T) {
// Check that the account list is sorted by filename.
wantAccounts
:=
make
([]
accounts
.
Account
,
len
(
accs
))
copy
(
wantAccounts
,
accs
)
s
ort
.
Sort
(
accountsByURL
(
wantAccounts
)
)
s
lices
.
SortFunc
(
wantAccounts
,
byURL
)
list
:=
cache
.
accounts
()
if
!
reflect
.
DeepEqual
(
list
,
wantAccounts
)
{
t
.
Fatalf
(
"got accounts: %s
\n
want %s"
,
spew
.
Sdump
(
accs
),
spew
.
Sdump
(
wantAccounts
))
...
...
accounts/keystore/keystore_test.go
View file @
311b742c
...
...
@@ -20,7 +20,6 @@ import (
"math/rand"
"os"
"runtime"
"sort"
"strings"
"sync"
"sync/atomic"
...
...
@@ -31,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event"
"golang.org/x/exp/slices"
)
var
testSigData
=
make
([]
byte
,
32
)
...
...
@@ -424,7 +424,7 @@ func checkAccounts(t *testing.T, live map[common.Address]accounts.Account, walle
for
_
,
account
:=
range
live
{
liveList
=
append
(
liveList
,
account
)
}
s
ort
.
Sort
(
accountsByURL
(
liveList
)
)
s
lices
.
SortFunc
(
liveList
,
byURL
)
for
j
,
wallet
:=
range
wallets
{
if
accs
:=
wallet
.
Accounts
();
len
(
accs
)
!=
1
{
t
.
Errorf
(
"wallet %d: contains invalid number of accounts: have %d, want 1"
,
j
,
len
(
accs
))
...
...
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