This repository has been archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcounter.vy
66 lines (55 loc) · 1.74 KB
/
counter.vy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Everything is in the same file, because Viper has no concept
# of imports (as of yet).
#
# To track the issue for "imports", see https://github.com/ethereum/vyper/issues/584
###
### INTERFACES / HELPERS
###
# Kernel interface
# See contracts/kernel/IKernel.sol
class Kernel():
# Checks whether `entity` has the role `role` on `app`.
def hasPermission(entity: address, app: address, role: bytes32) -> bool: pass
# Authentication helper
# See contracts/apps/App.sol
@internal
@constant
def auth(role: bytes32) -> bool:
# If no kernel is specified, then we're not being called
# through an app proxy, so for we'll just allow the transaction to pass
# for easier testing.
return not self.kernel or Kernel(self.kernel).hasPermission(msg.sender, self, role)
# Reference to the kernel (see ccontracts/apps/AppStorage.sol)
kernel: public(address)
# The application ID this app represents logic for (see ccontracts/apps/AppStorage.sol)
appId: public(bytes32)
# These methods ensure Solidity ABI compatibility
# Vyper creates different getters/setters (get_kernel, ...), but
# since we created Aragon using Solidity, we need to be backwards compatible
# in this way.
@public
@constant
def kernel() -> address:
return self.kernel
@public
def appId() -> bytes32:
return self.appId
###
### APPLICATION LOGIC
###
# The app itself is a simple counter app.
# You can increment a counter, or you can decrement it.
#
# The increment/decrement actions are governed by the ACL.
# Internal counter
value: public(num)
# Increment the internal counter
@public
def increment():
assert self.auth(sha3("increment"))
self.value += 1
# Decrement the internal counter
@public
def decrement():
assert self.auth(sha3("decrement"))
self.value -= 1