aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-06-22 05:17:17 +0800
committerzelig <viktor.tron@gmail.com>2015-07-03 06:29:07 +0800
commita4df9d74eabb3bef8449744c4fe966572586dc39 (patch)
treea04c7871818a855995681b311f918ec522c6ca41 /crypto
parenteb82ca4563cf80bef9b520673d3bd18283da3a1f (diff)
downloaddexon-a4df9d74eabb3bef8449744c4fe966572586dc39.tar
dexon-a4df9d74eabb3bef8449744c4fe966572586dc39.tar.gz
dexon-a4df9d74eabb3bef8449744c4fe966572586dc39.tar.bz2
dexon-a4df9d74eabb3bef8449744c4fe966572586dc39.tar.lz
dexon-a4df9d74eabb3bef8449744c4fe966572586dc39.tar.xz
dexon-a4df9d74eabb3bef8449744c4fe966572586dc39.tar.zst
dexon-a4df9d74eabb3bef8449744c4fe966572586dc39.zip
accounts order by keyfile ctime
Diffstat (limited to 'crypto')
-rw-r--r--crypto/key_store_plain.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/crypto/key_store_plain.go b/crypto/key_store_plain.go
index 6a8afe27d..e3150e9a9 100644
--- a/crypto/key_store_plain.go
+++ b/crypto/key_store_plain.go
@@ -27,11 +27,15 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
- "github.com/ethereum/go-ethereum/common"
"io"
"io/ioutil"
"os"
"path/filepath"
+ "sort"
+ "syscall"
+ "time"
+
+ "github.com/ethereum/go-ethereum/common"
)
// TODO: rename to KeyStore when replacing existing KeyStore
@@ -118,8 +122,15 @@ func GetKeyAddresses(keysDirPath string) (addresses []common.Address, err error)
if err != nil {
return nil, err
}
+ var kfis keyFileInfos
for _, fileInfo := range fileInfos {
- address, err := hex.DecodeString(fileInfo.Name())
+ stat := fileInfo.Sys().(*syscall.Stat_t)
+ ctime := time.Unix(int64(stat.Ctimespec.Sec), int64(stat.Ctimespec.Nsec))
+ kfis = append(kfis, keyFileInfo{fileInfo.Name(), ctime})
+ }
+ sort.Sort(kfis)
+ for _, kfi := range kfis {
+ address, err := hex.DecodeString(kfi.name)
if err != nil {
continue
}
@@ -127,3 +138,15 @@ func GetKeyAddresses(keysDirPath string) (addresses []common.Address, err error)
}
return addresses, err
}
+
+type keyFileInfo struct {
+ name string
+ ctime time.Time
+}
+type keyFileInfos []keyFileInfo
+
+func (a keyFileInfos) Len() int { return len(a) }
+func (a keyFileInfos) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+func (a keyFileInfos) Less(i, j int) bool {
+ return a[i].ctime.Before(a[j].ctime)
+}