Contract currency


Contract Code
1 balances = Hash(default_value=0, contract='currency', name='balances')
2
3
4 def (vk: str):
5 balances[vk] = 288090567
6
7
8 @export('currency')
9 def transfer(amount: float, to: str):
10 assert amount > 0, 'Cannot send negative balances!'
11 sender = ctx.caller
12 assert balances[sender] >= amount, 'Not enough coins to send!'
13 balances[sender] -= amount
14 balances[to] += amount
15
16
17 @export('currency')
18 def balance_of(account: str):
19 return balances[account]
20
21
22 @export('currency')
23 def allowance(owner: str, spender: str):
24 return balances[owner, spender]
25
26
27 @export('currency')
28 def approve(amount: float, to: str):
29 assert amount > 0, 'Cannot send negative balances!'
30 sender = ctx.caller
31 balances[sender, to] += amount
32 return balances[sender, to]
33
34
35 @export('currency')
36 def transfer_from(amount: float, to: str, main_account: str):
37 assert amount > 0, 'Cannot send negative balances!'
38 sender = ctx.caller
39 assert balances[main_account, sender
40 ] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'.format(
41 balances[main_account, sender], amount)
42 assert balances[main_account] >= amount, 'Not enough coins to send!'
43 balances[main_account, sender] -= amount
44 balances[main_account] -= amount
45 balances[to] += amount
46

Twitter @tauhq_com