-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency.py
60 lines (46 loc) · 1.56 KB
/
currency.py
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
# TODO - Update basetoken to whatever the first TRC_20 currency standard is
balances = Hash(default_value=0)
token_name = Variable()
token_symbol = Variable()
# Cannot set breakpoint in @construct
@construct
def seed(s_name:str, s_symbol: str, vk: str, vk_amount: int):
# Overloading this to mint tokens
token_name.set(s_name)
token_symbol.set(s_symbol)
balances[vk] = vk_amount
@export
def token_name():
return token_name.get()
@export
def token_symbol():
return token_symbol.get()
@export
def transfer(amount: float, to: str):
assert amount > 0, 'Cannot send negative balances!'
sender = ctx.caller
assert balances[sender] >= amount, 'Not enough coins to send!'
balances[sender] -= amount
balances[to] += amount
@export
def balance_of(account: str):
return balances[account]
@export
def main_balance_of(main_account: str, account: str):
return balances[main_account, account]
@export
def allowance(owner: str, spender: str):
return balances[owner, spender]
@export
def approve(amount: float, to: str):
assert amount > 0, 'Cannot send negative balances!'
sender = ctx.caller
balances[sender, to] += amount
return balances[sender, to]
@export
def transfer_from(amount: float, from_address: str, to_address: str):
assert amount > 0, 'Cannot send negative balances!'
assert balances[from_address] > amount, 'Cannot send amount greater than balance!'
# TODO - A1 - Trying to understand this currency.py vs. function in general...
balances[from_address] -= amount
balances[to_address] += amount