|
|
|
@ -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) |
|
|
|
|
sort.Sort(accountsByURL(err.Matches)) |
|
|
|
|
slices.SortFunc(err.Matches, byURL) |
|
|
|
|
return accounts.Account{}, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|