Skip to content

Instantly share code, notes, and snippets.

@Ankarrr
Created March 12, 2018 07:20
Show Gist options
  • Save Ankarrr/49c3ef5048e321b955d2b47ddc1279e4 to your computer and use it in GitHub Desktop.
Save Ankarrr/49c3ef5048e321b955d2b47ddc1279e4 to your computer and use it in GitHub Desktop.
"""
NEX ICO Template
===================================
Author: Thomas Saunders
Email: [email protected]
Date: Dec 11 2017
"""
from boa_test.example.demo.nex.txio import get_asset_attachments
from boa_test.example.demo.nex.token import *
from boa_test.example.demo.nex.crowdsale import *
from boa_test.example.demo.nex.nep5 import *
from boa_test.example.demo.nex.dao 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']
DAO_METHODS = ['addProposal', 'voteforProposal', 'finalizeProposal']
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 False
# return can_exchange(ctx,attachments, True)
elif trigger == Application():
for op in DAO_METHODS:
if operation == op:
return handle_dao(ctx, operation, args)
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)
Put(ctx, TOTAL_PROPOSAL, 0)
return add_to_circulation(ctx, TOKEN_INITIAL_AMOUNT)
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment