2019-12-19 18:27:27 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
2023-03-10 12:53:40 +00:00
|
|
|
"time"
|
|
|
|
|
2024-10-28 20:54:17 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2019-12-19 18:27:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-12-19 18:27:27 +00:00
|
|
|
"github.com/status-im/status-go/account/generator"
|
2023-03-10 12:53:40 +00:00
|
|
|
"github.com/status-im/status-go/rpc"
|
2019-12-19 18:27:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GethManager represents account manager interface.
|
|
|
|
type GethManager struct {
|
2023-06-21 12:13:31 +00:00
|
|
|
*DefaultManager
|
2019-12-19 18:27:27 +00:00
|
|
|
|
2019-12-30 09:43:51 +00:00
|
|
|
gethAccManager *accounts.Manager
|
2019-12-19 18:27:27 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 12:22:23 +00:00
|
|
|
// NewGethManager returns new node account manager.
|
2024-10-28 20:54:17 +00:00
|
|
|
func NewGethManager(logger *zap.Logger) *GethManager {
|
2019-12-19 18:27:27 +00:00
|
|
|
m := &GethManager{}
|
2024-10-28 20:54:17 +00:00
|
|
|
m.DefaultManager = &DefaultManager{
|
|
|
|
accountsGenerator: generator.New(m),
|
|
|
|
logger: logger,
|
|
|
|
}
|
2019-12-19 18:27:27 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-03-10 12:53:40 +00:00
|
|
|
func (m *GethManager) SetRPCClient(rpcClient *rpc.Client, rpcTimeout time.Duration) {
|
2023-06-21 12:13:31 +00:00
|
|
|
m.DefaultManager.rpcClient = rpcClient
|
|
|
|
m.DefaultManager.rpcTimeout = rpcTimeout
|
2023-03-10 12:53:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 18:27:27 +00: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 09:43:51 +00:00
|
|
|
m.gethAccManager, err = makeAccountManager(keydir)
|
2019-12-19 18:27:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-24 10:57:45 +00:00
|
|
|
|
2019-12-30 09:43:51 +00:00
|
|
|
m.keystore, err = makeKeyStore(m.gethAccManager)
|
2023-02-11 11:14:20 +00:00
|
|
|
m.Keydir = keydir
|
2019-12-19 18:27:27 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *GethManager) GetManager() *accounts.Manager {
|
|
|
|
m.mu.RLock()
|
|
|
|
defer m.mu.RUnlock()
|
2019-12-30 09:43:51 +00:00
|
|
|
return m.gethAccManager
|
2019-12-19 18:27:27 +00:00
|
|
|
}
|