Skip to content

Commit

Permalink
Working Nimbus branch with geth keystore
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropombeiro committed Jan 20, 2020
1 parent d4710fa commit 93975aa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 50 deletions.
2 changes: 0 additions & 2 deletions account/accounts_geth.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !nimbus

package account

import (
Expand Down
16 changes: 8 additions & 8 deletions account/accounts_nimbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func NewNimbusManager() *NimbusManager {
return m
}

// InitKeystore sets key manager and key store.
func (m *Manager) InitKeystore(keydir string) error {
m.mu.Lock()
defer m.mu.Unlock()
// // InitKeystore sets key manager and key store.
// func (m *Manager) InitKeystore(keydir string) error {
// m.mu.Lock()
// defer m.mu.Unlock()

var err error
m.keystore, err = makeKeyStore(keydir)
return err
}
// var err error
// m.keystore, err = makeKeyStore(keydir)
// return err
// }
78 changes: 38 additions & 40 deletions account/keystore_nimbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,47 @@
package account

import (
// "io/ioutil"
// "os"
"io/ioutil"
"os"

// gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
nimbusbridge "github.com/status-im/status-go/eth-node/bridge/nimbus"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"

gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
// nimbusbridge "github.com/status-im/status-go/eth-node/bridge/nimbus"
"github.com/status-im/status-go/eth-node/types"
)

// // makeAccountManager creates ethereum accounts.Manager with single disk backend and lightweight kdf.
// // If keydir is empty new temporary directory with go-ethereum-keystore will be intialized.
// func makeAccountManager(keydir string) (manager *accounts.Manager, err error) {
// if keydir == "" {
// // There is no datadir.
// keydir, err = ioutil.TempDir("", "nimbus-keystore")
// }
// if err != nil {
// return nil, err
// }
// if err := os.MkdirAll(keydir, 0700); err != nil {
// return nil, err
// }
// config := accounts.Config{InsecureUnlockAllowed: false}
// return accounts.NewManager(&config, keystore.NewKeyStore(keydir, keystore.LightScryptN, keystore.LightScryptP)), nil
// }

// func makeKeyStore(keydir string) (types.KeyStore, error) {
// manager, err := makeAccountManager(keydir)
// if err != nil {
// return err
// }

// backends := manager.Backends(keystore.KeyStoreType)
// if len(backends) == 0 {
// return nil, ErrAccountKeyStoreMissing
// }
// keyStore, ok := backends[0].(*keystore.KeyStore)
// if !ok {
// return nil, ErrAccountKeyStoreMissing
// }

// return gethbridge.WrapKeyStore(keyStore), nil
// }
// makeAccountManager creates ethereum accounts.Manager with single disk backend and lightweight kdf.
// If keydir is empty new temporary directory with go-ethereum-keystore will be intialized.
func makeAccountManager(keydir string) (manager *accounts.Manager, err error) {
if keydir == "" {
// There is no datadir.
keydir, err = ioutil.TempDir("", "nimbus-keystore")
}
if err != nil {
return nil, err
}
if err := os.MkdirAll(keydir, 0700); err != nil {
return nil, err
}
config := accounts.Config{InsecureUnlockAllowed: false}
return accounts.NewManager(&config, keystore.NewKeyStore(keydir, keystore.LightScryptN, keystore.LightScryptP)), nil
}

func makeKeyStore(_ string) (types.KeyStore, error) {
return nimbusbridge.WrapKeyStore(), nil
func makeKeyStore(manager *accounts.Manager) (types.KeyStore, error) {
backends := manager.Backends(keystore.KeyStoreType)
if len(backends) == 0 {
return nil, ErrAccountKeyStoreMissing
}
keyStore, ok := backends[0].(*keystore.KeyStore)
if !ok {
return nil, ErrAccountKeyStoreMissing
}

return gethbridge.WrapKeyStore(keyStore), nil
}

// func makeKeyStore(_ string) (types.KeyStore, error) {
// return nimbusbridge.WrapKeyStore(), nil
// }

0 comments on commit 93975aa

Please sign in to comment.