chore: rename and reorder types

This commit is contained in:
Dario Gabriel Lipicar 2023-07-05 06:33:48 -03:00 committed by dlipicar
parent 07a3726b1d
commit b5224b3cc5
10 changed files with 105 additions and 104 deletions

View File

@ -118,7 +118,7 @@ func (b *StatusNode) initServices(config *params.NodeConfig, mediaServer *server
services = append(services, wakuext) services = append(services, wakuext)
b.SetWalletNFTMetadataProvider(wakuext) b.SetWalletCollectibleMetadataProvider(wakuext)
} }
if config.WakuV2Config.Enabled { if config.WakuV2Config.Enabled {
@ -145,7 +145,7 @@ func (b *StatusNode) initServices(config *params.NodeConfig, mediaServer *server
services = append(services, wakuext) services = append(services, wakuext)
b.SetWalletNFTMetadataProvider(wakuext) b.SetWalletCollectibleMetadataProvider(wakuext)
} }
// We ignore for now local notifications flag as users who are upgrading have no mean to enable it // We ignore for now local notifications flag as users who are upgrading have no mean to enable it
@ -487,9 +487,9 @@ func (b *StatusNode) WalletService() *wallet.Service {
return b.walletSrvc return b.walletSrvc
} }
func (b *StatusNode) SetWalletNFTMetadataProvider(provider thirdparty.NFTMetadataProvider) { func (b *StatusNode) SetWalletCollectibleMetadataProvider(provider thirdparty.CollectibleMetadataProvider) {
if b.walletSrvc != nil { if b.walletSrvc != nil {
b.walletSrvc.SetNFTMetadataProvider(provider) b.walletSrvc.SetCollectibleMetadataProvider(provider)
} }
} }

View File

