github.com/DapperCollectives/CAST/backend@v0.0.0-20230921221157-1350c8be7c96/main/cadence/float/transactions/create_event.cdc (about) 1 import FLOAT from 0xf8d6e0586b0a20c7 2 import FLOATVerifiers from 0xf8d6e0586b0a20c7 3 import NonFungibleToken from 0xf8d6e0586b0a20c7 4 import MetadataViews from 0xf8d6e0586b0a20c7 5 import GrantedAccountAccess from 0xf8d6e0586b0a20c7 6 7 transaction( 8 forHost: Address, 9 claimable: Bool, 10 name: String, 11 description: String, 12 image: String, 13 url: String, 14 transferrable: Bool, 15 timelock: Bool, 16 dateStart: UFix64, 17 timePeriod: UFix64, 18 secret: Bool, 19 secretPK: String, 20 limited: Bool, 21 capacity: UInt64, 22 initialGroups: [String], 23 flowTokenPurchase: Bool, 24 flowTokenCost: UFix64, 25 minimumBalanceToggle: Bool, 26 minimumBalance: UFix64 27 ) { 28 29 let FLOATEvents: &FLOAT.FLOATEvents 30 31 prepare(acct: AuthAccount) { 32 // SETUP COLLECTION 33 if acct.borrow<&FLOAT.Collection>(from: FLOAT.FLOATCollectionStoragePath) == nil { 34 acct.save(<- FLOAT.createEmptyCollection(), to: FLOAT.FLOATCollectionStoragePath) 35 acct.link<&FLOAT.Collection{NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection, FLOAT.CollectionPublic}> 36 (FLOAT.FLOATCollectionPublicPath, target: FLOAT.FLOATCollectionStoragePath) 37 } 38 39 // SETUP FLOATEVENTS 40 if acct.borrow<&FLOAT.FLOATEvents>(from: FLOAT.FLOATEventsStoragePath) == nil { 41 acct.save(<- FLOAT.createEmptyFLOATEventCollection(), to: FLOAT.FLOATEventsStoragePath) 42 acct.link<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic, MetadataViews.ResolverCollection}> 43 (FLOAT.FLOATEventsPublicPath, target: FLOAT.FLOATEventsStoragePath) 44 } 45 46 // SETUP SHARED MINTING 47 if acct.borrow<&GrantedAccountAccess.Info>(from: GrantedAccountAccess.InfoStoragePath) == nil { 48 acct.save(<- GrantedAccountAccess.createInfo(), to: GrantedAccountAccess.InfoStoragePath) 49 acct.link<&GrantedAccountAccess.Info{GrantedAccountAccess.InfoPublic}> 50 (GrantedAccountAccess.InfoPublicPath, target: GrantedAccountAccess.InfoStoragePath) 51 } 52 53 if forHost != acct.address { 54 let FLOATEvents = acct.borrow<&FLOAT.FLOATEvents>(from: FLOAT.FLOATEventsStoragePath) 55 ?? panic("Could not borrow the FLOATEvents from the signer.") 56 self.FLOATEvents = FLOATEvents.borrowSharedRef(fromHost: forHost) 57 } else { 58 self.FLOATEvents = acct.borrow<&FLOAT.FLOATEvents>(from: FLOAT.FLOATEventsStoragePath) 59 ?? panic("Could not borrow the FLOATEvents from the signer.") 60 } 61 } 62 63 execute { 64 var Timelock: FLOATVerifiers.Timelock? = nil 65 var SecretV2: FLOATVerifiers.SecretV2? = nil 66 var Limited: FLOATVerifiers.Limited? = nil 67 var MinimumBalance: FLOATVerifiers.MinimumBalance? = nil 68 var verifiers: [{FLOAT.IVerifier}] = [] 69 if timelock { 70 Timelock = FLOATVerifiers.Timelock(_dateStart: dateStart, _timePeriod: timePeriod) 71 verifiers.append(Timelock!) 72 } 73 if secret { 74 SecretV2 = FLOATVerifiers.SecretV2(_publicKey: secretPK) 75 verifiers.append(SecretV2!) 76 } 77 if limited { 78 Limited = FLOATVerifiers.Limited(_capacity: capacity) 79 verifiers.append(Limited!) 80 } 81 if minimumBalanceToggle { 82 MinimumBalance = FLOATVerifiers.MinimumBalance(_amount: minimumBalance) 83 verifiers.append(MinimumBalance!) 84 } 85 let extraMetadata: {String: AnyStruct} = {} 86 if flowTokenPurchase { 87 let tokenInfo = FLOAT.TokenInfo(_path: /public/flowTokenReceiver, _price: flowTokenCost) 88 extraMetadata["prices"] = {"A.1654653399040a61.FlowToken.Vault": tokenInfo} 89 } 90 self.FLOATEvents.createEvent(claimable: claimable, description: description, image: image, name: name, transferrable: transferrable, url: url, verifiers: verifiers, extraMetadata, initialGroups: initialGroups) 91 log("Started a new event for host.") 92 } 93 }