mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-23 03:51:09 +00:00
accounts order by keyfile ctime
This commit is contained in:
parent
eb82ca4563
commit
a4df9d74ea
@ -9,6 +9,7 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@ -20,8 +21,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/rpc/comms"
|
||||
"github.com/ethereum/go-ethereum/rpc/codec"
|
||||
"github.com/ethereum/go-ethereum/rpc/comms"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -141,7 +142,6 @@ func TestAccounts(t *testing.T) {
|
||||
|
||||
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`"]`)
|
||||
checkEvalJSON(t, repl, `eth.coinbase`, `null`)
|
||||
|
||||
val, err := repl.re.Run(`personal.newAccount("password")`)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
@ -151,7 +151,7 @@ func TestAccounts(t *testing.T) {
|
||||
t.Errorf("address not hex: %q", addr)
|
||||
}
|
||||
|
||||
// checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`", "`+addr+`"]`)
|
||||
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`","`+addr+`"]`)
|
||||
}
|
||||
|
||||
func TestBlockChain(t *testing.T) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user