From 3734f036455e70c1f1320bf85dd8ee952c88995c Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Wed, 16 Aug 2023 10:01:57 -0300 Subject: [PATCH] chore: split collection data provider --- services/wallet/collectibles/manager.go | 6 ++++-- services/wallet/service.go | 8 +++++++- services/wallet/thirdparty/collectible_types.go | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/services/wallet/collectibles/manager.go b/services/wallet/collectibles/manager.go index 0b9d1ef84..4361745c5 100644 --- a/services/wallet/collectibles/manager.go +++ b/services/wallet/collectibles/manager.go @@ -43,6 +43,7 @@ type Manager struct { contractOwnershipProviders []thirdparty.CollectibleContractOwnershipProvider accountOwnershipProviders []thirdparty.CollectibleAccountOwnershipProvider collectibleDataProviders []thirdparty.CollectibleDataProvider + collectionDataProviders []thirdparty.CollectionDataProvider metadataProvider thirdparty.CollectibleMetadataProvider opensea *opensea.Client httpClient *http.Client @@ -50,7 +51,7 @@ type Manager struct { collectionsDataDB *CollectionDataDB } -func NewManager(db *sql.DB, rpcClient *rpc.Client, contractOwnershipProviders []thirdparty.CollectibleContractOwnershipProvider, accountOwnershipProviders []thirdparty.CollectibleAccountOwnershipProvider, collectibleDataProviders []thirdparty.CollectibleDataProvider, opensea *opensea.Client) *Manager { +func NewManager(db *sql.DB, rpcClient *rpc.Client, contractOwnershipProviders []thirdparty.CollectibleContractOwnershipProvider, accountOwnershipProviders []thirdparty.CollectibleAccountOwnershipProvider, collectibleDataProviders []thirdparty.CollectibleDataProvider, collectionDataProviders []thirdparty.CollectionDataProvider, opensea *opensea.Client) *Manager { hystrix.ConfigureCommand(hystrixContractOwnershipClientName, hystrix.CommandConfig{ Timeout: 10000, MaxConcurrentRequests: 100, @@ -63,6 +64,7 @@ func NewManager(db *sql.DB, rpcClient *rpc.Client, contractOwnershipProviders [] contractOwnershipProviders: contractOwnershipProviders, accountOwnershipProviders: accountOwnershipProviders, collectibleDataProviders: collectibleDataProviders, + collectionDataProviders: collectionDataProviders, opensea: opensea, httpClient: &http.Client{ Timeout: requestTimeout, @@ -293,7 +295,7 @@ func (o *Manager) FetchCollectionsDataByContractID(ids []thirdparty.ContractID) missingIDsPerChainID := thirdparty.GroupContractIDsByChainID(missingIDs) for chainID, idsToFetch := range missingIDsPerChainID { - for _, provider := range o.collectibleDataProviders { + for _, provider := range o.collectionDataProviders { if !provider.IsChainSupported(chainID) { continue } diff --git a/services/wallet/service.go b/services/wallet/service.go index 61c220821..12609d585 100644 --- a/services/wallet/service.go +++ b/services/wallet/service.go @@ -127,7 +127,13 @@ func NewService( alchemyClient, } - collectiblesManager := collectibles.NewManager(db, rpcClient, contractOwnershipProviders, accountOwnershipProviders, collectibleDataProviders, openseaClient) + collectionDataProviders := []thirdparty.CollectionDataProvider{ + openseaClient, + infuraClient, + alchemyClient, + } + + collectiblesManager := collectibles.NewManager(db, rpcClient, contractOwnershipProviders, accountOwnershipProviders, collectibleDataProviders, collectionDataProviders, openseaClient) collectibles := collectibles.NewService(db, walletFeed, accountsDB, accountFeed, rpcClient.NetworkManager, collectiblesManager) return &Service{ db: db, diff --git a/services/wallet/thirdparty/collectible_types.go b/services/wallet/thirdparty/collectible_types.go index 34dd4e3ef..0e5343a13 100644 --- a/services/wallet/thirdparty/collectible_types.go +++ b/services/wallet/thirdparty/collectible_types.go @@ -173,5 +173,9 @@ type CollectibleAccountOwnershipProvider interface { type CollectibleDataProvider interface { CollectibleProvider FetchAssetsByCollectibleUniqueID(uniqueIDs []CollectibleUniqueID) ([]FullCollectibleData, error) +} + +type CollectionDataProvider interface { + CollectibleProvider FetchCollectionsDataByContractID(ids []ContractID) ([]CollectionData, error) }