-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathico_template.py
103 lines (73 loc) · 2.69 KB
/
ico_template.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
NEX ICO Template
===================================
Author: Thomas Saunders
Email: tom@neonexchange.org
Date: Dec 11 2017
"""
from nex.txio import get_asset_attachments
from nex.token import *
from nex.crowdsale import *
from nex.nep5 import *
from boa.interop.Neo.Runtime import GetTrigger, CheckWitness
from boa.interop.Neo.TriggerType import Application, Verification
from boa.interop.Neo.Storage import *
ctx = GetContext()
NEP5_METHODS = ['name', 'symbol', 'decimals', 'totalSupply', 'balanceOf', 'transfer', 'transferFrom', 'approve', 'allowance']
def Main(operation, args):
"""
:param operation: str The name of the operation to perform
:param args: list A list of arguments along with the operation
:return:
bytearray: The result of the operation
"""
trigger = GetTrigger()
# This is used in the Verification portion of the contract
# To determine whether a transfer of system assets ( NEO/Gas) involving
# This contract's address can proceed
if trigger == Verification():
# check if the invoker is the owner of this contract
is_owner = CheckWitness(TOKEN_OWNER)
# If owner, proceed
if is_owner:
return True
# Otherwise, we need to lookup the assets and determine
# If attachments of assets is ok
attachments = get_asset_attachments()
return can_exchange(ctx, attachments, True)
elif trigger == Application():
for op in NEP5_METHODS:
if operation == op:
return handle_nep51(ctx, operation, args)
if operation == 'deploy':
return deploy()
elif operation == 'circulation':
return get_circulation(ctx)
# the following are handled by crowdsale
elif operation == 'mintTokens':
return perform_exchange(ctx)
elif operation == 'crowdsale_register':
return kyc_register(ctx, args)
elif operation == 'crowdsale_status':
return kyc_status(ctx, args)
elif operation == 'crowdsale_available':
return crowdsale_available_amount(ctx)
elif operation == 'get_attachments':
return get_asset_attachments()
return 'unknown operation'
return False
def deploy():
"""
:param token: Token The token to deploy
:return:
bool: Whether the operation was successful
"""
if not CheckWitness(TOKEN_OWNER):
print("Must be owner to deploy")
return False
if not Get(ctx, 'initialized'):
# do deploy logic
Put(ctx, 'initialized', 1)
Put(ctx, TOKEN_OWNER, TOKEN_INITIAL_AMOUNT)
return add_to_circulation(ctx, TOKEN_INITIAL_AMOUNT)
return False