-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_metadata_from_storefront_listing-mainnet.cdc
54 lines (45 loc) · 1.79 KB
/
get_metadata_from_storefront_listing-mainnet.cdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import MetadataViews from 0x1d7e57aa55817448
import NFTStorefront from 0x4eb8a10cb9f87357
import RCRDSHPNFT from 0x6c3ff40b90b928ab
pub struct PurchaseData {
pub let id: UInt64
pub let name: String?
pub let amount: UFix64
pub let description: String?
pub let imageURL: String?
init(id: UInt64, name: String?, amount: UFix64, description: String?, imageURL: String?) {
self.id = id
self.name = name
self.amount = amount
self.description = description
self.imageURL = imageURL
}
}
pub fun main(address: Address, listingResourceID: UInt64): PurchaseData {
let account = getAccount(address)
let marketCollectionRef = account
.getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(
NFTStorefront.StorefrontPublicPath
)
.borrow()
?? panic("Could not borrow market collection from address")
let saleItem = marketCollectionRef.borrowListing(listingResourceID: listingResourceID)
?? panic("No item with that ID")
let listingDetails = saleItem.getDetails()!
let collection = account
.getCapability<&RCRDSHPNFT.Collection{RCRDSHPNFT.RCRDSHPNFTCollectionPublic}>(RCRDSHPNFT.collectionPublicPath)
.borrow()?? panic("Could not borrow a reference to the collection")
let nft = collection.borrowRCRDSHPNFT(id: listingDetails.nftID)!
if let view = nft.resolveView(Type<MetadataViews.Display>()) {
let display = view as! MetadataViews.Display
let purchaseData = PurchaseData(
id: listingDetails.nftID,
name: display.name,
amount: listingDetails.salePrice,
description: display.description,
imageURL: display.thumbnail.uri(),
)
return purchaseData
}
panic("No NFT")
}