-
Notifications
You must be signed in to change notification settings - Fork 0
/
claim.cdc
71 lines (58 loc) · 3.52 KB
/
claim.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
import FLOAT from "FLOAT"
import FLOATVerifiers from "FLOATVerifiers"
import NonFungibleToken from "NonFungibleToken"
import MetadataViews from "MetadataViews"
import GrantedAccountAccess from "GrantedAccountAccess"
import FlowToken from "FlowToken"
transaction(eventId: UInt64, host: Address, secretSig: String?) {
let FLOATEvent: &FLOAT.FLOATEvent{FLOAT.FLOATEventPublic}
let Collection: &FLOAT.Collection
let FlowTokenVault: &FlowToken.Vault
prepare(acct: AuthAccount) {
// SETUP COLLECTION
if acct.borrow<&FLOAT.Collection>(from: FLOAT.FLOATCollectionStoragePath) == nil {
acct.save(<- FLOAT.createEmptyCollection(), to: FLOAT.FLOATCollectionStoragePath)
acct.link<&FLOAT.Collection{NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection, FLOAT.CollectionPublic}>
(FLOAT.FLOATCollectionPublicPath, target: FLOAT.FLOATCollectionStoragePath)
}
// SETUP FLOATEVENTS
if acct.borrow<&FLOAT.FLOATEvents>(from: FLOAT.FLOATEventsStoragePath) == nil {
acct.save(<- FLOAT.createEmptyFLOATEventCollection(), to: FLOAT.FLOATEventsStoragePath)
acct.link<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic, MetadataViews.ResolverCollection}>
(FLOAT.FLOATEventsPublicPath, target: FLOAT.FLOATEventsStoragePath)
}
// SETUP SHARED MINTING
if acct.borrow<&GrantedAccountAccess.Info>(from: GrantedAccountAccess.InfoStoragePath) == nil {
acct.save(<- GrantedAccountAccess.createInfo(), to: GrantedAccountAccess.InfoStoragePath)
acct.link<&GrantedAccountAccess.Info{GrantedAccountAccess.InfoPublic}>
(GrantedAccountAccess.InfoPublicPath, target: GrantedAccountAccess.InfoStoragePath)
}
let FLOATEvents = getAccount(host).getCapability(FLOAT.FLOATEventsPublicPath)
.borrow<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic}>()
?? panic("Could not borrow the public FLOATEvents from the host.")
self.FLOATEvent = FLOATEvents.borrowPublicEventRef(eventId: eventId) ?? panic("This event does not exist.")
self.Collection = acct.borrow<&FLOAT.Collection>(from: FLOAT.FLOATCollectionStoragePath)
?? panic("Could not get the Collection from the signer.")
self.FlowTokenVault = acct.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow the FlowToken.Vault from the signer.")
}
execute {
let params: {String: AnyStruct} = {}
// If the FLOAT has a secret phrase on it
if let unwrappedSecretSig = secretSig {
params["secretSig"] = unwrappedSecretSig
}
// If the FLOAT costs something
if let prices = self.FLOATEvent.getPrices() {
log(prices)
let payment <- self.FlowTokenVault.withdraw(amount: prices[self.FlowTokenVault.getType().identifier]!.price)
self.FLOATEvent.purchase(recipient: self.Collection, params: params, payment: <- payment)
log("Purchased the FLOAT.")
}
// If the FLOAT is free
else {
self.FLOATEvent.claim(recipient: self.Collection, params: params)
log("Claimed the FLOAT.")
}
}
}