Skip to content

Commit 12225e5

Browse files
committed
add setup to sell item transactions
1 parent 2a17e47 commit 12225e5

10 files changed

+63
-10
lines changed

scripts/has_listing_become_ghosted.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
1+
import "NFTStorefrontV2"
22

33
/// This script tells whether the provided `listingID` under the provided `storefront` address
44
/// has a ghost listing.

scripts/read_all_unique_ghost_listings.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
1+
import "NFTStorefrontV2"
22

33
/// This script provides the array of listing resource Id which got ghosted It automatically skips the duplicate listing
44
/// as duplicate listings would get automatically delete once the primary one.

scripts/read_allowed_commission_receivers.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
1+
import "NFTStorefrontV2"
22
import "FungibleToken"
33

44
/// This script returns the list of allowed commission receivers supported by the given listing Id.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
2-
import ExampleNFT from "../contracts/utility/ExampleNFT.cdc"
1+
import "NFTStorefrontV2"
32

43
/// This script returns an array of all the duplicate listingIDs for a given nftID.
54
///
6-
access(all) fun main(account: Address, nftID: UInt64, listingID: UInt64): [UInt64] {
5+
access(all) fun main(account: Address, nftID: UInt64, listingID: UInt64, nftTypeIdentifier: String): [UInt64] {
6+
let nftType = CompositeType(nftTypeIdentifier) ?? panic("Could not construct type from identifier ".concat(nftTypeIdentifier))
7+
78
return getAccount(account).capabilities.borrow<&{NFTStorefrontV2.StorefrontPublic}>(
89
NFTStorefrontV2.StorefrontPublicPath
9-
)?.getDuplicateListingIDs(nftType: Type<@ExampleNFT.NFT>(), nftID: nftID, listingID: listingID)
10+
)?.getDuplicateListingIDs(nftType: nftType, nftID: nftID, listingID: listingID)
1011
?? panic("Could not borrow public storefront from address")
1112
}

scripts/read_listing_details.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
1+
import "NFTStorefrontV2"
22

33
/// This script returns the details for a listing within a storefront
44
///

scripts/read_storefront_ids.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
1+
import "NFTStorefrontV2"
22

33
// This script returns an array of all the nft uuids for sale through a Storefront
44

tests/NFTStorefrontV2_test.cdc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ fun testBuyItem() {
186186
let allowedCommissionReceivers = scriptExecutor("read_allowed_commission_receivers.cdc", [seller.address, listingID])
187187
let listingDetails = scriptExecutor("read_listing_details.cdc", [seller.address, listingID])
188188
Test.assert(listingDetails != nil, message: "Received invalid result from reading listing details")
189-
let duplicateListingIDs = scriptExecutor("read_duplicate_listing_ids.cdc", [seller.address, listedNFTID, listingID])
189+
let duplicateListingIDs = scriptExecutor(
190+
"read_duplicate_listing_ids.cdc",
191+
[seller.address, listedNFTID, listingID, "A.0000000000000008.ExampleNFT.NFT"]
192+
)
190193
Test.assertEqual((duplicateListingIDs as! [UInt64]?)!.length, 0)
191194

192195
let code = loadCode("buy_item.cdc", "transactions")

transactions/sell_item.cdc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ transaction(
3333
var marketplacesCapability: [Capability<&{FungibleToken.Receiver}>]
3434

3535
prepare(acct: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, StorageCapabilities) &Account) {
36+
37+
// If the account doesn't already have a Storefront
38+
if acct.storage.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
39+
40+
// Create a new empty Storefront
41+
let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
42+
43+
// save it to the account
44+
acct.storage.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
45+
46+
// create a public capability for the Storefront
47+
let storefrontPublicCap = acct.capabilities.storage.issue<&{NFTStorefrontV2.StorefrontPublic}>(
48+
NFTStorefrontV2.StorefrontStoragePath
49+
)
50+
acct.capabilities.publish(storefrontPublicCap, at: NFTStorefrontV2.StorefrontPublicPath)
51+
}
52+
3653
self.saleCuts = []
3754
self.marketplacesCapability = []
3855

transactions/sell_item_and_replace_current_listing.cdc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ transaction(
3333
var marketplacesCapability: [Capability<&{FungibleToken.Receiver}>]
3434

3535
prepare(acct: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, StorageCapabilities) &Account) {
36+
// If the account doesn't already have a Storefront
37+
if acct.storage.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
38+
39+
// Create a new empty Storefront
40+
let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
41+
42+
// save it to the account
43+
acct.storage.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
44+
45+
// create a public capability for the Storefront
46+
let storefrontPublicCap = acct.capabilities.storage.issue<&{NFTStorefrontV2.StorefrontPublic}>(
47+
NFTStorefrontV2.StorefrontStoragePath
48+
)
49+
acct.capabilities.publish(storefrontPublicCap, at: NFTStorefrontV2.StorefrontPublicPath)
50+
}
51+
3652
self.saleCuts = []
3753
self.marketplacesCapability = []
3854

transactions/sell_item_with_marketplace_cut.cdc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ transaction(
3333

3434
prepare(acct: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, StorageCapabilities) &Account) {
3535

36+
// If the account doesn't already have a Storefront
37+
if acct.storage.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
38+
39+
// Create a new empty Storefront
40+
let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
41+
42+
// save it to the account
43+
acct.storage.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
44+
45+
// create a public capability for the Storefront
46+
let storefrontPublicCap = acct.capabilities.storage.issue<&{NFTStorefrontV2.StorefrontPublic}>(
47+
NFTStorefrontV2.StorefrontStoragePath
48+
)
49+
acct.capabilities.publish(storefrontPublicCap, at: NFTStorefrontV2.StorefrontPublicPath)
50+
}
51+
3652
self.saleCuts = []
3753
self.marketplacesCapability = []
3854

0 commit comments

Comments
 (0)