Smart Contract
CounterContract
A.f5fc2c119a988722.CounterContract
1pub contract CounterContract {
2
3 pub let CounterStoragePath: StoragePath
4 pub let CounterPublicPath: PublicPath
5 pub event AddedCount(currentCount: UInt64)
6
7
8 pub resource interface HasCount {
9 pub fun currentCount(): UInt64
10 }
11
12 pub resource Counter: HasCount {
13
14 access(contract) var count: UInt64
15
16 init() {
17 self.count = 0
18 }
19
20 pub fun plusOne(hash: String) {
21 self.count = self.count + 1
22 }
23
24 pub fun currentCount(): UInt64 {
25 return self.count
26 }
27
28 }
29
30
31 pub fun currentCount(): UInt64 {
32 let counter = self.account.getCapability<&{HasCount}>(self.CounterPublicPath)
33 let counterRef = counter.borrow()!
34 return counterRef.currentCount()
35 }
36
37 // initializer
38 //
39 init() {
40
41
42 self.CounterStoragePath = /storage/testCounterPrivatePath
43 self.CounterPublicPath = /public/testCounterPublicPath
44
45 let counter <- create Counter()
46 self.account.save(<-counter, to: self.CounterStoragePath)
47 self.account.link<&{HasCount}>(self.CounterPublicPath, target: self.CounterStoragePath)
48 }
49}
50