-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlistNFTForSale.cdc
70 lines (59 loc) · 3.84 KB
/
listNFTForSale.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import FindMarket from "../contracts/FindMarket.cdc"
import FindMarketSale from "../contracts/FindMarketSale.cdc"
import NonFungibleToken from "../contracts/standard/NonFungibleToken.cdc"
import MetadataViews from "../contracts/standard/MetadataViews.cdc"
import FindViews from "../contracts/FindViews.cdc"
import FINDNFTCatalog from "../contracts/FINDNFTCatalog.cdc"
import FTRegistry from "../contracts/FTRegistry.cdc"
transaction(nftAliasOrIdentifier: String, id: UInt64, ftAliasOrIdentifier: String, directSellPrice:UFix64, validUntil: UFix64?) {
let saleItems : &FindMarketSale.SaleItemCollection?
let pointer : FindViews.AuthNFTPointer
let vaultType : Type
prepare(account: AuthAccount) {
let marketplace = FindMarket.getFindTenantAddress()
let tenantCapability= FindMarket.getTenantCapability(marketplace)!
let saleItemType= Type<@FindMarketSale.SaleItemCollection>()
let tenant = tenantCapability.borrow()!
let publicPath=FindMarket.getPublicPath(saleItemType, name: tenant.name)
let storagePath= FindMarket.getStoragePath(saleItemType, name:tenant.name)
let saleItemCap= account.getCapability<&FindMarketSale.SaleItemCollection{FindMarketSale.SaleItemCollectionPublic, FindMarket.SaleItemCollectionPublic}>(publicPath)
if !saleItemCap.check() {
//The link here has to be a capability not a tenant, because it can change.
account.save<@FindMarketSale.SaleItemCollection>(<- FindMarketSale.createEmptySaleItemCollection(tenantCapability), to: storagePath)
account.link<&FindMarketSale.SaleItemCollection{FindMarketSale.SaleItemCollectionPublic, FindMarket.SaleItemCollectionPublic}>(publicPath, target: storagePath)
}
// Get supported NFT and FT Information from Registries from input alias
let collectionIdentifier = FINDNFTCatalog.getCollectionsForType(nftTypeIdentifier:nftAliasOrIdentifier)?.keys ?? panic("This NFT is not supported by the NFT Catalog yet. Type : ".concat(nftAliasOrIdentifier))
let collection = FINDNFTCatalog.getCatalogEntry(collectionIdentifier : collectionIdentifier[0])!
let nft = collection.collectionData
let ft = FTRegistry.getFTInfo(ftAliasOrIdentifier) ?? panic("This FT is not supported by the Find Market yet. Type : ".concat(ftAliasOrIdentifier))
var providerCap=account.getCapability<&{NonFungibleToken.Provider, MetadataViews.ResolverCollection, NonFungibleToken.CollectionPublic}>(nft.privatePath)
/* Ben : Question -> Either client will have to provide the path here or agree that we set it up for the user */
if !providerCap.check() {
let newCap = account.link<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(
nft.privatePath,
target: nft.storagePath
)
if newCap == nil {
// If linking is not successful, we link it using finds custom link
let pathIdentifier = nft.privatePath.toString()
let findPath = PrivatePath(identifier: pathIdentifier.slice(from: "/private/".length , upTo: pathIdentifier.length).concat("_FIND"))!
account.link<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(
findPath,
target: nft.storagePath
)
providerCap = account.getCapability<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(findPath)
}
}
// Get the salesItemRef from tenant
self.saleItems= account.borrow<&FindMarketSale.SaleItemCollection>(from: tenant.getStoragePath(Type<@FindMarketSale.SaleItemCollection>()))
self.pointer= FindViews.AuthNFTPointer(cap: providerCap, id: id)
self.vaultType= ft.type
}
pre{
self.saleItems != nil : "Cannot borrow reference to saleItem"
}
execute{
self.saleItems!.listForSale(pointer: self.pointer, vaultType: self.vaultType, directSellPrice: directSellPrice, validUntil: validUntil, extraField: {})
}
}