@ -62,7 +62,7 @@ type EnvelopeEventsHandler interface {
// Service is a service that provides some additional API to whisper-based protocols like Whisper or Waku. // Service is a service that provides some additional API to whisper-based protocols like Whisper or Waku.
type Service struct { type Service struct {
thirdparty.NFTMetadataProvider thirdparty.CollectibleMetadataProvider
messenger *protocol.Messenger messenger *protocol.Messenger
identity *ecdsa.PrivateKey identity *ecdsa.PrivateKey
cancelMessenger chan struct{} cancelMessenger chan struct{}
@ -545,12 +545,12 @@ func tokenURIToCommunityID(tokenURI string) string {
return communityID return communityID
} }
func (s *Service) CanProvideNFTMetadata(chainID uint64, id thirdparty.NFTUniqueID, tokenURI string) (bool, error) { func (s *Service) CanProvideCollectibleMetadata(chainID uint64, id thirdparty.CollectibleUniqueID, tokenURI string) (bool, error) {
ret := tokenURI != "" && tokenURIToCommunityID(tokenURI) != "" ret := tokenURI != "" && tokenURIToCommunityID(tokenURI) != ""
return ret, nil return ret, nil
} }
func (s *Service) FetchNFTMetadata(chainID uint64, id thirdparty.NFTUniqueID, tokenURI string) (*thirdparty.NFTMetadata, error) { func (s *Service) FetchCollectibleMetadata(chainID uint64, id thirdparty.CollectibleUniqueID, tokenURI string) (*thirdparty.CollectibleMetadata, error) {
if s.messenger == nil { if s.messenger == nil {
return nil, fmt.Errorf("messenger not ready") return nil, fmt.Errorf("messenger not ready")
} }
@ -574,7 +574,7 @@ func (s *Service) FetchNFTMetadata(chainID uint64, id thirdparty.NFTUniqueID, to
for _, tokenMetadata := range tokensMetadata { for _, tokenMetadata := range tokensMetadata {
contractAddresses := tokenMetadata.GetContractAddresses() contractAddresses := tokenMetadata.GetContractAddresses()
if contractAddresses[chainID] == id.ContractAddress.Hex() { if contractAddresses[chainID] == id.ContractAddress.Hex() {
return &thirdparty.NFTMetadata{ return &thirdparty.CollectibleMetadata{
Name: tokenMetadata.GetName(), Name: tokenMetadata.GetName(),
Description: tokenMetadata.GetDescription(), Description: tokenMetadata.GetDescription(),
CollectionImageURL: tokenMetadata.GetImage(), CollectionImageURL: tokenMetadata.GetImage(),

View File

@ -328,14 +328,14 @@ func (api *API) GetOpenseaAssetsByOwnerAndContractAddressWithCursor(ctx context.
return api.s.collectiblesManager.FetchAllAssetsByOwnerAndContractAddress(chainID, owner, contractAddresses, cursor, limit) return api.s.collectiblesManager.FetchAllAssetsByOwnerAndContractAddress(chainID, owner, contractAddresses, cursor, limit)
} }
func (api *API) GetOpenseaAssetsByNFTUniqueID(ctx context.Context, chainID uint64, uniqueIDs []thirdparty.NFTUniqueID, limit int) (*opensea.AssetContainer, error) { func (api *API) GetOpenseaAssetsByNFTUniqueID(ctx context.Context, chainID uint64, uniqueIDs []thirdparty.CollectibleUniqueID, limit int) (*opensea.AssetContainer, error) {
log.Debug("call to GetOpenseaAssetsByNFTUniqueID") log.Debug("call to GetOpenseaAssetsByNFTUniqueID")
return api.s.collectiblesManager.FetchAssetsByNFTUniqueID(chainID, uniqueIDs, limit) return api.s.collectiblesManager.FetchAssetsByNFTUniqueID(chainID, uniqueIDs, limit)
} }
func (api *API) GetCollectibleOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.NFTContractOwnership, error) { func (api *API) GetCollectibleOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.CollectibleContractOwnership, error) {
log.Debug("call to GetCollectibleOwnersByContractAddress") log.Debug("call to GetCollectibleOwnersByContractAddress")
return api.s.collectiblesManager.FetchNFTOwnersByContractAddress(chainID, contractAddress) return api.s.collectiblesManager.FetchCollectibleOwnersByContractAddress(chainID, contractAddress)
} }
func (api *API) FetchBalancesByOwnerAndContractAddress(chainID uint64, ownerAddress common.Address, contractAddresses []common.Address) (thirdparty.TokenBalancesPerContractAddress, error) { func (api *API) FetchBalancesByOwnerAndContractAddress(chainID uint64, ownerAddress common.Address, contractAddresses []common.Address) (thirdparty.TokenBalancesPerContractAddress, error) {

View File

@ -35,16 +35,16 @@ var noTokenURIErrorPrefixes = []string{
type Manager struct { type Manager struct {
rpcClient *rpc.Client rpcClient *rpc.Client
mainContractOwnershipProvider thirdparty.NFTContractOwnershipProvider mainContractOwnershipProvider thirdparty.CollectibleContractOwnershipProvider
fallbackContractOwnershipProvider thirdparty.NFTContractOwnershipProvider fallbackContractOwnershipProvider thirdparty.CollectibleContractOwnershipProvider
metadataProvider thirdparty.NFTMetadataProvider metadataProvider thirdparty.CollectibleMetadataProvider
openseaAPIKey string openseaAPIKey string
nftCache map[uint64]map[string]opensea.Asset nftCache map[uint64]map[string]opensea.Asset
nftCacheLock sync.RWMutex nftCacheLock sync.RWMutex
walletFeed *event.Feed walletFeed *event.Feed
} }
func NewManager(rpcClient *rpc.Client, mainContractOwnershipProvider thirdparty.NFTContractOwnershipProvider, fallbackContractOwnershipProvider thirdparty.NFTContractOwnershipProvider, openseaAPIKey string, walletFeed *event.Feed) *Manager { func NewManager(rpcClient *rpc.Client, mainContractOwnershipProvider thirdparty.CollectibleContractOwnershipProvider, fallbackContractOwnershipProvider thirdparty.CollectibleContractOwnershipProvider, openseaAPIKey string, walletFeed *event.Feed) *Manager {
hystrix.ConfigureCommand(hystrixContractOwnershipClientName, hystrix.CommandConfig{ hystrix.ConfigureCommand(hystrixContractOwnershipClientName, hystrix.CommandConfig{
Timeout: 10000, Timeout: 10000,
MaxConcurrentRequests: 100, MaxConcurrentRequests: 100,
@ -92,7 +92,7 @@ func makeContractOwnershipCall(main func() (any, error), fallback func() (any, e
} }
// Used to break circular dependency, call once as soon as possible after initialization // Used to break circular dependency, call once as soon as possible after initialization
func (o *Manager) SetMetadataProvider(metadataProvider thirdparty.NFTMetadataProvider) { func (o *Manager) SetMetadataProvider(metadataProvider thirdparty.CollectibleMetadataProvider) {
o.metadataProvider = metadataProvider o.metadataProvider = metadataProvider
} }
@ -136,7 +136,7 @@ func (o *Manager) FetchBalancesByOwnerAndContractAddress(chainID uint64, ownerAd
if err == opensea.ErrChainIDNotSupported { if err == opensea.ErrChainIDNotSupported {
// Use contract ownership providers // Use contract ownership providers
for _, contractAddress := range contractAddresses { for _, contractAddress := range contractAddresses {
ownership, err := o.FetchNFTOwnersByContractAddress(chainID, contractAddress) ownership, err := o.FetchCollectibleOwnersByContractAddress(chainID, contractAddress)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -203,7 +203,7 @@ func (o *Manager) FetchAllAssetsByOwner(chainID uint64, owner common.Address, cu
return assetContainer, nil return assetContainer, nil
} }
func (o *Manager) FetchAssetsByNFTUniqueID(chainID uint64, uniqueIDs []thirdparty.NFTUniqueID, limit int) (*opensea.AssetContainer, error) { func (o *Manager) FetchAssetsByNFTUniqueID(chainID uint64, uniqueIDs []thirdparty.CollectibleUniqueID, limit int) (*opensea.AssetContainer, error) {
assetContainer := new(opensea.AssetContainer) assetContainer := new(opensea.AssetContainer)
idsToFetch := o.getIDsNotInCache(chainID, uniqueIDs) idsToFetch := o.getIDsNotInCache(chainID, uniqueIDs)
@ -232,14 +232,14 @@ func (o *Manager) FetchAssetsByNFTUniqueID(chainID uint64, uniqueIDs []thirdpart
return assetContainer, nil return assetContainer, nil
} }
func (o *Manager) FetchNFTOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.NFTContractOwnership, error) { func (o *Manager) FetchCollectibleOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.CollectibleContractOwnership, error) {
mainFunc := func() (any, error) { mainFunc := func() (any, error) {
return o.mainContractOwnershipProvider.FetchNFTOwnersByContractAddress(chainID, contractAddress) return o.mainContractOwnershipProvider.FetchCollectibleOwnersByContractAddress(chainID, contractAddress)
} }
var fallbackFunc func() (any, error) = nil var fallbackFunc func() (any, error) = nil
if o.fallbackContractOwnershipProvider != nil && o.fallbackContractOwnershipProvider.IsChainSupported(chainID) { if o.fallbackContractOwnershipProvider != nil && o.fallbackContractOwnershipProvider.IsChainSupported(chainID) {
fallbackFunc = func() (any, error) { fallbackFunc = func() (any, error) {
return o.fallbackContractOwnershipProvider.FetchNFTOwnersByContractAddress(chainID, contractAddress) return o.fallbackContractOwnershipProvider.FetchCollectibleOwnersByContractAddress(chainID, contractAddress)
} }
} }
owners, err := makeContractOwnershipCall(mainFunc, fallbackFunc) owners, err := makeContractOwnershipCall(mainFunc, fallbackFunc)
@ -247,7 +247,7 @@ func (o *Manager) FetchNFTOwnersByContractAddress(chainID uint64, contractAddres
return nil, err return nil, err
} }
return owners.(*thirdparty.NFTContractOwnership), nil return owners.(*thirdparty.CollectibleContractOwnership), nil
} }
func isMetadataEmpty(asset opensea.Asset) bool { func isMetadataEmpty(asset opensea.Asset) bool {
@ -257,7 +257,7 @@ func isMetadataEmpty(asset opensea.Asset) bool {
asset.TokenURI == "" asset.TokenURI == ""
} }
func (o *Manager) fetchTokenURI(chainID uint64, id thirdparty.NFTUniqueID) (string, error) { func (o *Manager) fetchTokenURI(chainID uint64, id thirdparty.CollectibleUniqueID) (string, error) {
backend, err := o.rpcClient.EthClient(chainID) backend, err := o.rpcClient.EthClient(chainID)
if err != nil { if err != nil {
return "", err return "", err
@ -297,14 +297,14 @@ func (o *Manager) processAssets(chainID uint64, assets []opensea.Asset) error {
} }
for idx, asset := range assets { for idx, asset := range assets {
id := thirdparty.NFTUniqueID{ id := thirdparty.CollectibleUniqueID{
ContractAddress: common.HexToAddress(asset.Contract.Address), ContractAddress: common.HexToAddress(asset.Contract.Address),
TokenID: asset.TokenID, TokenID: asset.TokenID,
} }
if isMetadataEmpty(asset) { if isMetadataEmpty(asset) {
if o.metadataProvider == nil { if o.metadataProvider == nil {
return fmt.Errorf("NFTMetadataProvider not available") return fmt.Errorf("CollectibleMetadataProvider not available")
} }
tokenURI, err := o.fetchTokenURI(chainID, id) tokenURI, err := o.fetchTokenURI(chainID, id)
@ -314,14 +314,14 @@ func (o *Manager) processAssets(chainID uint64, assets []opensea.Asset) error {
assets[idx].TokenURI = tokenURI assets[idx].TokenURI = tokenURI
canProvide, err := o.metadataProvider.CanProvideNFTMetadata(chainID, id, tokenURI) canProvide, err := o.metadataProvider.CanProvideCollectibleMetadata(chainID, id, tokenURI)
if err != nil { if err != nil {
return err return err
} }
if canProvide { if canProvide {
metadata, err := o.metadataProvider.FetchNFTMetadata(chainID, id, tokenURI) metadata, err := o.metadataProvider.FetchCollectibleMetadata(chainID, id, tokenURI)
if err != nil { if err != nil {
return err return err
} }
@ -347,11 +347,11 @@ func (o *Manager) processAssets(chainID uint64, assets []opensea.Asset) error {
return nil return nil
} }
func (o *Manager) getIDsNotInCache(chainID uint64, uniqueIDs []thirdparty.NFTUniqueID) []thirdparty.NFTUniqueID { func (o *Manager) getIDsNotInCache(chainID uint64, uniqueIDs []thirdparty.CollectibleUniqueID) []thirdparty.CollectibleUniqueID {
o.nftCacheLock.RLock() o.nftCacheLock.RLock()
defer o.nftCacheLock.RUnlock() defer o.nftCacheLock.RUnlock()
idsToFetch := make([]thirdparty.NFTUniqueID, 0, len(uniqueIDs)) idsToFetch := make([]thirdparty.CollectibleUniqueID, 0, len(uniqueIDs))
if _, ok := o.nftCache[chainID]; !ok { if _, ok := o.nftCache[chainID]; !ok {
idsToFetch = uniqueIDs idsToFetch = uniqueIDs
} else { } else {
@ -364,7 +364,7 @@ func (o *Manager) getIDsNotInCache(chainID uint64, uniqueIDs []thirdparty.NFTUni
return idsToFetch return idsToFetch
} }
func (o *Manager) getCachedAssets(chainID uint64, uniqueIDs []thirdparty.NFTUniqueID) []opensea.Asset { func (o *Manager) getCachedAssets(chainID uint64, uniqueIDs []thirdparty.CollectibleUniqueID) []opensea.Asset {
o.nftCacheLock.RLock() o.nftCacheLock.RLock()
defer o.nftCacheLock.RUnlock() defer o.nftCacheLock.RUnlock()

View File

@ -181,7 +181,7 @@ func (s *Service) GetFeed() *event.Feed {
} }
// Set external Collectibles metadata provider // Set external Collectibles metadata provider
func (s *Service) SetNFTMetadataProvider(provider thirdparty.NFTMetadataProvider) { func (s *Service) SetCollectibleMetadataProvider(provider thirdparty.CollectibleMetadataProvider) {
s.collectiblesManager.SetMetadataProvider(provider) s.collectiblesManager.SetMetadataProvider(provider)
} }

View File

@ -58,18 +58,18 @@ type TokenBalance struct {
Balance *bigint.BigInt `json:"balance"` Balance *bigint.BigInt `json:"balance"`
} }
type NFTOwner struct { type CollectibleOwner struct {
OwnerAddress common.Address `json:"ownerAddress"` OwnerAddress common.Address `json:"ownerAddress"`
TokenBalances []TokenBalance `json:"tokenBalances"` TokenBalances []TokenBalance `json:"tokenBalances"`
} }
type NFTContractOwnership struct { type CollectibleContractOwnership struct {
Owners []NFTOwner `json:"ownerAddresses"` Owners []CollectibleOwner `json:"ownerAddresses"`
PageKey string `json:"pageKey"` PageKey string `json:"pageKey"`
} }
type Client struct { type Client struct {
thirdparty.NFTContractOwnershipProvider thirdparty.CollectibleContractOwnershipProvider
client *http.Client client *http.Client
apiKeys map[uint64]string apiKeys map[uint64]string
IsConnected bool IsConnected bool
@ -98,8 +98,8 @@ func (o *Client) IsChainSupported(chainID uint64) bool {
return err == nil return err == nil
} }
func alchemyOwnershipToCommon(contractAddress common.Address, alchemyOwnership NFTContractOwnership) (*thirdparty.NFTContractOwnership, error) { func alchemyOwnershipToCommon(contractAddress common.Address, alchemyOwnership CollectibleContractOwnership) (*thirdparty.CollectibleContractOwnership, error) {
owners := make([]thirdparty.NFTOwner, 0, len(alchemyOwnership.Owners)) owners := make([]thirdparty.CollectibleOwner, 0, len(alchemyOwnership.Owners))
for _, alchemyOwner := range alchemyOwnership.Owners { for _, alchemyOwner := range alchemyOwnership.Owners {
balances := make([]thirdparty.TokenBalance, 0, len(alchemyOwner.TokenBalances)) balances := make([]thirdparty.TokenBalance, 0, len(alchemyOwner.TokenBalances))
@ -109,7 +109,7 @@ func alchemyOwnershipToCommon(contractAddress common.Address, alchemyOwnership N
Balance: alchemyBalance.Balance, Balance: alchemyBalance.Balance,
}) })
} }
owner := thirdparty.NFTOwner{ owner := thirdparty.CollectibleOwner{
OwnerAddress: alchemyOwner.OwnerAddress, OwnerAddress: alchemyOwner.OwnerAddress,
TokenBalances: balances, TokenBalances: balances,
} }
@ -117,7 +117,7 @@ func alchemyOwnershipToCommon(contractAddress common.Address, alchemyOwnership N
owners = append(owners, owner) owners = append(owners, owner)
} }
ownership := thirdparty.NFTContractOwnership{ ownership := thirdparty.CollectibleContractOwnership{
ContractAddress: contractAddress, ContractAddress: contractAddress,
Owners: owners, Owners: owners,
} }
@ -125,7 +125,7 @@ func alchemyOwnershipToCommon(contractAddress common.Address, alchemyOwnership N
return &ownership, nil return &ownership, nil
} }
func (o *Client) FetchNFTOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.NFTContractOwnership, error) { func (o *Client) FetchCollectibleOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.CollectibleContractOwnership, error) {
queryParams := url.Values{ queryParams := url.Values{
"contractAddress": {contractAddress.String()}, "contractAddress": {contractAddress.String()},
"withTokenBalances": {"true"}, "withTokenBalances": {"true"},
@ -152,7 +152,7 @@ func (o *Client) FetchNFTOwnersByContractAddress(chainID uint64, contractAddress
return nil, err return nil, err
} }
var alchemyOwnership NFTContractOwnership var alchemyOwnership CollectibleContractOwnership
err = json.Unmarshal(body, &alchemyOwnership) err = json.Unmarshal(body, &alchemyOwnership)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -0,0 +1,49 @@
package thirdparty
import (
"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/services/wallet/bigint"
)
type CollectibleUniqueID struct {
ContractAddress common.Address `json:"contractAddress"`
TokenID *bigint.BigInt `json:"tokenID"`
}
func (k *CollectibleUniqueID) HashKey() string {
return k.ContractAddress.String() + "+" + k.TokenID.String()
}
type CollectibleMetadata struct {
Name string `json:"name"`
Description string `json:"description"`
CollectionImageURL string `json:"collection_image"`
ImageURL string `json:"image"`
}
type CollectibleMetadataProvider interface {
CanProvideCollectibleMetadata(chainID uint64, id CollectibleUniqueID, tokenURI string) (bool, error)
FetchCollectibleMetadata(chainID uint64, id CollectibleUniqueID, tokenURI string) (*CollectibleMetadata, error)
}
type TokenBalance struct {
TokenID *bigint.BigInt `json:"tokenId"`
Balance *bigint.BigInt `json:"balance"`
}
type TokenBalancesPerContractAddress = map[common.Address][]TokenBalance
type CollectibleOwner struct {
OwnerAddress common.Address `json:"ownerAddress"`
TokenBalances []TokenBalance `json:"tokenBalances"`
}
type CollectibleContractOwnership struct {
ContractAddress common.Address `json:"contractAddress"`
Owners []CollectibleOwner `json:"owners"`
}
type CollectibleContractOwnershipProvider interface {
FetchCollectibleOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*CollectibleContractOwnership, error)
IsChainSupported(chainID uint64) bool
}

View File

@ -16,21 +16,21 @@ import (
const baseURL = "https://nft.api.infura.io" const baseURL = "https://nft.api.infura.io"
type NFTOwner struct { type CollectibleOwner struct {
ContractAddress common.Address `json:"tokenAddress"` ContractAddress common.Address `json:"tokenAddress"`
TokenID *bigint.BigInt `json:"tokenId"` TokenID *bigint.BigInt `json:"tokenId"`
Amount *bigint.BigInt `json:"amount"` Amount *bigint.BigInt `json:"amount"`
OwnerAddress common.Address `json:"ownerOf"` OwnerAddress common.Address `json:"ownerOf"`
} }
type NFTContractOwnership struct { type CollectibleContractOwnership struct {
Owners []NFTOwner `json:"owners"` Owners []CollectibleOwner `json:"owners"`
Network string `json:"network"` Network string `json:"network"`
Cursor string `json:"cursor"` Cursor string `json:"cursor"`
} }
type Client struct { type Client struct {
thirdparty.NFTContractOwnershipProvider thirdparty.CollectibleContractOwnershipProvider
client *http.Client client *http.Client
apiKey string apiKey string
apiKeySecret string apiKeySecret string
@ -71,8 +71,8 @@ func (o *Client) IsChainSupported(chainID uint64) bool {
return false return false
} }
func infuraOwnershipToCommon(contractAddress common.Address, ownersMap map[common.Address][]NFTOwner) (*thirdparty.NFTContractOwnership, error) { func infuraOwnershipToCommon(contractAddress common.Address, ownersMap map[common.Address][]CollectibleOwner) (*thirdparty.CollectibleContractOwnership, error) {
owners := make([]thirdparty.NFTOwner, 0, len(ownersMap)) owners := make([]thirdparty.CollectibleOwner, 0, len(ownersMap))
for ownerAddress, ownerTokens := range ownersMap { for ownerAddress, ownerTokens := range ownersMap {
tokenBalances := make([]thirdparty.TokenBalance, 0, len(ownerTokens)) tokenBalances := make([]thirdparty.TokenBalance, 0, len(ownerTokens))
@ -84,13 +84,13 @@ func infuraOwnershipToCommon(contractAddress common.Address, ownersMap map[commo
}) })
} }
owners = append(owners, thirdparty.NFTOwner{ owners = append(owners, thirdparty.CollectibleOwner{
OwnerAddress: ownerAddress, OwnerAddress: ownerAddress,
TokenBalances: tokenBalances, TokenBalances: tokenBalances,
}) })
} }
ownership := thirdparty.NFTContractOwnership{ ownership := thirdparty.CollectibleContractOwnership{
ContractAddress: contractAddress, ContractAddress: contractAddress,
Owners: owners, Owners: owners,
} }
@ -98,9 +98,9 @@ func infuraOwnershipToCommon(contractAddress common.Address, ownersMap map[commo
return &ownership, nil return &ownership, nil
} }
func (o *Client) FetchNFTOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.NFTContractOwnership, error) { func (o *Client) FetchCollectibleOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*thirdparty.CollectibleContractOwnership, error) {
cursor := "" cursor := ""
ownersMap := make(map[common.Address][]NFTOwner) ownersMap := make(map[common.Address][]CollectibleOwner)
for { for {
url := fmt.Sprintf("%s/networks/%d/nfts/%s/owners", baseURL, chainID, contractAddress.String()) url := fmt.Sprintf("%s/networks/%d/nfts/%s/owners", baseURL, chainID, contractAddress.String())
@ -121,7 +121,7 @@ func (o *Client) FetchNFTOwnersByContractAddress(chainID uint64, contractAddress
return nil, err return nil, err
} }
var infuraOwnership NFTContractOwnership var infuraOwnership CollectibleContractOwnership
err = json.Unmarshal(body, &infuraOwnership) err = json.Unmarshal(body, &infuraOwnership)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -381,7 +381,7 @@ func (o *Client) FetchAllAssetsByOwner(owner common.Address, cursor string, limi
return o.fetchAssets(queryParams, limit) return o.fetchAssets(queryParams, limit)
} }
func (o *Client) FetchAssetsByNFTUniqueID(uniqueIDs []thirdparty.NFTUniqueID, limit int) (*AssetContainer, error) { func (o *Client) FetchAssetsByNFTUniqueID(uniqueIDs []thirdparty.CollectibleUniqueID, limit int) (*AssetContainer, error) {
queryParams := url.Values{} queryParams := url.Values{}
for _, uniqueID := range uniqueIDs { for _, uniqueID := range uniqueIDs {

View File

@ -1,10 +1,5 @@
package thirdparty package thirdparty
import (
"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/services/wallet/bigint"
)
type HistoricalPrice struct { type HistoricalPrice struct {
Timestamp int64 `json:"time"` Timestamp int64 `json:"time"`
Value float64 `json:"close"` Value float64 `json:"close"`
@ -41,49 +36,6 @@ type MarketDataProvider interface {
FetchTokenDetails(symbols []string) (map[string]TokenDetails, error) FetchTokenDetails(symbols []string) (map[string]TokenDetails, error)
} }
type NFTUniqueID struct {
ContractAddress common.Address `json:"contractAddress"`
TokenID *bigint.BigInt `json:"tokenID"`
}
func (k *NFTUniqueID) HashKey() string {
return k.ContractAddress.String() + "+" + k.TokenID.String()
}
type NFTMetadata struct {
Name string `json:"name"`
Description string `json:"description"`
CollectionImageURL string `json:"collection_image"`
ImageURL string `json:"image"`
}
type NFTMetadataProvider interface {
CanProvideNFTMetadata(chainID uint64, id NFTUniqueID, tokenURI string) (bool, error)
FetchNFTMetadata(chainID uint64, id NFTUniqueID, tokenURI string) (*NFTMetadata, error)
}
type TokenBalance struct {
TokenID *bigint.BigInt `json:"tokenId"`
Balance *bigint.BigInt `json:"balance"`
}
type TokenBalancesPerContractAddress = map[common.Address][]TokenBalance
type NFTOwner struct {
OwnerAddress common.Address `json:"ownerAddress"`
TokenBalances []TokenBalance `json:"tokenBalances"`
}
type NFTContractOwnership struct {
ContractAddress common.Address `json:"contractAddress"`
Owners []NFTOwner `json:"owners"`
}
type NFTContractOwnershipProvider interface {
FetchNFTOwnersByContractAddress(chainID uint64, contractAddress common.Address) (*NFTContractOwnership, error)
IsChainSupported(chainID uint64) bool
}
type DataParsed struct { type DataParsed struct {
Name string `json:"name"` Name string `json:"name"`
ID string `json:"id"` ID string `json:"id"`