TransactionSEALED

#@*@█^○◆@▫◆@@$&○%▪%▪%╱▪&!~■╳▪~?%▫●█●█■~!%●╳&▪■□▒○▫$●▪$░■╳@~~╱▫▒□

Transaction ID

Timestamp

Sep 05, 2024, 12:47:02 PM UTC
1y ago

Block Height

86,041,824

Computation

0

Proposerseq:13494 key:0

Authorizers

1

Transaction Summary

Transaction

Script Arguments

0listingResourceIDUInt64
82463373077107
1storefrontAddressAddress
2commissionRecipientAddress?

Cadence Script

1import FlowToken from 0x1654653399040a61
2import FungibleToken from 0xf233dcee88fe0abe
3import MetadataViews from 0x1d7e57aa55817448
4import NonFungibleToken from 0x1d7e57aa55817448
5import NFTStorefrontV2 from 0x4eb8a10cb9f87357
6
7    import HWGarageCard from 0xd0bcefdf1e67ea85
8    import HWGaragePack from 0xd0bcefdf1e67ea85
9    import HWGarageCardV2 from 0xd0bcefdf1e67ea85
10    import HWGaragePackV2 from 0xd0bcefdf1e67ea85
11    import HWGarageTokenV2 from 0xd0bcefdf1e67ea85
12  
13
14
15transaction(listingResourceID: UInt64, storefrontAddress: Address, commissionRecipient: Address?) {
16    let paymentVault: @{FungibleToken.Vault}
17    let HWGarageCardV2Collection: &{NonFungibleToken.Receiver}
18    let storefront: &{NFTStorefrontV2.StorefrontPublic}
19    let listing: &{NFTStorefrontV2.ListingPublic}
20    var commissionRecipientCap: Capability<&{FungibleToken.Receiver}>?
21
22    prepare(acct: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, Storage) &Account) {
23
24  
25
26        // HWGaragePack
27   let packCollectionData: MetadataViews.NFTCollectionData = HWGaragePack.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
28     ?? panic("ViewResolver does not resolve NFTCollectionData view")
29
30   // exit if packCollection exists
31   if acct.storage.borrow<&HWGaragePack.Collection>(from: packCollectionData.storagePath) == nil {
32     // create a new empty packCollection for HWGaragePack
33     let packCollection: @{NonFungibleToken.Collection} <- HWGaragePack.createEmptyCollection(nftType: Type<@HWGaragePack.NFT>())
34
35     // save HWGaragePack packCollection to the account
36     acct.storage.save(<-packCollection, to: packCollectionData.storagePath)
37
38     // create a public capability for the HWGaragePack packCollection
39     acct.capabilities.unpublish(packCollectionData.publicPath) // remove any current pubCap
40     let packCollectionCap: Capability<&HWGaragePack.Collection> = acct.capabilities.storage.issue<&HWGaragePack.Collection>(packCollectionData.storagePath)
41     acct.capabilities.publish(packCollectionCap, at: packCollectionData.publicPath)
42   }
43
44   // HWGarageCard
45   let cardCollectionData: MetadataViews.NFTCollectionData = HWGarageCard.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
46     ?? panic("ViewResolver does not resolve NFTCollectionData view")
47
48   // exit if cardCollection exists
49   if acct.storage.borrow<&HWGarageCard.Collection>(from: cardCollectionData.storagePath) == nil {
50     // create a new empty cardCollection for HWGarageCard
51     let cardCollection: @{NonFungibleToken.Collection} <- HWGarageCard.createEmptyCollection(nftType: Type<@HWGarageCard.NFT>())
52
53     // save HWGarageCard cardCollection to the account
54     acct.storage.save(<-cardCollection, to: cardCollectionData.storagePath)
55
56     // create a public capability for the HWGarageCard cardCollection
57     acct.capabilities.unpublish(cardCollectionData.publicPath) // remove any current pubCap
58     let cardCollectionCap: Capability<&HWGarageCard.Collection> = acct.capabilities.storage.issue<&HWGarageCard.Collection>(cardCollectionData.storagePath)
59     acct.capabilities.publish(cardCollectionCap, at: cardCollectionData.publicPath)
60   }
61
62   // HWGarageTokenV2
63   let tokenCollectionDataV2: MetadataViews.NFTCollectionData = HWGarageTokenV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
64     ?? panic("ViewResolver does not resolve NFTCollectionData view")
65
66   if acct.storage.borrow<&HWGarageTokenV2.Collection>(from: tokenCollectionDataV2.storagePath) == nil {
67     // create a new empty tokenCollection for HWGarageTokenV2
68     let tokenCollection: @{NonFungibleToken.Collection} <- HWGarageTokenV2.createEmptyCollection(nftType: Type<@HWGarageTokenV2.NFT>())
69
70     // save HWGarageTokenV2 tokenCollection to the account
71     acct.storage.save(<-tokenCollection, to: tokenCollectionDataV2.storagePath)
72
73     // create a public capability for the HWGarageTokenV2 tokenCollection
74     acct.capabilities.unpublish(tokenCollectionDataV2.publicPath) // remove any current pubCap
75     let tokenCollectionCap = acct.capabilities.storage.issue<&HWGarageTokenV2.Collection>(tokenCollectionDataV2.storagePath)
76     acct.capabilities.publish(tokenCollectionCap, at: tokenCollectionDataV2.publicPath)
77   }
78
79   // HWGarageCardV2
80   let cardCollectionDataV2: MetadataViews.NFTCollectionData = HWGarageCardV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
81     ?? panic("ViewResolver does not resolve NFTCollectionData view")
82
83   // exit if cardCollection exists
84   if acct.storage.borrow<&HWGarageCardV2.Collection>(from: cardCollectionDataV2.storagePath) == nil {
85     // create a new empty cardCollection for HWGarageCardV2
86     let cardCollection: @{NonFungibleToken.Collection} <- HWGarageCardV2.createEmptyCollection(nftType: Type<@HWGarageCardV2.NFT>())
87
88     // save HWGarageCardV2 cardCollection to the account
89     acct.storage.save(<-cardCollection, to: cardCollectionDataV2.storagePath)
90
91     // create a public capability for the HWGarageCardV2 cardCollection
92     acct.capabilities.unpublish(cardCollectionDataV2.publicPath) // remove any current pubCap
93     let cardCollectionCap = acct.capabilities.storage.issue<&HWGarageCardV2.Collection>(cardCollectionDataV2.storagePath)
94     acct.capabilities.publish(cardCollectionCap, at: cardCollectionDataV2.publicPath)
95   }
96
97   // HWGaragePackV2
98   let garagePackCollectionDataV2: MetadataViews.NFTCollectionData = HWGaragePackV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
99     ?? panic("ViewResolver does not resolve NFTCollectionData view")
100
101   // exit if packCollection exists
102   if acct.storage.borrow<&HWGaragePackV2.Collection>(from: garagePackCollectionDataV2.storagePath) == nil {
103     // create a new empty packCollection for HWGaragePackV2
104     let packCollection: @{NonFungibleToken.Collection} <- HWGaragePackV2.createEmptyCollection(nftType: Type<@HWGaragePackV2.NFT>())
105
106     // save HWGaragePackV2 packCollection to the account
107     acct.storage.save(<-packCollection, to: garagePackCollectionDataV2.storagePath)
108
109     // create a public capability for the HWGaragePackV2 packCollection
110     acct.capabilities.unpublish(garagePackCollectionDataV2.publicPath) // remove any current pubCap
111     let packCollectionCap = acct.capabilities.storage.issue<&HWGaragePackV2.Collection>(garagePackCollectionDataV2.storagePath)
112     acct.capabilities.publish(packCollectionCap, at: garagePackCollectionDataV2.publicPath)
113   }
114
115
116  
117        if acct.storage.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
118
119            // Create a new empty Storefront
120            let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
121
122            // save it to the account
123            acct.storage.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
124
125            // create a public capability for the Storefront
126            let storefrontPublicCap = acct.capabilities.storage.issue<&{NFTStorefrontV2.StorefrontPublic}>(
127                    NFTStorefrontV2.StorefrontStoragePath
128                )
129            acct.capabilities.publish(storefrontPublicCap, at: NFTStorefrontV2.StorefrontPublicPath)
130        }
131
132
133
134        self.commissionRecipientCap = nil
135        self.storefront = getAccount(storefrontAddress).capabilities.borrow<&{NFTStorefrontV2.StorefrontPublic}>(
136                NFTStorefrontV2.StorefrontPublicPath
137            ) ?? panic("Could not borrow Storefront from provided address")
138
139        // Borrow the listing
140        self.listing = self.storefront.borrowListing(listingResourceID: listingResourceID)
141                    ?? panic("No Offer with that ID in Storefront")
142        let price = self.listing.getDetails().salePrice
143
144        let mainFlowVault = acct.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
145            ?? panic("Cannot borrow FlowToken vault from acct storage")
146        // Access the vault of the buyer to pay the sale price of the listing.
147        self.paymentVault <- mainFlowVault.withdraw(amount: price)
148
149        let collectionData = HWGarageCardV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
150            ?? panic("ViewResolver does not resolve NFTCollectionData view")
151
152        // Access the buyer's NFT collection to store the purchased NFT.
153        self.HWGarageCardV2Collection = acct.capabilities.borrow<&{NonFungibleToken.Receiver}>(collectionData.publicPath)
154            ?? panic("Cannot borrow buyers Pack collection receiver")
155
156        let commissionAmount = self.listing.getDetails().commissionAmount
157
158        if commissionRecipient != nil && commissionAmount != 0.0 {
159            let _commissionRecipientCap = getAccount(commissionRecipient!).capabilities.get<&{FungibleToken.Receiver}>(
160               /public/flowTokenReceiver
161            )
162            // Access the capability to receive the commission.
163            assert(_commissionRecipientCap.check(), message: "Commission Recipient doesn't have FT receiving capability")
164            self.commissionRecipientCap = _commissionRecipientCap
165        } else if commissionAmount == 0.0 {
166            self.commissionRecipientCap = nil
167        } else {
168            panic("Commission recipient can not be empty when commission amount is non zero")
169        }
170    }
171
172    execute {
173        // Purchase the NFT
174        let item <- self.listing.purchase(
175            payment: <-self.paymentVault,
176            commissionRecipient: self.commissionRecipientCap
177        )
178        // Deposit the NFT in the buyer's collection.
179        self.HWGarageCardV2Collection.deposit(token: <-item)
180    }
181}