diff --git a/services/wallet/api.go b/services/wallet/api.go index d52c619b8..77211defe 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -332,6 +332,16 @@ func (api *API) GetOpenseaAssetsByOwnerWithCursor(ctx context.Context, chainID u return client.FetchAllAssetsByOwner(owner, cursor, limit) } +func (api *API) GetOpenseaAssetsByOwnerAndContractAddressWithCursor(ctx context.Context, chainID uint64, owner common.Address, contractAddresses []common.Address, cursor string, limit int) (*opensea.AssetContainer, error) { + log.Debug("call to GetOpenseaAssetsByOwnerAndContractAddressWithCursor") + client, err := opensea.NewOpenseaClient(chainID, api.s.openseaAPIKey) + if err != nil { + return nil, err + } + + return client.FetchAllAssetsByOwnerAndContractAddress(owner, contractAddresses, cursor, limit) +} + func (api *API) GetOpenseaAssetsByNFTUniqueID(ctx context.Context, chainID uint64, uniqueIDs []opensea.NFTUniqueID, limit int) (*opensea.AssetContainer, error) { log.Debug("call to GetOpenseaAssetsByNFTUniqueID") diff --git a/services/wallet/thirdparty/opensea/client.go b/services/wallet/thirdparty/opensea/client.go index 22c0c7122..024fd4674 100644 --- a/services/wallet/thirdparty/opensea/client.go +++ b/services/wallet/thirdparty/opensea/client.go @@ -216,6 +216,22 @@ func (o *Client) FetchAllAssetsByOwnerAndCollection(owner common.Address, collec return o.fetchAssets(queryParams, limit) } +func (o *Client) FetchAllAssetsByOwnerAndContractAddress(owner common.Address, contractAddresses []common.Address, cursor string, limit int) (*AssetContainer, error) { + queryParams := url.Values{ + "owner": {owner.String()}, + } + + for _, contractAddress := range contractAddresses { + queryParams.Add("asset_contract_addresses", contractAddress.String()) + } + + if len(cursor) > 0 { + queryParams["cursor"] = []string{cursor} + } + + return o.fetchAssets(queryParams, limit) +} + func (o *Client) FetchAllAssetsByOwner(owner common.Address, cursor string, limit int) (*AssetContainer, error) { queryParams := url.Values{ "owner": {owner.String()}, @@ -246,8 +262,8 @@ func (o *Client) fetchAssets(queryParams url.Values, limit int) (*AssetContainer assets.PreviousCursor = queryParams["cursor"][0] } - tmpLimit := limit - if AssetLimit < limit { + tmpLimit := AssetLimit + if limit > 0 && limit < tmpLimit { tmpLimit = AssetLimit } @@ -283,7 +299,7 @@ func (o *Client) fetchAssets(queryParams url.Values, limit int) (*AssetContainer queryParams["cursor"] = []string{assets.NextCursor} - if len(assets.Assets) >= limit { + if limit > 0 && len(assets.Assets) >= limit { break } }