feat: implemented openseaV2 api changes
This commit is contained in:
parent
544e2ea76f
commit
addf6e4aaf
|
@ -126,6 +126,7 @@ func NewService(
|
||||||
}
|
}
|
||||||
|
|
||||||
collectionDataProviders := []thirdparty.CollectionDataProvider{
|
collectionDataProviders := []thirdparty.CollectionDataProvider{
|
||||||
|
openseaV2Client,
|
||||||
alchemyClient,
|
alchemyClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,3 +231,79 @@ func (o *ClientV2) fetchDetailedAssets(uniqueIDs []thirdparty.CollectibleUniqueI
|
||||||
|
|
||||||
return assets, nil
|
return assets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *ClientV2) fetchContractDataByContractID(id thirdparty.ContractID) (*ContractData, error) {
|
||||||
|
path := fmt.Sprintf("chain/%s/contract/%s", chainIDToChainString(id.ChainID), id.Address.String())
|
||||||
|
url, err := o.urlGetter(id.ChainID, path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := o.client.doGetRequest(url, o.apiKey)
|
||||||
|
if err != nil {
|
||||||
|
o.connectionStatus.SetIsConnected(false)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.connectionStatus.SetIsConnected(true)
|
||||||
|
|
||||||
|
// if Json is not returned there must be an error
|
||||||
|
if !json.Valid(body) {
|
||||||
|
return nil, fmt.Errorf("invalid json: %s", string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
contract := ContractData{}
|
||||||
|
err = json.Unmarshal(body, &contract)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &contract, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ClientV2) fetchCollectionDataBySlug(chainID walletCommon.ChainID, slug string) (*CollectionData, error) {
|
||||||
|
path := fmt.Sprintf("collections/%s", slug)
|
||||||
|
url, err := o.urlGetter(chainID, path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := o.client.doGetRequest(url, o.apiKey)
|
||||||
|
if err != nil {
|
||||||
|
o.connectionStatus.SetIsConnected(false)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.connectionStatus.SetIsConnected(true)
|
||||||
|
|
||||||
|
// if Json is not returned there must be an error
|
||||||
|
if !json.Valid(body) {
|
||||||
|
return nil, fmt.Errorf("invalid json: %s", string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
collection := CollectionData{}
|
||||||
|
err = json.Unmarshal(body, &collection)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &collection, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ClientV2) FetchCollectionsDataByContractID(contractIDs []thirdparty.ContractID) ([]thirdparty.CollectionData, error) {
|
||||||
|
ret := make([]thirdparty.CollectionData, 0, len(contractIDs))
|
||||||
|
|
||||||
|
for _, id := range contractIDs {
|
||||||
|
contractData, err := o.fetchContractDataByContractID(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionData, err := o.fetchCollectionDataBySlug(id.ChainID, contractData.Collection)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, collectionData.toCommon(id))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ const (
|
||||||
arbitrumMainnetString = "arbitrum"
|
arbitrumMainnetString = "arbitrum"
|
||||||
optimismMainnetString = "optimism"
|
optimismMainnetString = "optimism"
|
||||||
ethereumGoerliString = "goerli"
|
ethereumGoerliString = "goerli"
|
||||||
|
ethereumSepoliaString = "sepolia"
|
||||||
arbitrumGoerliString = "arbitrum_goerli"
|
arbitrumGoerliString = "arbitrum_goerli"
|
||||||
optimismGoerliString = "optimism_goerli"
|
optimismGoerliString = "optimism_goerli"
|
||||||
)
|
)
|
||||||
|
@ -38,6 +39,8 @@ func chainIDToChainString(chainID walletCommon.ChainID) string {
|
||||||
chainString = optimismMainnetString
|
chainString = optimismMainnetString
|
||||||
case walletCommon.EthereumGoerli:
|
case walletCommon.EthereumGoerli:
|
||||||
chainString = ethereumGoerliString
|
chainString = ethereumGoerliString
|
||||||
|
case walletCommon.EthereumSepolia:
|
||||||
|
chainString = ethereumSepoliaString
|
||||||
case walletCommon.ArbitrumGoerli:
|
case walletCommon.ArbitrumGoerli:
|
||||||
chainString = arbitrumGoerliString
|
chainString = arbitrumGoerliString
|
||||||
case walletCommon.OptimismGoerli:
|
case walletCommon.OptimismGoerli:
|
||||||
|
@ -74,6 +77,7 @@ type DetailedNFT struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url"`
|
||||||
|
AnimationURL string `json:"animation_url"`
|
||||||
MetadataURL string `json:"metadata_url"`
|
MetadataURL string `json:"metadata_url"`
|
||||||
Owners []OwnerV2 `json:"owners"`
|
Owners []OwnerV2 `json:"owners"`
|
||||||
Traits []TraitV2 `json:"traits"`
|
Traits []TraitV2 `json:"traits"`
|
||||||
|
@ -113,6 +117,28 @@ type TraitV2 struct {
|
||||||
Value TraitValue `json:"value"`
|
Value TraitValue `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContractData struct {
|
||||||
|
Address common.Address `json:"address"`
|
||||||
|
Chain string `json:"chain"`
|
||||||
|
Collection string `json:"collection"`
|
||||||
|
ContractStandard string `json:"contract_standard"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContractID struct {
|
||||||
|
Address common.Address `json:"address"`
|
||||||
|
Chain string `json:"chain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollectionData struct {
|
||||||
|
Collection string `json:"collection"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Owner common.Address `json:"owner"`
|
||||||
|
ImageURL string `json:"image_url"`
|
||||||
|
Contracts []ContractID `json:"contracts"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *NFT) id(chainID walletCommon.ChainID) thirdparty.CollectibleUniqueID {
|
func (c *NFT) id(chainID walletCommon.ChainID) thirdparty.CollectibleUniqueID {
|
||||||
return thirdparty.CollectibleUniqueID{
|
return thirdparty.CollectibleUniqueID{
|
||||||
ContractID: thirdparty.ContractID{
|
ContractID: thirdparty.ContractID{
|
||||||
|
@ -176,7 +202,7 @@ func (c *DetailedNFT) toCollectiblesData(chainID walletCommon.ChainID) thirdpart
|
||||||
Name: c.Name,
|
Name: c.Name,
|
||||||
Description: c.Description,
|
Description: c.Description,
|
||||||
ImageURL: c.ImageURL,
|
ImageURL: c.ImageURL,
|
||||||
AnimationURL: c.ImageURL,
|
AnimationURL: c.AnimationURL,
|
||||||
Traits: openseaV2ToCollectibleTraits(c.Traits),
|
Traits: openseaV2ToCollectibleTraits(c.Traits),
|
||||||
TokenURI: c.MetadataURL,
|
TokenURI: c.MetadataURL,
|
||||||
}
|
}
|
||||||
|
@ -188,3 +214,14 @@ func (c *DetailedNFT) toCommon(chainID walletCommon.ChainID) thirdparty.FullColl
|
||||||
CollectionData: nil,
|
CollectionData: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CollectionData) toCommon(id thirdparty.ContractID) thirdparty.CollectionData {
|
||||||
|
ret := thirdparty.CollectionData{
|
||||||
|
ID: id,
|
||||||
|
Provider: OpenseaV2ID,
|
||||||
|
Name: c.Name,
|
||||||
|
Slug: c.Collection,
|
||||||
|
ImageURL: c.ImageURL,
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue