2019-12-19 19:27:27 +01:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
2023-03-10 13:53:40 +01:00
|
|
|
"time"
|
|
|
|
|
2019-12-19 19:27:27 +01:00
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
2020-01-02 10:10:19 +01:00
|
|
|
|
2019-12-19 19:27:27 +01:00
|
|
|
"github.com/status-im/status-go/account/generator"
|
2023-03-10 13:53:40 +01:00
|
|
|
"github.com/status-im/status-go/rpc"
|
2019-12-19 19:27:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// GethManager represents account manager interface.
|
|
|
|
type GethManager struct {
|
2023-06-21 16:13:31 +04:00
|
|
|
*DefaultManager
|
2019-12-19 19:27:27 +01:00
|
|
|
|
2019-12-30 10:43:51 +01:00
|
|
|
gethAccManager *accounts.Manager
|
2019-12-19 19:27:27 +01:00
|
|
|
}
|
|
|
|
|
2019-11-27 13:22:23 +01:00
|
|
|
// NewGethManager returns new node account manager.
|
|
|
|
func NewGethManager() *GethManager {
|
2019-12-19 19:27:27 +01:00
|
|
|
m := &GethManager{}
|
2023-06-21 16:13:31 +04:00
|
|
|
m.DefaultManager = &DefaultManager{accountsGenerator: generator.New(m)}
|
2019-12-19 19:27:27 +01:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:53:40 +01:00
|
|
|
func (m *GethManager) SetRPCClient(rpcClient *rpc.Client, rpcTimeout time.Duration) {
|
2023-06-21 16:13:31 +04:00
|
|
|
m.DefaultManager.rpcClient = rpcClient
|
|
|
|
m.DefaultManager.rpcTimeout = rpcTimeout
|
2023-03-10 13:53:40 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 19:27:27 +01:00
|
|
|
// InitKeystore sets key manager and key store.
|
|
|
|
func (m *GethManager) InitKeystore(keydir string) error {
|
|
|
|
m.mu.Lock()
|
|
|
|
defer m.mu.Unlock()
|
|
|
|
|
|
|
|
var err error
|
2019-12-30 10:43:51 +01:00
|
|
|
m.gethAccManager, err = makeAccountManager(keydir)
|
2019-12-19 19:27:27 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-24 12:57:45 +02:00
|
|
|
|
2019-12-30 10:43:51 +01:00
|
|
|
m.keystore, err = makeKeyStore(m.gethAccManager)
|
2023-02-11 12:14:20 +01:00
|
|
|
m.Keydir = keydir
|
2019-12-19 19:27:27 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *GethManager) GetManager() *accounts.Manager {
|
|
|
|
m.mu.RLock()
|
|
|
|
defer m.mu.RUnlock()
|
2019-12-30 10:43:51 +01:00
|
|
|
return m.gethAccManager
|
2019-12-19 19:27:27 +01:00
|
|
|
}
|