This commit is contained in:
Jae Kwon 2015-02-24 16:28:29 +00:00
commit c95e7d2554
3 changed files with 28 additions and 3 deletions

View file

@ -76,6 +76,10 @@ func (am AccountManager) NewAccount(auth string) (*Account, error) {
return ua, err return ua, err
} }
func (am AccountManager) DeleteAccount(address []byte, auth string) error {
return am.keyStore.DeleteKey(address, auth)
}
// set of accounts == set of keys in given key store // set of accounts == set of keys in given key store
// TODO: do we need persistence of accounts as well? // TODO: do we need persistence of accounts as well?
func (am *AccountManager) Accounts() ([]Account, error) { func (am *AccountManager) Accounts() ([]Account, error) {

View file

@ -8,13 +8,31 @@ import (
) )
func TestAccountManager(t *testing.T) { func TestAccountManager(t *testing.T) {
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir())
// Get AccountManager
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir() + "/testaccounts")
am := NewAccountManager(ks) am := NewAccountManager(ks)
// Create a new account
pass := "" // not used but required by API pass := "" // not used but required by API
a1, err := am.NewAccount(pass) a1, err := am.NewAccount(pass)
// Sign junk
toSign := randentropy.GetEntropyCSPRNG(32) toSign := randentropy.GetEntropyCSPRNG(32)
_, err = am.Sign(a1, pass, toSign) _, err = am.Sign(a1, pass, toSign)
if err != nil { if err != nil {
t.Fatal(err) 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)
}
}
} }

View file

@ -126,8 +126,11 @@ func GetKeyAddresses(keysDirPath string) (addresses [][]byte, err error) {
} }
addresses = make([][]byte, len(fileInfos)) addresses = make([][]byte, len(fileInfos))
for i, fileInfo := range fileInfos { for i, fileInfo := range fileInfos {
addresses[i] = make([]byte, 40) address, err := hex.DecodeString(fileInfo.Name())
addresses[i] = []byte(fileInfo.Name()) if err != nil {
continue
}
addresses[i] = address
} }
return addresses, err return addresses, err
} }