Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityblast committed Jul 19, 2019
1 parent 21253fb commit b54000d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion account/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ func (m *Manager) Logout() {
m.selectedChatAccount = nil
}

func (m *Manager) ImportNormalAccount(privateKey *ecdsa.PrivateKey, password string) (common.Address, error) {
// ImportAccount imports the account specified with privateKey.
func (m *Manager) ImportAccount(privateKey *ecdsa.PrivateKey, password string) (common.Address, error) {
keyStore, err := m.geth.AccountKeyStore()
if err != nil {
return common.Address{}, err
Expand Down
13 changes: 12 additions & 1 deletion services/statusaccounts/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"sync"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/crypto"
Expand All @@ -21,6 +22,7 @@ var (
type generator struct {
am *staccount.Manager
accounts map[string]*account
sync.Mutex
}

func newGenerator() *generator {
Expand Down Expand Up @@ -256,7 +258,7 @@ func (g *generator) store(acc *account, password string) (AccountInfo, error) {
return AccountInfo{}, err
}
} else {
if _, err := g.am.ImportNormalAccount(acc.privateKey, password); err != nil {
if _, err := g.am.ImportAccount(acc.privateKey, password); err != nil {
return AccountInfo{}, err
}
}
Expand All @@ -267,6 +269,9 @@ func (g *generator) store(acc *account, password string) (AccountInfo, error) {
}

func (g *generator) addAccount(acc *account) string {
g.Lock()
defer g.Unlock()

id := uuid.NewRandom().String()
g.accounts[id] = acc

Expand All @@ -275,10 +280,16 @@ func (g *generator) addAccount(acc *account) string {

// Reset resets the accounts map removing all the accounts from memory.
func (g *generator) Reset() {
g.Lock()
defer g.Unlock()

g.accounts = make(map[string]*account)
}

func (g *generator) findAccount(accountID string) (*account, error) {
g.Lock()
defer g.Unlock()

acc, ok := g.accounts[accountID]
if !ok {
return nil, errAccountNotFoundByID
Expand Down
6 changes: 4 additions & 2 deletions services/statusaccounts/path_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func newPathDecoder(path string) (*pathDecoder, error) {
r: strings.NewReader(path),
}

err := d.reset()
if err := d.reset(); err != nil {
return nil, err
}

return d, err
return d, nil
}

func (d *pathDecoder) reset() error {
Expand Down
4 changes: 2 additions & 2 deletions t/e2e/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *AccountsTestSuite) TestImportSingleExtendedKey() {
s.Equal(crypto.FromECDSA(key.PrivateKey), crypto.FromECDSA(key.ExtendedKey.ToECDSA()))
}

func (s *AccountsTestSuite) TestImportNormalAccount() {
func (s *AccountsTestSuite) TestImportAccount() {
s.StartTestBackend()
defer s.StopTestBackend()

Expand All @@ -125,7 +125,7 @@ func (s *AccountsTestSuite) TestImportNormalAccount() {

// import as normal account
password := "test-password-2"
addr, err := s.Backend.AccountManager().ImportNormalAccount(privateKey, password)
addr, err := s.Backend.AccountManager().ImportAccount(privateKey, password)
s.Require().NoError(err)

_, key, err := s.Backend.AccountManager().AddressToDecryptedAccount(addr.String(), password)
Expand Down

0 comments on commit b54000d

Please sign in to comment.