Smart Contract
Admin
A.30cf5dcf6ea8d379.Admin
1import FungibleToken from 0xf233dcee88fe0abe
2import FUSD from 0x3c5959b568896393
3import NonFungibleToken from 0x1d7e57aa55817448
4import Debug from 0x30cf5dcf6ea8d379
5import Clock from 0x30cf5dcf6ea8d379
6import AeraNFT from 0x30cf5dcf6ea8d379
7import AeraPack from 0x30cf5dcf6ea8d379
8import AeraPackExtraData from 0x30cf5dcf6ea8d379
9import AeraPanels from 0x30cf5dcf6ea8d379
10import AeraRewards from 0x30cf5dcf6ea8d379
11import MetadataViews from 0x1d7e57aa55817448
12import FindViews from 0x097bafa4e0b48eef
13
14pub contract Admin {
15
16 //store the proxy for the admin
17 pub let AdminProxyPublicPath: PublicPath
18 pub let AdminProxyStoragePath: StoragePath
19 pub let AdminServerStoragePath: StoragePath
20 pub let AdminServerPrivatePath: PrivatePath
21 pub event BurnedPack(packId:UInt64, packTypeId:UInt64)
22
23
24 // This is just an empty resource to signal that you can control the admin, more logic can be added here or changed later if you want to
25 pub resource Server {
26
27 }
28
29 /// ===================================================================================
30 // Admin things
31 /// ===================================================================================
32
33 //Admin client to use for capability receiver pattern
34 pub fun createAdminProxyClient() : @AdminProxy {
35 return <- create AdminProxy()
36 }
37
38 //interface to use for capability receiver pattern
39 pub resource interface AdminProxyClient {
40 pub fun addCapability(_ cap: Capability<&Server>)
41 }
42
43
44 //admin proxy with capability receiver
45 pub resource AdminProxy: AdminProxyClient {
46
47 access(self) var capability: Capability<&Server>?
48
49 pub fun addCapability(_ cap: Capability<&Server>) {
50 pre {
51 cap.check() : "Invalid server capablity"
52 self.capability == nil : "Server already set"
53 }
54 self.capability = cap
55 }
56
57 pub fun registerGame(_ game: AeraNFT.Game) {
58 pre {
59 self.capability != nil: "Cannot create Admin, capability is not set"
60 }
61 AeraNFT.addGame(game)
62 }
63
64 pub fun registerPlayMetadata(_ play: AeraNFT.PlayMetadata) {
65 pre {
66 self.capability != nil: "Cannot create Admin, capability is not set"
67 }
68 AeraNFT.addPlayMetadata(play)
69 }
70
71 pub fun registerLicense(_ license: AeraNFT.License) {
72 pre {
73 self.capability != nil: "Cannot create Admin, capability is not set"
74 }
75 AeraNFT.addLicense(license)
76 }
77 pub fun registerPlayer(_ player: AeraNFT.Player) {
78 pre {
79 self.capability != nil: "Cannot create Admin, capability is not set"
80 }
81 AeraNFT.addPlayer(player)
82 }
83
84
85 pub fun mintAeraWithBadges(
86 recipient: &{NonFungibleToken.Receiver},
87 edition:UInt64,
88 play: AeraNFT.Play,
89 badges: [AeraNFT.Badge]
90 ){
91
92 pre {
93 self.capability != nil: "Cannot create Admin, capability is not set"
94 }
95
96 AeraNFT.mintNFT(recipient:recipient, edition: edition, play: play, badges: badges)
97 }
98
99
100 pub fun mintAera(
101 recipient: &{NonFungibleToken.Receiver},
102 edition:UInt64,
103 play: AeraNFT.Play,
104 ){
105
106 pre {
107 self.capability != nil: "Cannot create Admin, capability is not set"
108 }
109
110 AeraNFT.mintNFT(recipient:recipient, edition: edition, play: play, badges:[])
111 }
112
113 pub fun advanceClock(_ time: UFix64) {
114 pre {
115 self.capability != nil: "Cannot create Admin, capability is not set"
116 }
117 Debug.enable(true)
118 Clock.enable()
119 Clock.tick(time)
120 }
121
122
123 pub fun debug(_ value: Bool) {
124 pre {
125 self.capability != nil: "Cannot create Admin, capability is not set"
126 }
127 Debug.enable(value)
128 }
129
130
131 pub fun setPacksLeftForType(_ type:UInt64, amount:UInt64) {
132 pre {
133 self.capability != nil: "Cannot create Admin, capability is not set"
134 }
135
136 let packs = Admin.account.borrow<&AeraPack.Collection>(from: AeraPack.CollectionStoragePath)!
137 packs.setPacksLeftForType(type, amount: amount)
138
139 }
140
141 pub fun registerPackMetadata(typeId:UInt64, metadata:AeraPack.Metadata, items: Int, tier: String,receiverPath: String) {
142 pre {
143 self.capability != nil: "Cannot create Admin, capability is not set"
144 }
145 AeraPack.registerMetadata(typeId: typeId, metadata: metadata)
146 AeraPackExtraData.registerItemsForPackType(typeId:typeId, items:items)
147 AeraPackExtraData.registerTierForPackType(typeId:typeId, tier:tier)
148 AeraPackExtraData.registerReceiverPathForPackType(typeId:typeId, receiverPath:receiverPath)
149 }
150
151 pub fun batchMintPacks(typeId: UInt64, hashes:[String]) {
152 pre {
153 self.capability != nil: "Cannot create Admin, capability is not set"
154 }
155
156 let recipient=Admin.account.getCapability<&{NonFungibleToken.Receiver}>(AeraPack.CollectionPublicPath).borrow()!
157 for hash in hashes {
158 AeraPack.mintNFT(recipient:recipient, typeId: typeId, hash: hash)
159 }
160 }
161
162 pub fun requeue(packId:UInt64) {
163 pre {
164 self.capability != nil: "Cannot create Admin, capability is not set"
165 }
166
167 let cap= Admin.account.borrow<&AeraPack.Collection>(from: AeraPack.DLQCollectionStoragePath)!
168 cap.requeue(packId: packId)
169 }
170
171 pub fun fulfill(packId: UInt64, rewardIds:[UInt64], salt:String) {
172 pre {
173 self.capability != nil: "Cannot create Admin, capability is not set"
174 }
175 AeraPack.fulfill(packId: packId, rewardIds: rewardIds, salt: salt)
176 }
177
178 pub fun transfer(fromPath:String, toPath:String, ids:[UInt64]) {
179
180 pre {
181 self.capability != nil: "Cannot create Admin, capability is not set"
182 }
183 let sp = StoragePath(identifier: fromPath) ?? panic("Invalid path ".concat(fromPath))
184
185 let treasuryPath = PublicPath(identifier: toPath) ?? panic("Invalid toPath ".concat(toPath))
186 let collection = Admin.account.getCapability<&{NonFungibleToken.Receiver}>(treasuryPath).borrow() ?? panic("Could not borrow nft.cp at toPath ".concat(toPath).concat(" address ").concat(Admin.account.address.toString()))
187
188 self.sendNFT(storagePath: fromPath, recipient: collection, ids: ids)
189 }
190
191 pub fun sendNFT( storagePath: String, recipient: &{NonFungibleToken.Receiver}, ids:[UInt64]) {
192
193 pre {
194 self.capability != nil: "Cannot create Admin, capability is not set"
195 }
196
197 let sp = StoragePath(identifier: storagePath) ?? panic("Invalid path ".concat(storagePath))
198 let collection = Admin.account.borrow<&NonFungibleToken.Collection>(from: sp) ?? panic("Could not borrow collection at path ".concat(storagePath))
199 for id in ids {
200 recipient.deposit(token: <- collection.withdraw(withdrawID: id))
201 }
202 }
203
204 pub fun getAuthPointer(pathIdentifier: String, id: UInt64) : FindViews.AuthNFTPointer {
205 pre {
206 self.capability != nil: "Cannot create Admin, capability is not set"
207 }
208
209 let privatePath = PrivatePath(identifier: pathIdentifier)!
210 var cap = Admin.account.getCapability<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(privatePath)
211 if !cap.check() {
212 let storagePath = StoragePath(identifier: pathIdentifier)!
213 Admin.account.link<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(privatePath , target: storagePath)
214 cap = Admin.account.getCapability<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(privatePath)
215 }
216 return FindViews.AuthNFTPointer(cap: cap, id: id)
217 }
218
219 pub fun getProviderCapForPath(path:PrivatePath): Capability<&{NonFungibleToken.Provider, MetadataViews.ResolverCollection}> {
220 pre {
221 self.capability != nil: "Cannot create Admin, capability is not set"
222 }
223 return Admin.account.getCapability<&{NonFungibleToken.Provider, MetadataViews.ResolverCollection}>(path)
224 }
225
226 pub fun getProviderCap(): Capability<&{NonFungibleToken.Provider, MetadataViews.ResolverCollection}> {
227 pre {
228 self.capability != nil: "Cannot create Admin, capability is not set"
229 }
230 return Admin.account.getCapability<&{NonFungibleToken.Provider, MetadataViews.ResolverCollection}>(AeraNFT.CollectionPrivatePath)
231 }
232
233 pub fun burn( storagePath: String,ids:[UInt64]) {
234
235 pre {
236 self.capability != nil: "Cannot create Admin, capability is not set"
237 }
238
239 let sp = StoragePath(identifier: storagePath) ?? panic("Invalid path ".concat(storagePath))
240 let collection = Admin.account.borrow<&NonFungibleToken.Collection>(from: sp) ?? panic("Could not borrow collection at path ".concat(storagePath))
241 for id in ids {
242 let item <- collection.withdraw(withdrawID: id) as! @AeraPack.NFT
243 emit BurnedPack(packId:id, packTypeId:item.getTypeID())
244 destroy <- item
245 }
246 }
247
248 pub fun burnNFT(storagePath: String,ids:[UInt64]) {
249
250 pre {
251 self.capability != nil: "Cannot create Admin, capability is not set"
252 }
253
254 let sp = StoragePath(identifier: storagePath) ?? panic("Invalid path ".concat(storagePath))
255 let collection = Admin.account.borrow<&AeraNFT.Collection>(from: sp) ?? panic("Could not borrow collection at path ".concat(storagePath))
256 for id in ids {
257 collection.burn(id)
258 }
259 }
260
261 pub fun registerPanelTemplate(panel: AeraPanels.PanelTemplate, mint_count: UInt64?) {
262
263 pre {
264 self.capability != nil: "Cannot create Admin, capability is not set"
265 }
266 AeraPanels.addPanelTemplate(panel: panel, mint_count: mint_count)
267
268 }
269
270 pub fun registerChapterTemplate(_ chapter: AeraPanels.ChapterTemplate) {
271
272 pre {
273 self.capability != nil: "Cannot create Admin, capability is not set"
274 }
275 AeraPanels.addChapterTemplate(chapter)
276
277 }
278
279 pub fun mintAeraPanel(
280 recipient: &{NonFungibleToken.Receiver},
281 edition: UInt64,
282 panelTemplateId: UInt64
283 ) {
284 pre {
285 self.capability != nil: "Cannot create Admin, capability is not set"
286 }
287 AeraPanels.mintNFT(recipient: recipient, edition: edition, panelTemplateId: panelTemplateId)
288
289 }
290
291 pub fun registerRewardTemplate(reward: AeraRewards.RewardTemplate, maxQuantity: UInt64?) {
292
293 pre {
294 self.capability != nil: "Cannot create Admin, capability is not set"
295 }
296 AeraRewards.addRewardTemplate(reward: reward, maxQuantity: maxQuantity)
297
298 }
299
300 pub fun mintAeraReward(
301 recipient: &{NonFungibleToken.Receiver},
302 rewardTemplateId: UInt64,
303 rewardFields: {UInt64 : {String : String}}
304 ) : UInt64 {
305
306 pre {
307 self.capability != nil: "Cannot create Admin, capability is not set"
308 }
309
310 return AeraRewards.mintNFT(
311 recipient: recipient,
312 rewardTemplateId: rewardTemplateId,
313 rewardFields: rewardFields
314 )
315 }
316
317 init() {
318 self.capability = nil
319 }
320
321 }
322
323 init() {
324
325 self.AdminProxyPublicPath= /public/onefootballAdminProxy
326 self.AdminProxyStoragePath=/storage/onefootballAdminProxy
327
328 //create a dummy server for now, if we have a resource later we want to use instead of server we can change to that
329 self.AdminServerPrivatePath=/private/onefootballAdminServer
330 self.AdminServerStoragePath=/storage/onefootballAdminServer
331 self.account.save(<- create Server(), to: self.AdminServerStoragePath)
332 self.account.link<&Server>( self.AdminServerPrivatePath, target: self.AdminServerStoragePath)
333 }
334
335}
336