2019-08-20 15:38:40 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
2019-08-28 07:49:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/event"
|
2019-08-20 15:38:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2023-01-06 12:21:14 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2022-06-25 07:20:02 +00:00
|
|
|
"github.com/status-im/status-go/server"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
"github.com/status-im/status-go/account"
|
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-01-24 09:29:18 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2022-07-06 16:12:49 +00:00
|
|
|
"github.com/status-im/status-go/protocol"
|
2019-08-20 15:38:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewService initializes service instance.
|
2022-06-25 07:20:02 +00:00
|
|
|
func NewService(db *accounts.Database, mdb *multiaccounts.Database, manager *account.GethManager, config *params.NodeConfig, feed *event.Feed, mediaServer *server.MediaServer) *Service {
|
|
|
|
return &Service{db, mdb, manager, config, feed, nil, mediaServer}
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Service is a browsers service.
|
|
|
|
type Service struct {
|
2022-08-07 07:35:54 +00:00
|
|
|
db *accounts.Database
|
|
|
|
mdb *multiaccounts.Database
|
|
|
|
manager *account.GethManager
|
|
|
|
config *params.NodeConfig
|
|
|
|
feed *event.Feed
|
|
|
|
messenger *protocol.Messenger
|
2022-06-25 07:20:02 +00:00
|
|
|
mediaServer *server.MediaServer
|
2022-07-06 16:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) Init(messenger *protocol.Messenger) {
|
|
|
|
s.messenger = messenger
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start a service.
|
2021-06-30 11:40:54 +00:00
|
|
|
func (s *Service) Start() error {
|
2022-01-24 09:29:18 +00:00
|
|
|
return s.manager.InitKeystore(s.config.KeyStoreDir)
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop a service.
|
|
|
|
func (s *Service) Stop() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// APIs returns list of available RPC APIs.
|
|
|
|
func (s *Service) APIs() []rpc.API {
|
|
|
|
return []rpc.API{
|
|
|
|
{
|
|
|
|
Namespace: "settings",
|
|
|
|
Version: "0.1.0",
|
2022-08-02 12:56:26 +00:00
|
|
|
Service: NewSettingsAPI(&s.messenger, s.db, s.config),
|
2019-08-20 15:38:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: "accounts",
|
|
|
|
Version: "0.1.0",
|
2022-07-06 16:12:49 +00:00
|
|
|
Service: NewAccountsAPI(s.manager, s.config, s.db, s.feed, &s.messenger),
|
2019-08-20 15:38:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: "multiaccounts",
|
|
|
|
Version: "0.1.0",
|
2022-06-25 07:20:02 +00:00
|
|
|
Service: NewMultiAccountsAPI(s.mdb, s.mediaServer),
|
2019-08-20 15:38:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocols returns list of p2p protocols.
|
|
|
|
func (s *Service) Protocols() []p2p.Protocol {
|
|
|
|
return nil
|
|
|
|
}
|
2023-01-06 12:21:14 +00:00
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
func (s *Service) GetKeypairByKeyUID(keyUID string) (*accounts.Keypair, error) {
|
2023-01-06 12:21:14 +00:00
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
return s.db.GetKeypairByKeyUID(keyUID)
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GetSettings() (settings.Settings, error) {
|
|
|
|
return s.db.GetSettings()
|
|
|
|
}
|
2023-01-11 11:30:54 +00:00
|
|
|
|
|
|
|
func (s *Service) GetMessenger() *protocol.Messenger {
|
|
|
|
return s.messenger
|
|
|
|
}
|