From 5fd85ada0b866950bd6a7ef5f8c99edf76a601c7 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Mon, 17 Feb 2025 15:11:06 -0300 Subject: [PATCH] chore_: reorganize thirdparty dir into categories --- services/wallet/decoder.go | 4 +- services/wallet/service.go | 10 ++-- .../wallet/thirdparty/collectible_types.go | 14 +---- .../{ => collectibles}/alchemy/client.go | 0 .../{ => collectibles}/alchemy/client_test.go | 0 .../alchemy/client_test_data.go | 0 .../{ => collectibles}/alchemy/types.go | 0 .../{ => collectibles}/opensea/client_v2.go | 0 .../opensea/client_v2_test.go | 0 .../{ => collectibles}/opensea/http_client.go | 0 .../{ => collectibles}/opensea/types_v2.go | 0 .../{ => collectibles}/rarible/client.go | 0 .../rarible/client_int_test.go | 0 .../{ => collectibles}/rarible/client_test.go | 0 .../rarible/client_test_data.go | 0 .../{ => collectibles}/rarible/types.go | 0 .../{ => decoder}/fourbyte/client.go | 0 .../{ => decoder}/fourbyte/client_test.go | 0 .../{ => decoder}/fourbytegithub/client.go | 0 .../fourbytegithub/client_test.go | 0 services/wallet/thirdparty/decoder_types.go | 14 +++++ .../{ => market}/coingecko/client.go | 0 .../{ => market}/coingecko/client_test.go | 0 .../{ => market}/cryptocompare/client.go | 0 .../{ => market}/cryptocompare/client_test.go | 0 services/wallet/thirdparty/market_types.go | 40 +++++++++++++ services/wallet/thirdparty/types.go | 57 ++++++------------- .../cryptocompare/cryptocompare_test.go | 2 +- 28 files changed, 80 insertions(+), 61 deletions(-) rename services/wallet/thirdparty/{ => collectibles}/alchemy/client.go (100%) rename services/wallet/thirdparty/{ => collectibles}/alchemy/client_test.go (100%) rename services/wallet/thirdparty/{ => collectibles}/alchemy/client_test_data.go (100%) rename services/wallet/thirdparty/{ => collectibles}/alchemy/types.go (100%) rename services/wallet/thirdparty/{ => collectibles}/opensea/client_v2.go (100%) rename services/wallet/thirdparty/{ => collectibles}/opensea/client_v2_test.go (100%) rename services/wallet/thirdparty/{ => collectibles}/opensea/http_client.go (100%) rename services/wallet/thirdparty/{ => collectibles}/opensea/types_v2.go (100%) rename services/wallet/thirdparty/{ => collectibles}/rarible/client.go (100%) rename services/wallet/thirdparty/{ => collectibles}/rarible/client_int_test.go (100%) rename services/wallet/thirdparty/{ => collectibles}/rarible/client_test.go (100%) rename services/wallet/thirdparty/{ => collectibles}/rarible/client_test_data.go (100%) rename services/wallet/thirdparty/{ => collectibles}/rarible/types.go (100%) rename services/wallet/thirdparty/{ => decoder}/fourbyte/client.go (100%) rename services/wallet/thirdparty/{ => decoder}/fourbyte/client_test.go (100%) rename services/wallet/thirdparty/{ => decoder}/fourbytegithub/client.go (100%) rename services/wallet/thirdparty/{ => decoder}/fourbytegithub/client_test.go (100%) create mode 100644 services/wallet/thirdparty/decoder_types.go rename services/wallet/thirdparty/{ => market}/coingecko/client.go (100%) rename services/wallet/thirdparty/{ => market}/coingecko/client_test.go (100%) rename services/wallet/thirdparty/{ => market}/cryptocompare/client.go (100%) rename services/wallet/thirdparty/{ => market}/cryptocompare/client_test.go (100%) create mode 100644 services/wallet/thirdparty/market_types.go diff --git a/services/wallet/decoder.go b/services/wallet/decoder.go index 76af45d8f69..5f79c280c32 100644 --- a/services/wallet/decoder.go +++ b/services/wallet/decoder.go @@ -2,8 +2,8 @@ package wallet import ( "github.com/status-im/status-go/services/wallet/thirdparty" - "github.com/status-im/status-go/services/wallet/thirdparty/fourbyte" - "github.com/status-im/status-go/services/wallet/thirdparty/fourbytegithub" + "github.com/status-im/status-go/services/wallet/thirdparty/decoder/fourbyte" + "github.com/status-im/status-go/services/wallet/thirdparty/decoder/fourbytegithub" ) type Decoder struct { diff --git a/services/wallet/service.go b/services/wallet/service.go index 4e4350e72a8..225ccf441d0 100644 --- a/services/wallet/service.go +++ b/services/wallet/service.go @@ -33,11 +33,11 @@ import ( "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/thirdparty/collectibles/alchemy" + "github.com/status-im/status-go/services/wallet/thirdparty/collectibles/opensea" + "github.com/status-im/status-go/services/wallet/thirdparty/collectibles/rarible" + "github.com/status-im/status-go/services/wallet/thirdparty/market/coingecko" + "github.com/status-im/status-go/services/wallet/thirdparty/market/cryptocompare" "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" diff --git a/services/wallet/thirdparty/collectible_types.go b/services/wallet/thirdparty/collectible_types.go index 5f12b7ba217..43ace7302f1 100644 --- a/services/wallet/thirdparty/collectible_types.go +++ b/services/wallet/thirdparty/collectible_types.go @@ -5,7 +5,6 @@ package thirdparty import ( "context" "database/sql" - "errors" "fmt" "math/big" @@ -15,19 +14,8 @@ import ( w_common "github.com/status-im/status-go/services/wallet/common" ) -var ( - ErrChainIDNotSupported = errors.New("chainID not supported") - ErrEndpointNotSupported = errors.New("endpoint not supported") -) - -const FetchNoLimit = 0 -const FetchFromStartCursor = "" -const FetchFromAnyProvider = "" - type CollectibleProvider interface { - ID() string - IsChainSupported(chainID w_common.ChainID) bool - IsConnected() bool + ChainProvider } type ContractID struct { diff --git a/services/wallet/thirdparty/alchemy/client.go b/services/wallet/thirdparty/collectibles/alchemy/client.go similarity index 100% rename from services/wallet/thirdparty/alchemy/client.go rename to services/wallet/thirdparty/collectibles/alchemy/client.go diff --git a/services/wallet/thirdparty/alchemy/client_test.go b/services/wallet/thirdparty/collectibles/alchemy/client_test.go similarity index 100% rename from services/wallet/thirdparty/alchemy/client_test.go rename to services/wallet/thirdparty/collectibles/alchemy/client_test.go diff --git a/services/wallet/thirdparty/alchemy/client_test_data.go b/services/wallet/thirdparty/collectibles/alchemy/client_test_data.go similarity index 100% rename from services/wallet/thirdparty/alchemy/client_test_data.go rename to services/wallet/thirdparty/collectibles/alchemy/client_test_data.go diff --git a/services/wallet/thirdparty/alchemy/types.go b/services/wallet/thirdparty/collectibles/alchemy/types.go similarity index 100% rename from services/wallet/thirdparty/alchemy/types.go rename to services/wallet/thirdparty/collectibles/alchemy/types.go diff --git a/services/wallet/thirdparty/opensea/client_v2.go b/services/wallet/thirdparty/collectibles/opensea/client_v2.go similarity index 100% rename from services/wallet/thirdparty/opensea/client_v2.go rename to services/wallet/thirdparty/collectibles/opensea/client_v2.go diff --git a/services/wallet/thirdparty/opensea/client_v2_test.go b/services/wallet/thirdparty/collectibles/opensea/client_v2_test.go similarity index 100% rename from services/wallet/thirdparty/opensea/client_v2_test.go rename to services/wallet/thirdparty/collectibles/opensea/client_v2_test.go diff --git a/services/wallet/thirdparty/opensea/http_client.go b/services/wallet/thirdparty/collectibles/opensea/http_client.go similarity index 100% rename from services/wallet/thirdparty/opensea/http_client.go rename to services/wallet/thirdparty/collectibles/opensea/http_client.go diff --git a/services/wallet/thirdparty/opensea/types_v2.go b/services/wallet/thirdparty/collectibles/opensea/types_v2.go similarity index 100% rename from services/wallet/thirdparty/opensea/types_v2.go rename to services/wallet/thirdparty/collectibles/opensea/types_v2.go diff --git a/services/wallet/thirdparty/rarible/client.go b/services/wallet/thirdparty/collectibles/rarible/client.go similarity index 100% rename from services/wallet/thirdparty/rarible/client.go rename to services/wallet/thirdparty/collectibles/rarible/client.go diff --git a/services/wallet/thirdparty/rarible/client_int_test.go b/services/wallet/thirdparty/collectibles/rarible/client_int_test.go similarity index 100% rename from services/wallet/thirdparty/rarible/client_int_test.go rename to services/wallet/thirdparty/collectibles/rarible/client_int_test.go diff --git a/services/wallet/thirdparty/rarible/client_test.go b/services/wallet/thirdparty/collectibles/rarible/client_test.go similarity index 100% rename from services/wallet/thirdparty/rarible/client_test.go rename to services/wallet/thirdparty/collectibles/rarible/client_test.go diff --git a/services/wallet/thirdparty/rarible/client_test_data.go b/services/wallet/thirdparty/collectibles/rarible/client_test_data.go similarity index 100% rename from services/wallet/thirdparty/rarible/client_test_data.go rename to services/wallet/thirdparty/collectibles/rarible/client_test_data.go diff --git a/services/wallet/thirdparty/rarible/types.go b/services/wallet/thirdparty/collectibles/rarible/types.go similarity index 100% rename from services/wallet/thirdparty/rarible/types.go rename to services/wallet/thirdparty/collectibles/rarible/types.go diff --git a/services/wallet/thirdparty/fourbyte/client.go b/services/wallet/thirdparty/decoder/fourbyte/client.go similarity index 100% rename from services/wallet/thirdparty/fourbyte/client.go rename to services/wallet/thirdparty/decoder/fourbyte/client.go diff --git a/services/wallet/thirdparty/fourbyte/client_test.go b/services/wallet/thirdparty/decoder/fourbyte/client_test.go similarity index 100% rename from services/wallet/thirdparty/fourbyte/client_test.go rename to services/wallet/thirdparty/decoder/fourbyte/client_test.go diff --git a/services/wallet/thirdparty/fourbytegithub/client.go b/services/wallet/thirdparty/decoder/fourbytegithub/client.go similarity index 100% rename from services/wallet/thirdparty/fourbytegithub/client.go rename to services/wallet/thirdparty/decoder/fourbytegithub/client.go diff --git a/services/wallet/thirdparty/fourbytegithub/client_test.go b/services/wallet/thirdparty/decoder/fourbytegithub/client_test.go similarity index 100% rename from services/wallet/thirdparty/fourbytegithub/client_test.go rename to services/wallet/thirdparty/decoder/fourbytegithub/client_test.go diff --git a/services/wallet/thirdparty/decoder_types.go b/services/wallet/thirdparty/decoder_types.go new file mode 100644 index 00000000000..cc34d5fa6ca --- /dev/null +++ b/services/wallet/thirdparty/decoder_types.go @@ -0,0 +1,14 @@ +package thirdparty + +//go:generate mockgen -package=mock_thirdparty -source=decoder_types.go -destination=mock/decoder_types.go + +type DataParsed struct { + Name string `json:"name"` + ID string `json:"id"` + Inputs map[string]string `json:"inputs"` + Signature string `json:"signature"` +} + +type DecoderProvider interface { + Run(data string) (*DataParsed, error) +} diff --git a/services/wallet/thirdparty/coingecko/client.go b/services/wallet/thirdparty/market/coingecko/client.go similarity index 100% rename from services/wallet/thirdparty/coingecko/client.go rename to services/wallet/thirdparty/market/coingecko/client.go diff --git a/services/wallet/thirdparty/coingecko/client_test.go b/services/wallet/thirdparty/market/coingecko/client_test.go similarity index 100% rename from services/wallet/thirdparty/coingecko/client_test.go rename to services/wallet/thirdparty/market/coingecko/client_test.go diff --git a/services/wallet/thirdparty/cryptocompare/client.go b/services/wallet/thirdparty/market/cryptocompare/client.go similarity index 100% rename from services/wallet/thirdparty/cryptocompare/client.go rename to services/wallet/thirdparty/market/cryptocompare/client.go diff --git a/services/wallet/thirdparty/cryptocompare/client_test.go b/services/wallet/thirdparty/market/cryptocompare/client_test.go similarity index 100% rename from services/wallet/thirdparty/cryptocompare/client_test.go rename to services/wallet/thirdparty/market/cryptocompare/client_test.go diff --git a/services/wallet/thirdparty/market_types.go b/services/wallet/thirdparty/market_types.go new file mode 100644 index 00000000000..05178a7f6e2 --- /dev/null +++ b/services/wallet/thirdparty/market_types.go @@ -0,0 +1,40 @@ +package thirdparty + +//go:generate mockgen -package=mock_thirdparty -source=market_types.go -destination=mock/market_types.go + +type HistoricalPrice struct { + Timestamp int64 `json:"time"` + Value float64 `json:"close"` +} + +type TokenMarketValues struct { + MKTCAP float64 `json:"MKTCAP"` + HIGHDAY float64 `json:"HIGHDAY"` + LOWDAY float64 `json:"LOWDAY"` + CHANGEPCTHOUR float64 `json:"CHANGEPCTHOUR"` + CHANGEPCTDAY float64 `json:"CHANGEPCTDAY"` + CHANGEPCT24HOUR float64 `json:"CHANGEPCT24HOUR"` + CHANGE24HOUR float64 `json:"CHANGE24HOUR"` +} + +type TokenDetails struct { + ID string `json:"Id"` + Name string `json:"Name"` + Symbol string `json:"Symbol"` + Description string `json:"Description"` + TotalCoinsMined float64 `json:"TotalCoinsMined"` + AssetLaunchDate string `json:"AssetLaunchDate"` + AssetWhitepaperURL string `json:"AssetWhitepaperUrl"` + AssetWebsiteURL string `json:"AssetWebsiteUrl"` + BuiltOn string `json:"BuiltOn"` + SmartContractAddress string `json:"SmartContractAddress"` +} + +type MarketDataProvider interface { + ID() string + FetchPrices(symbols []string, currencies []string) (map[string]map[string]float64, error) + FetchHistoricalDailyPrices(symbol string, currency string, limit int, allData bool, aggregate int) ([]HistoricalPrice, error) + FetchHistoricalHourlyPrices(symbol string, currency string, limit int, aggregate int) ([]HistoricalPrice, error) + FetchTokenMarketValues(symbols []string, currency string) (map[string]TokenMarketValues, error) + FetchTokenDetails(symbols []string) (map[string]TokenDetails, error) +} diff --git a/services/wallet/thirdparty/types.go b/services/wallet/thirdparty/types.go index a6eed3e78c9..54ca0dbbb69 100644 --- a/services/wallet/thirdparty/types.go +++ b/services/wallet/thirdparty/types.go @@ -2,50 +2,27 @@ package thirdparty //go:generate mockgen -package=mock_thirdparty -source=types.go -destination=mock/types.go -type HistoricalPrice struct { - Timestamp int64 `json:"time"` - Value float64 `json:"close"` -} +import ( + "errors" -type TokenMarketValues struct { - MKTCAP float64 `json:"MKTCAP"` - HIGHDAY float64 `json:"HIGHDAY"` - LOWDAY float64 `json:"LOWDAY"` - CHANGEPCTHOUR float64 `json:"CHANGEPCTHOUR"` - CHANGEPCTDAY float64 `json:"CHANGEPCTDAY"` - CHANGEPCT24HOUR float64 `json:"CHANGEPCT24HOUR"` - CHANGE24HOUR float64 `json:"CHANGE24HOUR"` -} + w_common "github.com/status-im/status-go/services/wallet/common" +) -type TokenDetails struct { - ID string `json:"Id"` - Name string `json:"Name"` - Symbol string `json:"Symbol"` - Description string `json:"Description"` - TotalCoinsMined float64 `json:"TotalCoinsMined"` - AssetLaunchDate string `json:"AssetLaunchDate"` - AssetWhitepaperURL string `json:"AssetWhitepaperUrl"` - AssetWebsiteURL string `json:"AssetWebsiteUrl"` - BuiltOn string `json:"BuiltOn"` - SmartContractAddress string `json:"SmartContractAddress"` -} +var ( + ErrChainIDNotSupported = errors.New("chainID not supported") + ErrEndpointNotSupported = errors.New("endpoint not supported") +) -type MarketDataProvider interface { - ID() string - FetchPrices(symbols []string, currencies []string) (map[string]map[string]float64, error) - FetchHistoricalDailyPrices(symbol string, currency string, limit int, allData bool, aggregate int) ([]HistoricalPrice, error) - FetchHistoricalHourlyPrices(symbol string, currency string, limit int, aggregate int) ([]HistoricalPrice, error) - FetchTokenMarketValues(symbols []string, currency string) (map[string]TokenMarketValues, error) - FetchTokenDetails(symbols []string) (map[string]TokenDetails, error) -} +const FetchNoLimit = 0 +const FetchFromStartCursor = "" +const FetchFromAnyProvider = "" -type DataParsed struct { - Name string `json:"name"` - ID string `json:"id"` - Inputs map[string]string `json:"inputs"` - Signature string `json:"signature"` +type Provider interface { + ID() string + IsConnected() bool } -type DecoderProvider interface { - Run(data string) (*DataParsed, error) +type ChainProvider interface { + Provider + IsChainSupported(chainID w_common.ChainID) bool } diff --git a/tests-unit-network/cryptocompare/cryptocompare_test.go b/tests-unit-network/cryptocompare/cryptocompare_test.go index 5551adb6e6e..0ed96dd99e5 100644 --- a/tests-unit-network/cryptocompare/cryptocompare_test.go +++ b/tests-unit-network/cryptocompare/cryptocompare_test.go @@ -7,7 +7,7 @@ import ( "github.com/status-im/status-go/params" mock_network "github.com/status-im/status-go/rpc/network/mock" w_common "github.com/status-im/status-go/services/wallet/common" - "github.com/status-im/status-go/services/wallet/thirdparty/cryptocompare" + "github.com/status-im/status-go/services/wallet/thirdparty/market/cryptocompare" "github.com/status-im/status-go/services/wallet/token" "github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/walletdatabase"