2018-05-03 10:36:56 +00:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-01-18 09:01:14 +00:00
|
|
|
"github.com/status-im/status-go/account"
|
2020-12-09 14:36:40 +00:00
|
|
|
"github.com/status-im/status-go/account/generator"
|
2019-12-19 18:27:27 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2018-05-03 10:36:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Make sure that Service implements node.Service interface.
|
|
|
|
var _ node.Service = (*Service)(nil)
|
|
|
|
|
|
|
|
// WhisperService whisper interface to add key pairs
|
|
|
|
type WhisperService interface {
|
|
|
|
AddKeyPair(key *ecdsa.PrivateKey) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccountManager interface to manage account actions
|
|
|
|
type AccountManager interface {
|
2019-12-19 18:27:27 +00:00
|
|
|
AddressToDecryptedAccount(string, string) (types.Account, *types.Key, error)
|
2019-07-26 14:45:10 +00:00
|
|
|
SelectAccount(account.LoginParams) error
|
2020-12-09 14:36:40 +00:00
|
|
|
CreateAccount(password string) (mkInfo generator.IdentifiedAccountInfo, accountInfo account.Info, mnemonic string, err error)
|
2018-05-03 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 13:27:17 +00:00
|
|
|
// Service represents our own implementation of status status operations.
|
2018-05-03 10:36:56 +00:00
|
|
|
type Service struct {
|
|
|
|
am AccountManager
|
|
|
|
w WhisperService
|
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a new Service.
|
|
|
|
func New(w WhisperService) *Service {
|
|
|
|
return &Service{w: w}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocols returns a new protocols list. In this case, there are none.
|
|
|
|
func (s *Service) Protocols() []p2p.Protocol {
|
|
|
|
return []p2p.Protocol{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// APIs returns a list of new APIs.
|
|
|
|
func (s *Service) APIs() []rpc.API {
|
|
|
|
|
|
|
|
return []rpc.API{
|
|
|
|
{
|
|
|
|
Namespace: "status",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: NewAPI(s),
|
|
|
|
Public: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAccountManager sets account manager for the API calls.
|
|
|
|
func (s *Service) SetAccountManager(a AccountManager) {
|
|
|
|
s.am = a
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start is run when a service is started.
|
|
|
|
// It does nothing in this case but is required by `node.Service` interface.
|
|
|
|
func (s *Service) Start(server *p2p.Server) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop is run when a service is stopped.
|
|
|
|
// It does nothing in this case but is required by `node.Service` interface.
|
|
|
|
func (s *Service) Stop() error {
|
|
|
|
return nil
|
|
|
|
}
|