mirror of
https://github.com/status-im/status-go.git
synced 2025-01-20 19:52:42 +00:00
14dcd29eee
author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530 committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530 test: Code Migration from status-cli-tests fix_: functional tests (#5979) * fix_: generate on test-functional * chore(test)_: fix functional test assertion --------- Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com> feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977) * feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766) The original GH issue https://github.com/status-im/status-mobile/issues/21113 came from a request from the Legal team. We must show to Status v1 users the new terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2 from the stores. The solution we use is to create a flag in the accounts table, named hasAcceptedTerms. The flag will be set to true on the first account ever created in v2 and we provide a native call in mobile/status.go#AcceptTerms, which allows the client to persist the user's choice in case they are upgrading (from v1 -> v2, or from a v2 older than this PR). This solution is not the best because we should store the setting in a separate table, not in the accounts table. Related Mobile PR https://github.com/status-im/status-mobile/pull/21124 * fix(test)_: Compare addresses using uppercased strings --------- Co-authored-by: Icaro Motta <icaro.ldm@gmail.com> test_: restore account (#5960) feat_: `LogOnPanic` linter (#5969) * feat_: LogOnPanic linter * fix_: add missing defer LogOnPanic * chore_: make vendor * fix_: tests, address pr comments * fix_: address pr comments fix(ci)_: remove workspace and tmp dir This ensures we do not encounter weird errors like: ``` + ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists script returned exit code 1 ``` Signed-off-by: Jakub Sokołowski <jakub@status.im> chore_: enable windows and macos CI build (#5840) - Added support for Windows and macOS in CI pipelines - Added missing dependencies for Windows and x86-64-darwin - Resolved macOS SDK version compatibility for darwin-x86_64 The `mkShell` override was necessary to ensure compatibility with the newer macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures because of the missing libs and frameworks. OverrideSDK creates a mapping from the default SDK in all package categories to the requested SDK (11.0). fix(contacts)_: fix trust status not being saved to cache when changed (#5965) Fixes https://github.com/status-im/status-desktop/issues/16392 cleanup added logger and cleanup review comments changes fix_: functional tests (#5979) * fix_: generate on test-functional * chore(test)_: fix functional test assertion --------- Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com> feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977) * feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766) The original GH issue https://github.com/status-im/status-mobile/issues/21113 came from a request from the Legal team. We must show to Status v1 users the new terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2 from the stores. The solution we use is to create a flag in the accounts table, named hasAcceptedTerms. The flag will be set to true on the first account ever created in v2 and we provide a native call in mobile/status.go#AcceptTerms, which allows the client to persist the user's choice in case they are upgrading (from v1 -> v2, or from a v2 older than this PR). This solution is not the best because we should store the setting in a separate table, not in the accounts table. Related Mobile PR https://github.com/status-im/status-mobile/pull/21124 * fix(test)_: Compare addresses using uppercased strings --------- Co-authored-by: Icaro Motta <icaro.ldm@gmail.com> test_: restore account (#5960) feat_: `LogOnPanic` linter (#5969) * feat_: LogOnPanic linter * fix_: add missing defer LogOnPanic * chore_: make vendor * fix_: tests, address pr comments * fix_: address pr comments chore_: enable windows and macos CI build (#5840) - Added support for Windows and macOS in CI pipelines - Added missing dependencies for Windows and x86-64-darwin - Resolved macOS SDK version compatibility for darwin-x86_64 The `mkShell` override was necessary to ensure compatibility with the newer macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures because of the missing libs and frameworks. OverrideSDK creates a mapping from the default SDK in all package categories to the requested SDK (11.0). fix(contacts)_: fix trust status not being saved to cache when changed (#5965) Fixes https://github.com/status-im/status-desktop/issues/16392 test_: remove port bind chore(wallet)_: move route execution code to separate module chore_: replace geth logger with zap logger (#5962) closes: #6002 feat(telemetry)_: add metrics for message reliability (#5899) * feat(telemetry)_: track message reliability Add metrics for dial errors, missed messages, missed relevant messages, and confirmed delivery. * fix_: handle error from json marshal chore_: use zap logger as request logger iterates: status-im/status-desktop#16536 test_: unique project per run test_: use docker compose v2, more concrete project name fix(codecov)_: ignore folders without tests Otherwise Codecov reports incorrect numbers when making changes. https://docs.codecov.com/docs/ignoring-paths Signed-off-by: Jakub Sokołowski <jakub@status.im> test_: verify schema of signals during init; fix schema verification warnings (#5947) fix_: update defaultGorushURL (#6011) fix(tests)_: use non-standard port to avoid conflicts We have observed `nimbus-eth2` build failures reporting this port: ```json { "lvl": "NTC", "ts": "2024-10-28 13:51:32.308+00:00", "msg": "REST HTTP server could not be started", "topics": "beacnde", "address": "127.0.0.1:5432", "reason": "(98) Address already in use" } ``` https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/ Signed-off-by: Jakub Sokołowski <jakub@status.im> fix_: create request logger ad-hoc in tests Fixes `TestCall` failing when run concurrently. chore_: configure codecov (#6005) * chore_: configure codecov * fix_: after_n_builds
409 lines
13 KiB
Go
409 lines
13 KiB
Go
package wallet
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/event"
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
|
|
|
"github.com/status-im/status-go/account"
|
|
"github.com/status-im/status-go/logutils"
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
|
"github.com/status-im/status-go/params"
|
|
protocolCommon "github.com/status-im/status-go/protocol/common"
|
|
"github.com/status-im/status-go/rpc"
|
|
"github.com/status-im/status-go/server"
|
|
"github.com/status-im/status-go/services/ens"
|
|
"github.com/status-im/status-go/services/stickers"
|
|
"github.com/status-im/status-go/services/wallet/activity"
|
|
"github.com/status-im/status-go/services/wallet/balance"
|
|
"github.com/status-im/status-go/services/wallet/blockchainstate"
|
|
"github.com/status-im/status-go/services/wallet/collectibles"
|
|
"github.com/status-im/status-go/services/wallet/community"
|
|
"github.com/status-im/status-go/services/wallet/currency"
|
|
"github.com/status-im/status-go/services/wallet/history"
|
|
"github.com/status-im/status-go/services/wallet/market"
|
|
"github.com/status-im/status-go/services/wallet/onramp"
|
|
"github.com/status-im/status-go/services/wallet/routeexecution"
|
|
"github.com/status-im/status-go/services/wallet/router"
|
|
"github.com/status-im/status-go/services/wallet/router/pathprocessor"
|
|
"github.com/status-im/status-go/services/wallet/thirdparty"
|
|
"github.com/status-im/status-go/services/wallet/thirdparty/alchemy"
|
|
"github.com/status-im/status-go/services/wallet/thirdparty/coingecko"
|
|
"github.com/status-im/status-go/services/wallet/thirdparty/cryptocompare"
|
|
"github.com/status-im/status-go/services/wallet/thirdparty/opensea"
|
|
"github.com/status-im/status-go/services/wallet/thirdparty/rarible"
|
|
"github.com/status-im/status-go/services/wallet/token"
|
|
"github.com/status-im/status-go/services/wallet/transfer"
|
|
"github.com/status-im/status-go/services/wallet/walletevent"
|
|
"github.com/status-im/status-go/transactions"
|
|
)
|
|
|
|
const (
|
|
EventBlockchainStatusChanged walletevent.EventType = "wallet-blockchain-status-changed"
|
|
)
|
|
|
|
// NewService initializes service instance.
|
|
func NewService(
|
|
db *sql.DB,
|
|
accountsDB *accounts.Database,
|
|
appDB *sql.DB,
|
|
rpcClient *rpc.Client,
|
|
accountFeed *event.Feed,
|
|
settingsFeed *event.Feed,
|
|
gethManager *account.GethManager,
|
|
transactor *transactions.Transactor,
|
|
config *params.NodeConfig,
|
|
ens *ens.Service,
|
|
stickers *stickers.Service,
|
|
pendingTxManager *transactions.PendingTxTracker,
|
|
feed *event.Feed,
|
|
mediaServer *server.MediaServer,
|
|
statusProxyStageName string,
|
|
) *Service {
|
|
signals := &walletevent.SignalsTransmitter{
|
|
Publisher: feed,
|
|
}
|
|
blockchainStatus := make(map[uint64]string)
|
|
mutex := sync.Mutex{}
|
|
rpcClient.SetWalletNotifier(func(chainID uint64, message string) {
|
|
mutex.Lock()
|
|
defer mutex.Unlock()
|
|
|
|
if len(blockchainStatus) == 0 {
|
|
networks, err := rpcClient.NetworkManager.Get(false)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, network := range networks {
|
|
blockchainStatus[network.ChainID] = "up"
|
|
}
|
|
}
|
|
|
|
blockchainStatus[chainID] = message
|
|
encodedmessage, err := json.Marshal(blockchainStatus)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
feed.Send(walletevent.Event{
|
|
Type: EventBlockchainStatusChanged,
|
|
Accounts: []common.Address{},
|
|
Message: string(encodedmessage),
|
|
At: time.Now().Unix(),
|
|
ChainID: chainID,
|
|
})
|
|
})
|
|
|
|
communityManager := community.NewManager(db, mediaServer, feed)
|
|
balanceCacher := balance.NewCacherWithTTL(5 * time.Minute)
|
|
tokenManager := token.NewTokenManager(db, rpcClient, communityManager, rpcClient.NetworkManager, appDB, mediaServer, feed, accountFeed, accountsDB, token.NewPersistence(db))
|
|
tokenManager.Start()
|
|
|
|
cryptoOnRampProviders := []onramp.Provider{
|
|
onramp.NewMercuryoProvider(tokenManager),
|
|
onramp.NewRampProvider(),
|
|
onramp.NewMoonPayProvider(),
|
|
}
|
|
cryptoOnRampManager := onramp.NewManager(cryptoOnRampProviders)
|
|
|
|
savedAddressesManager := &SavedAddressesManager{db: db}
|
|
transactionManager := transfer.NewTransactionManager(transfer.NewMultiTransactionDB(db), gethManager, transactor, config, accountsDB, pendingTxManager, feed)
|
|
blockChainState := blockchainstate.NewBlockChainState()
|
|
transferController := transfer.NewTransferController(db, accountsDB, rpcClient, accountFeed, feed, transactionManager, pendingTxManager,
|
|
tokenManager, balanceCacher, blockChainState)
|
|
transferController.Start()
|
|
cryptoCompare := cryptocompare.NewClient()
|
|
coingecko := coingecko.NewClient()
|
|
cryptoCompareProxy := cryptocompare.NewClientWithParams(cryptocompare.Params{
|
|
ID: fmt.Sprintf("%s-proxy", cryptoCompare.ID()),
|
|
URL: fmt.Sprintf("https://%s.api.status.im/cryptocompare/", statusProxyStageName),
|
|
User: config.WalletConfig.StatusProxyMarketUser,
|
|
Password: config.WalletConfig.StatusProxyMarketPassword,
|
|
})
|
|
marketManager := market.NewManager([]thirdparty.MarketDataProvider{cryptoCompare, coingecko, cryptoCompareProxy}, feed)
|
|
reader := NewReader(tokenManager, marketManager, token.NewPersistence(db), feed)
|
|
history := history.NewService(db, accountsDB, accountFeed, feed, rpcClient, tokenManager, marketManager, balanceCacher.Cache())
|
|
currency := currency.NewService(db, feed, tokenManager, marketManager)
|
|
|
|
openseaHTTPClient := opensea.NewHTTPClient()
|
|
openseaV2Client := opensea.NewClientV2(config.WalletConfig.OpenseaAPIKey, openseaHTTPClient)
|
|
raribleClient := rarible.NewClient(config.WalletConfig.RaribleMainnetAPIKey, config.WalletConfig.RaribleTestnetAPIKey)
|
|
alchemyClient := alchemy.NewClient(config.WalletConfig.AlchemyAPIKeys)
|
|
|
|
// Collectible providers in priority order (i.e. provider N+1 will be tried only if provider N fails)
|
|
contractOwnershipProviders := []thirdparty.CollectibleContractOwnershipProvider{
|
|
raribleClient,
|
|
alchemyClient,
|
|
}
|
|
|
|
accountOwnershipProviders := []thirdparty.CollectibleAccountOwnershipProvider{
|
|
raribleClient,
|
|
alchemyClient,
|
|
openseaV2Client,
|
|
}
|
|
|
|
collectibleDataProviders := []thirdparty.CollectibleDataProvider{
|
|
raribleClient,
|
|
alchemyClient,
|
|
openseaV2Client,
|
|
}
|
|
|
|
collectionDataProviders := []thirdparty.CollectionDataProvider{
|
|
raribleClient,
|
|
alchemyClient,
|
|
openseaV2Client,
|
|
}
|
|
|
|
collectibleSearchProviders := []thirdparty.CollectibleSearchProvider{
|
|
raribleClient,
|
|
}
|
|
|
|
collectibleProviders := thirdparty.CollectibleProviders{
|
|
ContractOwnershipProviders: contractOwnershipProviders,
|
|
AccountOwnershipProviders: accountOwnershipProviders,
|
|
CollectibleDataProviders: collectibleDataProviders,
|
|
CollectionDataProviders: collectionDataProviders,
|
|
SearchProviders: collectibleSearchProviders,
|
|
}
|
|
|
|
collectiblesManager := collectibles.NewManager(
|
|
db,
|
|
rpcClient,
|
|
communityManager,
|
|
collectibleProviders,
|
|
mediaServer,
|
|
feed,
|
|
)
|
|
collectibles := collectibles.NewService(db, feed, accountsDB, accountFeed, settingsFeed, communityManager, rpcClient.NetworkManager, collectiblesManager)
|
|
|
|
activity := activity.NewService(db, accountsDB, tokenManager, collectiblesManager, feed, pendingTxManager)
|
|
|
|
featureFlags := &protocolCommon.FeatureFlags{}
|
|
if config.WalletConfig.EnableCelerBridge {
|
|
featureFlags.EnableCelerBridge = true
|
|
}
|
|
|
|
router := router.NewRouter(rpcClient, transactor, tokenManager, marketManager, collectibles,
|
|
collectiblesManager, ens, stickers)
|
|
pathProcessors := buildPathProcessors(rpcClient, transactor, tokenManager, ens, stickers, featureFlags)
|
|
for _, processor := range pathProcessors {
|
|
router.AddPathProcessor(processor)
|
|
}
|
|
|
|
routeExecutionManager := routeexecution.NewManager(router, transactionManager, transferController)
|
|
|
|
return &Service{
|
|
db: db,
|
|
accountsDB: accountsDB,
|
|
rpcClient: rpcClient,
|
|
tokenManager: tokenManager,
|
|
communityManager: communityManager,
|
|
savedAddressesManager: savedAddressesManager,
|
|
transactionManager: transactionManager,
|
|
pendingTxManager: pendingTxManager,
|
|
transferController: transferController,
|
|
cryptoOnRampManager: cryptoOnRampManager,
|
|
collectiblesManager: collectiblesManager,
|
|
collectibles: collectibles,
|
|
gethManager: gethManager,
|
|
marketManager: marketManager,
|
|
transactor: transactor,
|
|
ens: ens,
|
|
stickers: stickers,
|
|
feed: feed,
|
|
signals: signals,
|
|
reader: reader,
|
|
history: history,
|
|
currency: currency,
|
|
activity: activity,
|
|
decoder: NewDecoder(),
|
|
blockChainState: blockChainState,
|
|
keycardPairings: NewKeycardPairings(),
|
|
config: config,
|
|
featureFlags: featureFlags,
|
|
router: router,
|
|
routeExecutionManager: routeExecutionManager,
|
|
}
|
|
}
|
|
|
|
func buildPathProcessors(
|
|
rpcClient *rpc.Client,
|
|
transactor *transactions.Transactor,
|
|
tokenManager *token.Manager,
|
|
ens *ens.Service,
|
|
stickers *stickers.Service,
|
|
featureFlags *protocolCommon.FeatureFlags,
|
|
) []pathprocessor.PathProcessor {
|
|
ret := make([]pathprocessor.PathProcessor, 0)
|
|
|
|
transfer := pathprocessor.NewTransferProcessor(rpcClient, transactor)
|
|
ret = append(ret, transfer)
|
|
|
|
erc721Transfer := pathprocessor.NewERC721Processor(rpcClient, transactor)
|
|
ret = append(ret, erc721Transfer)
|
|
|
|
erc1155Transfer := pathprocessor.NewERC1155Processor(rpcClient, transactor)
|
|
ret = append(ret, erc1155Transfer)
|
|
|
|
hop := pathprocessor.NewHopBridgeProcessor(rpcClient, transactor, tokenManager, rpcClient.NetworkManager)
|
|
ret = append(ret, hop)
|
|
|
|
if featureFlags.EnableCelerBridge {
|
|
// TODO: Celar Bridge is out of scope for 2.30, check it thoroughly once we decide to include it again
|
|
cbridge := pathprocessor.NewCelerBridgeProcessor(rpcClient, transactor, tokenManager)
|
|
ret = append(ret, cbridge)
|
|
}
|
|
|
|
paraswap := pathprocessor.NewSwapParaswapProcessor(rpcClient, transactor, tokenManager)
|
|
ret = append(ret, paraswap)
|
|
|
|
ensRegister := pathprocessor.NewENSRegisterProcessor(rpcClient, transactor, ens)
|
|
ret = append(ret, ensRegister)
|
|
|
|
ensRelease := pathprocessor.NewENSReleaseProcessor(rpcClient, transactor, ens)
|
|
ret = append(ret, ensRelease)
|
|
|
|
return ret
|
|
}
|
|
|
|
// Service is a wallet service.
|
|
type Service struct {
|
|
db *sql.DB
|
|
accountsDB *accounts.Database
|
|
rpcClient *rpc.Client
|
|
savedAddressesManager *SavedAddressesManager
|
|
tokenManager *token.Manager
|
|
communityManager *community.Manager
|
|
transactionManager *transfer.TransactionManager
|
|
pendingTxManager *transactions.PendingTxTracker
|
|
cryptoOnRampManager *onramp.Manager
|
|
transferController *transfer.Controller
|
|
marketManager *market.Manager
|
|
started bool
|
|
collectiblesManager *collectibles.Manager
|
|
collectibles *collectibles.Service
|
|
gethManager *account.GethManager
|
|
transactor *transactions.Transactor
|
|
ens *ens.Service
|
|
stickers *stickers.Service
|
|
feed *event.Feed
|
|
signals *walletevent.SignalsTransmitter
|
|
reader *Reader
|
|
history *history.Service
|
|
currency *currency.Service
|
|
activity *activity.Service
|
|
decoder *Decoder
|
|
blockChainState *blockchainstate.BlockChainState
|
|
keycardPairings *KeycardPairings
|
|
config *params.NodeConfig
|
|
featureFlags *protocolCommon.FeatureFlags
|
|
router *router.Router
|
|
routeExecutionManager *routeexecution.Manager
|
|
}
|
|
|
|
// Start signals transmitter.
|
|
func (s *Service) Start() error {
|
|
s.transferController.Start()
|
|
s.currency.Start()
|
|
err := s.signals.Start()
|
|
s.history.Start()
|
|
s.collectibles.Start()
|
|
s.started = true
|
|
return err
|
|
}
|
|
|
|
// Set external Collectibles community info provider
|
|
func (s *Service) SetWalletCommunityInfoProvider(provider thirdparty.CommunityInfoProvider) {
|
|
s.communityManager.SetCommunityInfoProvider(provider)
|
|
}
|
|
|
|
// Stop reactor and close db.
|
|
func (s *Service) Stop() error {
|
|
logutils.ZapLogger().Info("wallet will be stopped")
|
|
s.router.Stop()
|
|
s.signals.Stop()
|
|
s.transferController.Stop()
|
|
s.currency.Stop()
|
|
s.reader.Stop()
|
|
s.history.Stop()
|
|
s.activity.Stop()
|
|
s.collectibles.Stop()
|
|
s.tokenManager.Stop()
|
|
s.started = false
|
|
logutils.ZapLogger().Info("wallet stopped")
|
|
return nil
|
|
}
|
|
|
|
// APIs returns list of available RPC APIs.
|
|
func (s *Service) APIs() []gethrpc.API {
|
|
return []gethrpc.API{
|
|
{
|
|
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
|
|
}
|
|
|
|
func (s *Service) IsStarted() bool {
|
|
return s.started
|
|
}
|
|
|
|
func (s *Service) KeycardPairings() *KeycardPairings {
|
|
return s.keycardPairings
|
|
}
|
|
|
|
func (s *Service) Config() *params.NodeConfig {
|
|
return s.config
|
|
}
|
|
|
|
func (s *Service) FeatureFlags() *protocolCommon.FeatureFlags {
|
|
return s.featureFlags
|
|
}
|
|
|
|
func (s *Service) GetRPCClient() *rpc.Client {
|
|
return s.rpcClient
|
|
}
|
|
|
|
func (s *Service) GetTransactor() *transactions.Transactor {
|
|
return s.transactor
|
|
}
|
|
|
|
func (s *Service) GetTokenManager() *token.Manager {
|
|
return s.tokenManager
|
|
}
|
|
|
|
func (s *Service) GetMarketManager() *market.Manager {
|
|
return s.marketManager
|
|
}
|
|
|
|
func (s *Service) GetCollectiblesService() *collectibles.Service {
|
|
return s.collectibles
|
|
}
|
|
|
|
func (s *Service) GetCollectiblesManager() *collectibles.Manager {
|
|
return s.collectiblesManager
|
|
}
|
|
|
|
func (s *Service) GetEnsService() *ens.Service {
|
|
return s.ens
|
|
}
|
|
|
|
func (s *Service) GetStickersService() *stickers.Service {
|
|
return s.stickers
|
|
}
|