Smart Contract
MotoGPCounter
A.a49cc0ee46c54bfb.MotoGPCounter
1import MotoGPAdmin from 0xa49cc0ee46c54bfb
2import ContractVersion from 0xa49cc0ee46c54bfb
3
4pub contract MotoGPCounter: ContractVersion {
5
6 pub fun getVersion(): String {
7 return "0.7.8"
8 }
9
10 access(self) let counterMap:{String:UInt64}
11
12 access(account) fun increment(_ key:String): UInt64 {
13 if self.counterMap.containsKey(key) {
14 self.counterMap[key] = self.counterMap[key]! + 1
15 } else {
16 self.counterMap[key] = 1
17 }
18 return self.counterMap[key]!
19 }
20
21 access(account) fun incrementBy(_ key:String, _ value:UInt64){
22 if self.counterMap.containsKey(key) {
23 self.counterMap[key] = self.counterMap[key]! + value
24 } else {
25 self.counterMap[key] = value
26 }
27 }
28
29 pub fun hasCounter(_ key:String): Bool {
30 return self.counterMap.containsKey(key)
31 }
32
33 pub fun getCounter(_ key:String): UInt64 {
34 return self.counterMap[key]!
35 }
36
37 init(){
38 self.counterMap = {}
39 }
40
41}