-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbidMarketDirectOfferSoft.cdc
85 lines (70 loc) · 4.81 KB
/
bidMarketDirectOfferSoft.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Profile from "../contracts/Profile.cdc"
import FindMarketDirectOfferSoft from "../contracts/FindMarketDirectOfferSoft.cdc"
import FindMarket from "../contracts/FindMarket.cdc"
import FungibleToken from "../contracts/standard/FungibleToken.cdc"
import NonFungibleToken from "../contracts/standard/NonFungibleToken.cdc"
import MetadataViews from "../contracts/standard/MetadataViews.cdc"
import FindViews from "../contracts/FindViews.cdc"
import FTRegistry from "../contracts/FTRegistry.cdc"
import FINDNFTCatalog from "../contracts/FINDNFTCatalog.cdc"
import FIND from "../contracts/FIND.cdc"
transaction(user: String, nftAliasOrIdentifier: String, id: UInt64, ftAliasOrIdentifier:String, amount: UFix64, validUntil: UFix64?) {
var targetCapability : Capability<&{NonFungibleToken.Receiver}>
let walletReference : &FungibleToken.Vault
let bidsReference: &FindMarketDirectOfferSoft.MarketBidCollection?
let balanceBeforeBid: UFix64
let pointer: FindViews.ViewReadPointer
let ftVaultType: Type
prepare(account: AuthAccount) {
let marketplace = FindMarket.getFindTenantAddress()
let resolveAddress = FIND.resolve(user)
if resolveAddress == nil {panic("The address input is not a valid name nor address. Input : ".concat(user))}
let address = resolveAddress!
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))
self.ftVaultType = ft.type
self.targetCapability= account.getCapability<&{NonFungibleToken.Receiver}>(nft.publicPath)
self.walletReference = account.borrow<&FungibleToken.Vault>(from: ft.vaultPath) ?? panic("No suitable wallet linked for this account")
let tenantCapability= FindMarket.getTenantCapability(marketplace)!
let tenant = tenantCapability.borrow()!
let receiverCap=account.getCapability<&{FungibleToken.Receiver}>(Profile.publicReceiverPath)
let dosBidType= Type<@FindMarketDirectOfferSoft.MarketBidCollection>()
let dosBidPublicPath=FindMarket.getPublicPath(dosBidType, name: tenant.name)
let dosBidStoragePath= FindMarket.getStoragePath(dosBidType, name:tenant.name)
let dosBidCap= account.getCapability<&FindMarketDirectOfferSoft.MarketBidCollection{FindMarketDirectOfferSoft.MarketBidCollectionPublic, FindMarket.MarketBidCollectionPublic}>(dosBidPublicPath)
if !dosBidCap.check() {
account.save<@FindMarketDirectOfferSoft.MarketBidCollection>(<- FindMarketDirectOfferSoft.createEmptyMarketBidCollection(receiver:receiverCap, tenantCapability:tenantCapability), to: dosBidStoragePath)
account.link<&FindMarketDirectOfferSoft.MarketBidCollection{FindMarketDirectOfferSoft.MarketBidCollectionPublic, FindMarket.MarketBidCollectionPublic}>(dosBidPublicPath, target: dosBidStoragePath)
}
self.bidsReference= account.borrow<&FindMarketDirectOfferSoft.MarketBidCollection>(from: dosBidStoragePath)
self.balanceBeforeBid=self.walletReference.balance
self.pointer= FindViews.createViewReadPointer(address: address, path:nft.publicPath, id: id)
/* Check for nftCapability */
if !self.targetCapability.check() {
let cd = self.pointer.getNFTCollectionData()
// should use account.type here instead
if account.type(at: cd.storagePath) != nil {
let pathIdentifier = nft.publicPath.toString()
let findPath = PublicPath(identifier: pathIdentifier.slice(from: "/public/".length , upTo: pathIdentifier.length).concat("_FIND"))!
account.link<&{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(
findPath,
target: nft.storagePath
)
self.targetCapability = account.getCapability<&{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(findPath)
} else {
account.save(<- cd.createEmptyCollection(), to: cd.storagePath)
account.link<&{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(cd.publicPath, target: cd.storagePath)
account.link<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(cd.providerPath, target: cd.storagePath)
}
}
}
pre {
self.bidsReference != nil : "This account does not have a bid collection"
self.walletReference.balance > amount : "Your wallet does not have enough funds to pay for this item"
}
execute {
self.bidsReference!.bid(item:self.pointer, amount: amount, vaultType: self.ftVaultType, nftCap: self.targetCapability, validUntil: validUntil, saleItemExtraField: {}, bidExtraField: {})
}
}