diff options
author | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-02-25 01:03:10 +0800 |
---|---|---|
committer | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-02-25 01:05:10 +0800 |
commit | 923950ccaaa4f9c1c0cebfbdd99fb0f16c47fd37 (patch) | |
tree | 8b268fcfcf2585c38db00d57b5bf5da4c2040473 | |
parent | 91a8c08f037c1ec737d15ce00c6720015347e0d6 (diff) | |
download | dexon-923950ccaaa4f9c1c0cebfbdd99fb0f16c47fd37.tar.gz dexon-923950ccaaa4f9c1c0cebfbdd99fb0f16c47fd37.tar.zst dexon-923950ccaaa4f9c1c0cebfbdd99fb0f16c47fd37.zip |
Fix key store address hex decoding and accounts test
Thanks to https://github.com/jaekwon for original fix!
-rw-r--r-- | accounts/account_manager.go | 4 | ||||
-rw-r--r-- | accounts/accounts_test.go | 14 | ||||
-rw-r--r-- | crypto/key_store_plain.go | 7 |
3 files changed, 22 insertions, 3 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go index da0bd8900..f7a7506ba 100644 --- a/accounts/account_manager.go +++ b/accounts/account_manager.go @@ -56,6 +56,10 @@ func NewAccountManager(keyStore crypto.KeyStore2) AccountManager { return *am } +func (am AccountManager) DeleteAccount(address []byte, auth string) error { + return am.keyStore.DeleteKey(address, auth) +} + func (am *AccountManager) Sign(fromAccount *Account, keyAuth string, toSign []byte) (signature []byte, err error) { key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth) if err != nil { diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go index 127334404..4e97de545 100644 --- a/accounts/accounts_test.go +++ b/accounts/accounts_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccountManager(t *testing.T) { - ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir()) + ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts") am := NewAccountManager(ks) pass := "" // not used but required by API a1, err := am.NewAccount(pass) @@ -18,4 +18,16 @@ func TestAccountManager(t *testing.T) { if err != nil { t.Fatal(err) } + + // Cleanup + accounts, err := am.Accounts() + if err != nil { + t.Fatal(err) + } + for _, account := range accounts { + err := am.DeleteAccount(account.Address, pass) + if err != nil { + t.Fatal(err) + } + } } diff --git a/crypto/key_store_plain.go b/crypto/key_store_plain.go index 255ae0ed7..338a4a2c3 100644 --- a/crypto/key_store_plain.go +++ b/crypto/key_store_plain.go @@ -119,8 +119,11 @@ func GetKeyAddresses(keysDirPath string) (addresses [][]byte, err error) { } addresses = make([][]byte, len(fileInfos)) for i, fileInfo := range fileInfos { - addresses[i] = make([]byte, 40) - addresses[i] = []byte(fileInfo.Name()) + address, err := hex.DecodeString(fileInfo.Name()) + if err != nil { + continue + } + addresses[i] = address } return addresses, err } |