2019-06-14 10:16:30 +00:00
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
2021-09-09 14:28:54 +00:00
|
|
|
"database/sql"
|
2019-06-14 10:16:30 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/event"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2021-09-22 17:49:20 +00:00
|
|
|
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/rpc"
|
2021-09-09 14:28:54 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/transfer"
|
2019-06-14 10:16:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewService initializes service instance.
|
2022-02-16 09:22:19 +00:00
|
|
|
func NewService(db *sql.DB, rpcClient *rpc.Client, accountFeed *event.Feed, openseaAPIKey string) *Service {
|
2021-09-09 14:28:54 +00:00
|
|
|
cryptoOnRampManager := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
|
|
|
dataSourceType: DataSourceStatic,
|
|
|
|
})
|
|
|
|
tokenManager := &TokenManager{db: db}
|
2021-09-10 18:08:22 +00:00
|
|
|
savedAddressesManager := &SavedAddressesManager{db: db}
|
2021-09-09 14:28:54 +00:00
|
|
|
transactionManager := &TransactionManager{db: db}
|
|
|
|
favouriteManager := &FavouriteManager{db: db}
|
2021-09-22 17:49:20 +00:00
|
|
|
transferController := transfer.NewTransferController(db, rpcClient, accountFeed)
|
2021-09-09 14:28:54 +00:00
|
|
|
|
2019-06-14 10:16:30 +00:00
|
|
|
return &Service{
|
2021-09-22 17:49:20 +00:00
|
|
|
rpcClient: rpcClient,
|
2021-09-10 18:08:22 +00:00
|
|
|
favouriteManager: favouriteManager,
|
|
|
|
tokenManager: tokenManager,
|
|
|
|
savedAddressesManager: savedAddressesManager,
|
|
|
|
transactionManager: transactionManager,
|
|
|
|
transferController: transferController,
|
|
|
|
cryptoOnRampManager: cryptoOnRampManager,
|
2022-02-16 09:22:19 +00:00
|
|
|
openseaAPIKey: openseaAPIKey,
|
2019-06-14 10:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Service is a wallet service.
|
|
|
|
type Service struct {
|
2021-09-22 17:49:20 +00:00
|
|
|
rpcClient *rpc.Client
|
2021-09-10 18:08:22 +00:00
|
|
|
savedAddressesManager *SavedAddressesManager
|
|
|
|
tokenManager *TokenManager
|
|
|
|
transactionManager *TransactionManager
|
|
|
|
favouriteManager *FavouriteManager
|
|
|
|
cryptoOnRampManager *CryptoOnRampManager
|
|
|
|
transferController *transfer.Controller
|
|
|
|
started bool
|
2022-02-16 09:22:19 +00:00
|
|
|
openseaAPIKey string
|
2019-06-14 10:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start signals transmitter.
|
2021-06-30 11:40:54 +00:00
|
|
|
func (s *Service) Start() error {
|
2021-09-09 14:28:54 +00:00
|
|
|
err := s.transferController.Start()
|
|
|
|
s.started = true
|
|
|
|
return err
|
2019-06-14 10:16:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 07:56:14 +00:00
|
|
|
// GetFeed returns signals feed.
|
|
|
|
func (s *Service) GetFeed() *event.Feed {
|
2021-09-09 14:28:54 +00:00
|
|
|
return s.transferController.TransferFeed
|
2019-06-14 10:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop reactor, signals transmitter and close db.
|
|
|
|
func (s *Service) Stop() error {
|
|
|
|
log.Info("wallet will be stopped")
|
2021-09-09 14:28:54 +00:00
|
|
|
s.transferController.Stop()
|
|
|
|
s.started = false
|
2019-06-14 10:16:30 +00:00
|
|
|
log.Info("wallet stopped")
|
2021-09-09 14:28:54 +00:00
|
|
|
return nil
|
2019-06-14 10:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// APIs returns list of available RPC APIs.
|
2021-09-22 17:49:20 +00:00
|
|
|
func (s *Service) APIs() []gethrpc.API {
|
|
|
|
return []gethrpc.API{
|
2019-06-14 10:16:30 +00:00
|
|
|
{
|
|
|
|
Namespace: "wallet",
|
|
|
|
Version: "0.1.0",
|
|
|
|
Service: NewAPI(s),
|
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocols returns list of p2p protocols.
|
|
|
|
func (s *Service) Protocols() []p2p.Protocol {
|
|
|
|
return nil
|
|
|
|
}
|
2019-08-28 07:49:03 +00:00
|
|
|
|
2020-02-28 16:05:37 +00:00
|
|
|
func (s *Service) IsStarted() bool {
|
2020-08-18 08:44:56 +00:00
|
|
|
return s.started
|
2020-02-28 16:05:37 +00:00
|
|
|
}
|