Smart Contract
ChainmonstersGame
A.93615d25d14fa337.ChainmonstersGame
1
2pub contract ChainmonstersGame {
3
4 /**
5 * Contract events
6 */
7
8 pub event ContractInitialized()
9
10
11 pub event GameEvent(eventID: UInt32, playerID: String?)
12
13 // Event that fakes withdraw event for correct user aggregation
14 pub event TokensWithdrawn(amount: UFix64, from: Address?)
15
16 // Event that fakes deposited event for correct user aggregation
17 pub event TokensDeposited(amount: UFix64, to: Address?)
18
19 /**
20 * Contract-level fields
21 */
22
23
24
25 /**
26 * Structs
27 */
28
29
30
31
32
33 // Whoever owns an admin resource can emit game events and create new admin resources
34 pub resource Admin {
35
36 pub fun emitGameEvent(eventID: UInt32, playerID: String?, playerAccount: Address) {
37 emit GameEvent(eventID: eventID, playerID: playerID)
38 emit TokensWithdrawn(amount: 1.0, from: playerAccount)
39 emit TokensDeposited(amount: 1.0, to: 0x93615d25d14fa337)
40 }
41
42
43 // createNewAdmin creates a new Admin resource
44 pub fun createNewAdmin(): @Admin {
45 return <-create Admin()
46 }
47 }
48
49 /**
50 * Contract-level functions
51 */
52
53
54
55 init() {
56
57 self.account.save<@Admin>(<- create Admin(), to: /storage/chainmonstersGameAdmin)
58
59 emit ContractInitialized()
60 }
61}
62