def Main(arg):

    if arg == 1:
        return Application()

    elif arg == 2:
        return Verification()

    elif arg == 3:

        if GetTrigger() == Application():
            return b'\x20'

    return -1
Exemple #2
0
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 is_owner

        # 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)

        elif operation == 'ico_sold':
            return get_ico_token_sold(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 == 'airdrop':
            return drop_tokens(ctx, args)

        return 'unknown operation'

    return False
Exemple #3
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        is_owner = CheckWitness(CONTRACT_OWNER)
        if is_owner:
            return True
        else:
            return False
    elif trigger == Application():
        sender = args[0]
        authorized = CheckWitness(sender)
        """
            Make sure that invoker is valid
        """
        if not authorized:
            Notify("Not authorized")
            return False
        Log("test")
        Notify(len(args))
        """
            query operations    
        """
        if operation == "sendMessage" and len(args) == 4:
            Notify("In operation sendMessage")
            return sendMessage(args)
        else:
            return False
    return False
Exemple #4
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        if CheckWitness(OWNER):
            return True

        return False

    elif trigger == Application():

        if operation == 'currentKing':
            return Get(ctx, KOTH_KEY)

        if operation == 'currentBounty':
            myhash = GetExecutingScriptHash()
            currentBalance = TUT_Contract('balanceOf', [myhash])
            current_bounty = currentBalance + INCREMENT
            return current_bounty

        chash = GetCallingScriptHash()
        if chash != TUT_Scripthash:
            print('Token type not accepted by this contract')
            return False

        elif operation == 'onTokenTransfer':
            print('onTokenTransfer() called')

            return handle_token_received(ctx, args)

    return False
def Main(operation, args):

    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():
        print("verification step")
        # check if the invoker is the owner of this contract
        is_owner = CheckWitness(TOKEN_OWNER)

        # If owner, proceed
        if is_owner:
            print("is owner")
            return True
        print("not owner")
        return False

    elif trigger == Application():

        for op in NEP5_METHODS:
            if operation == op:
                return handle_nep51(ctx, operation, args)

        if operation == 'setToken':
            return setToken(args[0], args[1])

        elif operation == 'bonusToken':
            return bonusToken(args[0], args[1])

        elif operation == 'minusToken':
            return minusToken(args[0], args[1])

        elif operation == 'getTime':
            return getCurrentTime()

        elif operation == "setProposal":
            # update:
            minusToken(args[1], args[4])
            return setProposal(args[0], args[1], args[2], args[3], args[4])

        elif operation == "getProposal":
            return getProposal(args[0])

        elif operation == "upVote":
            return upVote(args[0], args[1])

        elif operation == "downVote":
            return downVote(args[0], args[1])

        elif operation == "isExped":
            return isExped(args[0])

        elif operation == "isVoted":
            return isVoted(args[0], args[1])

        return 'unknown operation'

    return False
Exemple #6
0
def Main(operation, args):
    """
    :Entry point of Core_NA SmartContract:
    """

    trigger = GetTrigger()
    if trigger == Verification():
        # check if the invoker is the owner of this contract
        is_owner = CheckWitness(ROOT_ADMIN)
        # If owner, proceed
        if is_owner:
            return True
        return False
    elif trigger == Application():
        if operation == 'init':
            initialized = storage_load("Core_NASC_initialized")
            if not initialized:
                return init()

        root_na = storage_load("root_NA")
        if root_na:
            return DynamicAppCall(root_na, operation, args)
        else:
            Notify("DynamicAppCall failed.")
            return False
Exemple #7
0
def Main(operation, args):

    trigger = GetTrigger()
    if trigger == Verification():
        print("Verification")
        return CheckWitness(token_owner)

    if trigger == Application():
        if operation == "bet":
            if len(args) != 2 or args[1] == '':
                return False

            attachments = get_asset_attachments()
            sent_neo = attachments[2]
            sender = attachments[1]

            bet_id = args[0]
            option = args[1]

            print("sent_neo")
            print(sent_neo)

            if sent_neo > 0:
                bet(sender, bet_id, option, sent_neo)

            return True

    print("nothing matches")
    return False
def Main(operation, args):

    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)

        for op1 in NS_METHODS:
            if operation == op1:
                return handle_name_service(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 False
Exemple #9
0
def Main(operation, args):
    """
    This is the main entry point for the Smart Contract

    :param operation: the operation to be performed ( eg `balanceOf`, `transfer`, etc)
    :type operation: str
    :param args: a list of arguments ( which may be empty, but not absent )
    :type args: list
    :return: indicating the successful execution of the smart contract
    :rtype: bool
    """

    # The trigger determines whether this smart contract is being
    # run in 'verification' mode or 'application'

    trigger = GetTrigger()

    # 'Verification' mode is used when trying to spend assets ( eg NEO, Gas)
    # on behalf of this contract's address
    if trigger == Verification():

        # if the script that sent this is the owner
        # we allow the spend
        assert CheckWitness(OWNER), 'unauthorized'
        return True

    # 'Application' mode is the main body of the smart contract
    elif trigger == Application():

        if operation == 'name':
            return TOKEN_NAME

        elif operation == 'decimals':
            return TOKEN_DECIMALS

        elif operation == 'symbol':
            return TOKEN_SYMBOL

        elif operation == 'totalSupply':
            return TOKEN_TOTAL_SUPPLY

        elif operation == 'balanceOf':
            assert len(args) == 1, 'incorrect arg length'
            account = args[0]
            return do_balance_of(ctx, account)

        elif operation == 'transfer':
            assert len(args) == 3, 'incorrect arg length'
            t_from = args[0]
            t_to = args[1]
            t_amount = args[2]
            return do_transfer(ctx, t_from, t_to, t_amount,
                               GetCallingScriptHash())

        AssertionError('unknown operation')
Exemple #10
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        if CheckWitness(OWNER):
            return True

        return False

    elif trigger == Application():

        if operation == 'hello':
            print('hello world!')
            totalcalls = Get('totalCalls')
            totalcalls = totalcalls + 1
            print(totalcalls)
            if Put('totalCalls', totalcalls):
                return True
            print('staked storage call failed')
            return False

            return True

        if operation == 'ownerWithdraw':
            if not CheckWitness(OWNER):
                print(
                    'only the contract owner can withdraw MCT from the contract'
                )
                return False

            if len(args) != 1:
                print('withdraw amount not specified')
                return False

            t_amount = args[0]
            myhash = GetExecutingScriptHash()

            return MCTContract('transfer', [myhash, OWNER, t_amount])

        # end of normal invocations, reject any non-MCT invocations

        caller = GetCallingScriptHash()

        if caller != MCT_SCRIPTHASH:
            print('token type not accepted by this contract')
            return False

        if operation == 'onTokenTransfer':
            print('onTokenTransfer() called')
            return handle_token_received(caller, args)

    return False
Exemple #11
0
def Main(operation, args):
    """
    :Entry point of NA SmartContract:
    \n NA SmartContract has to conform to this conditions in final implementations:
    \n - configurated trough voting mechanism
    \n - pure dapp - belongs to community
    \n - open source 
    \n - updates managed by group of elected (by other community admins) 
    community admins, propably under control of CoZ if they are interested 
    """
    trigger = GetTrigger()
    if trigger == Verification():
        # check if the invoker is the owner of this contract
        if CheckWitness(ROOT_ADMIN):
            return True
        return False

    elif trigger == Application():
        if operation != None:
            
            if NA_service_initialized():
                # just for testing
                if operation == 'na_test':
                    Notify("Test Smart Contract Success!")
                    return "NASC is up!"
            
                for op in NEP5_methods:
                    if op == operation:
                        return NEP5_call(operation, args)
                
                for op in SMART_NEP5_METHODS:
                    if op == operation:
                        return smart_NEP5_call(operation, args)

                for op in NA_METHODS:
                    if op == operation:
                        return na_call(operation, args)
                
                nargs = len(args)
                if nargs >= 1:
                    alias = args[0]
                    args = list_slice(args,1,nargs)

                    return sc_call(alias,operation,args)
            else: 
                if operation == 'init':
                    return init_NA_service()
                Notify("NASC is not yet initialized.")
                return False

                
        return "Uknown operation"
Exemple #12
0
def Main(operation, addr, value):

    print("Running Sample v4")
    trigger = GetTrigger()
    print(trigger)

    # This determines that the SC is runnning in Verification mode
    # This determines whether the TX will be relayed to the rest of the network
    # The `Verification` portion of SC is *read-only*, so calls to `Storage.Put` will fail.
    # You can, however, use `Storage.Get`
    if trigger == Verification():

        print("Running Verification!")

        # This routine is: if the invoker ( or the Address that signed the contract ) is not OWNER,
        # Then we return False, and the TX will not be relayed to the network
        # Otherwise, we know the owner address signed the TX and return True
        is_owner = CheckWitness(OWNER)

        if is_owner:
            print("Is Owner!")
            return True

        print("Not Owner")

        return False

    elif trigger == Application():

        print("Running Application!")

        if not is_valid_addr(addr):
            print("Not Valid Address")
            return False

        ctx = GetContext()

        if operation == 'add':
            balance = Get(ctx, addr)
            new_balance = balance + value
            Put(ctx, addr, new_balance)
            return new_balance

        elif operation == 'remove':
            balance = Get(ctx, addr)
            Put(ctx, addr, balance - value)
            return balance - value

        elif operation == 'balance':
            return Get(ctx, addr)

    return False
Exemple #13
0
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()

    if trigger == Verification():

        is_owner = CheckWitness(TOKEN_OWNER)

        if is_owner:
            return True

        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)

        for op in TEAM_METHODS:
            if operation == op:
                return handle_team_operations(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, args)

        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)

        return 'unknown operation'
Exemple #14
0
def Main(operation, addr, group="", value=0):

	groups = {
	"elderly": [],
	"disabled": []
	}

	# Get trigger to determine interaction
	trigger = GetTrigger()

	# address of node that calls contract
	caller = addr

	# Used to spend assets on behalf of contract's address
	if trigger == Verification():
	
		if CheckWitness(OWNER):
			return True
	
		return False
	
	# Main body of Smart Contract
	elif trigger == Application():
		

		if operation == 'balance':
			return Get(ctx, addr)

		elif operation == 'register':

			groups[group] = groups[group].append(addr)

		elif operation == 'add':
			assert security_check()==True
	        balance = Get(ctx, addr)
	        new_balance = balance + value
	        Put(ctx, addr, new_balance)
	        return new_balance

    	elif operation == 'subtract':
			assert security_check()==True
	        balance = Get(ctx, addr)
	        Put(ctx, addr, balance - value)
	        return balance - value

		elif operation == 'totalSupply':
			return totalSupply()
Exemple #15
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        is_owner = CheckWitness(CONTRACT_OWNER)
        if is_owner:
            return True
        else:
            return False
    elif trigger == Application():
        if operation == "array":
            Notify("array")
            #31
            bigdata = 'In ac dui quis mi consectetuer '
            i = 0
            while i < 2200:
                bigdata = concat(bigdata, 'In ac dui quis mi consectetuer ')
                i = i + 1
            time = GetTime()
            data = [bigdata, time]
            result = Serialize(data)
            return result
        if operation == "dict":
            Notify("dict")
            j = 10
            d = {
                'a': 1,
                'b': 4,
                4: 'blah',
                'm': j,
                'z': [1, 3, 4, 5, 'abcd', j]
            }
            result = Serialize(d)
            return result
        if operation == "bool":
            Notify("array")
            #31
            bigdata = 'In ac dui quis mi consectetuer '
            time = GetTime()
            data = [False, True, False, True]
            result = Serialize(data)
            return result
        else:
            return False
    return False
Exemple #16
0
def Main(operation, args):
    """
    This is the main entry point for the Smart Contract

    :param operation: the operation to be performed ( eg `balanceOf`, `transfer`, etc)
    :type operation: str
    :param args: a list of arguments ( which may be empty, but not absent )
    :type args: list
    :return: indicating the successful execution of the smart contract
    :rtype: bool
    """

    # The trigger determines whether this smart contract is being
    # run in 'verification' mode or 'application'

    trigger = GetTrigger()

    # 'Verification' mode is used when trying to spend assets ( eg NEO, Gas)
    # on behalf of this contract's address
    if trigger == Verification():

        # if the script that sent this is the owner
        # we allow the spend
        is_owner = CheckWitness(OWNER)

        if is_owner:

            return True

        return False

    # 'Application' mode is the main body of the smart contract
    elif trigger == Application():
        for op in DEGREES:
            if operation == op:
                return handle_degrees(context, operation, args)

        if operation == 'deploy':
            deploy()

        result = 'unknown operation'

        return result

    return False
Exemple #17
0
def Main(operation, args):
    trigger = GetTrigger()

    if trigger == Verification():
        if CheckWitness(OWNER):
            return True

        return False

    elif trigger == Application():
        for op in NEP5_METHODS:
            if operation == op:
                return handle_token(ctx, operation, args)

        if operation == 'deploy':
            return deploy(ctx)

        elif operation == 'claimTokens':
            return claim_tokens(ctx)

        elif operation == 'vote':
            if len(args) == 2:
                return vote(ctx, args[0], args[1])

        elif operation == 'getVote':
            if len(args) == 1:
                return get_vote(ctx, args[0])

        elif operation == 'getData':
            return get_data(ctx)

        elif operation == 'putData':
            if len(args) == 1:
                return put_data(ctx, args[0])

        elif operation == 'deleteData':
            return delete_data(ctx)

        elif operation == 'withdraw':
            if len(args) == 1:
                return withdraw(ctx, args[0])

        return 'unknown operation'
Exemple #18
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():

        if CheckWitness(TOKEN_OWNER):
            return True

        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':
            deploy()

        if operation == 'circulation':
            get_circulation(ctx)

        if operation == 'mintTokens':
            pass

        if operation == 'crowdsale_register ':
            kyc_register(ctx, args)

        if operation == 'crowdsale_status ':
            kyc_status(ctx, args)

        if operation == 'crowdsale_avaiable ':
            crowdsale_available_amount(ctx)

        if operation == 'get_attachements ':
            get_asset_attachments()

        return 'Unknown operation'

    return False
Exemple #19
0
def Main(operation, arguments):
    print("Running DNS contract v1")
    trigger = GetTrigger()

    if len(arguments) < 1 or (operation == 'put' and len(arguments) < 2):
        return False

    if not is_valid_addr(arguments[0]):
        return False

    # This determines that the SC is running in Verification mode
    # This determines whether the TX will be relayed to the rest of the network
    # The `Verification` portion of SC is *read-only*, so calls to `Storage.Put` will fail.
    # You can, however, use `Storage.Get`
    if trigger == Verification():

        print("Running Verification!")
        if operation == 'put' or operation == 'delete':
            return CheckWitness(arguments[0])
        elif operation == 'get':
            return True

        return False

    elif trigger == Application():

        print("Running Application!")

        ctx = GetContext()

        if operation == 'put':
            Put(ctx, arguments[0], arguments[1])
            return True
        elif operation == 'get':
            return Get(ctx, arguments[0])
        elif operation == 'delete':
            Delete(ctx, arguments[0])
            return True

        return False

    return False
Exemple #20
0
def Main(operation, arguments):

    # Get the contract trigger type
    trigger = GetTrigger()

    # Contract transaction
    if trigger == Verification():

        return False

    # Invocation transaction
    elif trigger == Application():

        # User says hello
        if operation == 'hello':

            return greetings(arguments)

        # Requested method is not implemented
        print('Invalid operation')
        return False
Exemple #21
0
def Main(method, args):
    trigger = GetTrigger()

    #The 'correct' usage of this project would be using a correct implemented Verification Trigger;
    #Since the tools doesn't permit to test this, we are sending the transactions directly to the ownders
    if trigger == Verification():
        return CheckWitness(OWNER)

    elif trigger == Application():
        Log("met:" + method)
        if method == "name":
            return name()
        elif method == "readDomain":
            return readDomain(args[0])
        elif method == "listDomains":
            return listDomains(args[0])
        elif method == "registerDomain":
            return registerDomain(args[0], args[1])
        elif method == "saveMeta":
            return saveMeta(args[0], args[1], args[2])
        elif method == "addSlaveAsMaster":
            return addSubaccountAsMaster(args[0], args[1], args[2], args[3])
        elif method == "addDomainAsSlave":
            return addDomainAsSubaccount(args[0], args[1])
        elif method == "removeSlaveAsMaster":
            return removeSubaccountAsMaster(args[0], args[1], args[2])
        elif method == "transferDomain":
            return transferDomain(args[0], args[1], args[2])
        elif method == "createPendingTransaction":
            return createPendingTransaction(args[0], args[1], args[2], args[3])
        elif method == "readPendingTransaction":
            return readPendingTransaction(args[0], args[1])
        elif method == "removePendingTransaction":
            return removePendingTransaction(args[0], args[1], args[2])
        elif method == "completePendingTransaction":
            return completePendingTransaction(args[0], args[1], args[2])
        else:
            return False

    return False
def Main(operation, args):
    """
        :param operation: The name of the operation to perform
        :param args: A list of arguments along with the operation
        :type operation: str
        :type args: list
        :return: The result of the operation
        :rtype: bytearray
        """

    trigger = GetTrigger()
    if trigger == Verification():
        Notify("Verification")
        is_owner = CheckWitness(OWNER)

        if is_owner:
            return True
        else:
            return False

    elif trigger == Application():
        Notify("Application")

        if operation == 'create':
            return do_create(args)
        elif operation == 'transfer':
            return do_transfer(args)
        elif operation == 'info':
            return do_info(args)
        elif operation == 'delete':
            return do_delete_partnership(args)
        elif operation == 'set_partnership':
            return do_set_percentage_partnership(args)
        elif operation == 'set_flatfees':
            return do_set_flatfee_partnership(args)
        elif operation == 'set_webpage':
            return do_set_webpage(args)
        else:
            Notify('unknown operation')
            return False
Exemple #23
0
def Main(operation, addr, value):
	# Get trigger to determine interaction
	trigger = GetTrigger()

	# Used to spend assets on behalf of contract's address
	if trigger == Verification():
	
		if CheckWitness(OWNER):
			return True
	
		return False
	
	# Main body of Smart Contract
	elif trigger == Application():
		
		ctx = GetContext()

		if operation == 'balance':
			return Get(ctx, addr)

		elif operation == 'add':
			assert security_check()==True
		        balance = Get(ctx, addr)
	        	new_balance = balance + value
	        	Put(ctx, addr, new_balance)
	       		return new_balance

    		elif operation == 'remove':
			assert security_check()
			balance = Get(ctx, addr)
			Put(ctx, addr, balance - value)
			return balance - value

		elif operation == 'totalSupply':
			return totalSupply()

		return 'unknown operation'
Exemple #24
0
def Main(operation, args):
    """
    This is the main entry point for the Smart Contract

    :param operation: the operation to be performed ( eg `balanceOf`, `transfer`, etc)
    :type operation: str
    :param args: a list of arguments ( which may be empty, but not absent )
    :type args: list
    :return: indicating the successful execution of the smart contract
    :rtype: bool
    """

    # The trigger determines whether this smart contract is being
    # run in 'verification' mode or 'application'

    trigger = GetTrigger()

    # 'Verification' mode is used when trying to spend assets ( eg NEO, Gas)
    # on behalf of this contract's address
    if trigger == Verification():

        # if the script that sent this is the owner
        # we allow the spend
        is_owner = CheckWitness(OWNER)

        if is_owner:

            return True

        return False

    # 'Application' mode is the main body of the smart contract
    elif trigger == Application():

        if operation == 'name':
            n = TOKEN_NAME
            return n

        elif operation == 'decimals':
            d = DECIMALS
            return d

        elif operation == 'symbol':
            sym = SYMBOL
            return sym

        elif operation == 'totalSupply':
            supply = TOTAL_SUPPLY
            return supply

        elif operation == 'balanceOf':
            if len(args) == 1:
                account = args[0]
                balance = BalanceOf(account)
                return balance
            return 0

        elif operation == 'transfer':
            if len(args) == 3:
                t_from = args[0]
                t_to = args[1]
                t_amount = args[2]
                transfer = DoTransfer(t_from, t_to, t_amount)
                return transfer
            else:
                return False

        elif operation == 'transferFrom':
            if len(args) == 3:
                t_from = args[0]
                t_to = args[1]
                t_amount = args[2]
                transfer = DoTransferFrom(t_from, t_to, t_amount)
                return transfer
            return False

        elif operation == 'approve':
            if len(args) == 3:
                t_owner = args[0]
                t_spender = args[1]
                t_amount = args[2]
                approve = DoApprove(t_owner, t_spender, t_amount)
                return approve
            return False

        elif operation == 'allowance':
            if len(args) == 2:
                t_owner = args[0]
                t_spender = args[1]
                amount = GetAllowance(t_owner, t_spender)
                return amount
            return False

        elif operation == 'deploy':
            if len(args) == 4:
                seas = args[0]
                begin_bouns = args[1]
                bouns_interval = args[2]
                accept_coin = args[3]
                dp = DoDeploy(ctx, seas, begin_bouns, bouns_interval, accept_coin)
                return dp
            return False

        elif operation == 'mintTokens':
           mt = MintTokens(ctx) 
           return mt

        elif operation == 'bouns':
            if len(args) == 4:
                address = args[0]
                start_height = args[1]
                end_height = args[2]
                amount = args[3]
                result = DistributeBouns(ctx, address, start_height, end_height, amount)
                return result
            return False

        result = 'unknown operation'

        return result

    return False
Exemple #25
0
def Main(operation, args):
    """Entry point to the program

    :param str operation: The name of the operation to perform
    :param list args: A list of arguments along with the operation
    :return: The result of the operation
    :rtype: bytearray


    Token operations:

    - name(): returns name of token
    - symbol(): returns token symbol
    - totalSupply(): Returns the total token supply deployed in the
      system.
    - decimals(): Return decimalS
    - tokens(): Return enumerator with all tokens FEHLT
    - transfer(to, token_id, extra_arg): transfers a token
    - ownerOf(token_id): returns the owner of the specified token.
    - tokenURI(token_id): Returns a distinct Uniform Resource Identifier
        (URI) for a given asset.
        The URI data of a token supplies a reference to get more
        information about a specific token or its data.
    - balanceOf(owner): returns owner's current total tokens owned
    - tokensOfOwner(owner, starting_index): returns a dictionary that
        contains less than or equal to ten of the tokens owned by
        the specified address starting at the `starting_index`.

    - allowance(token_id): returns approved third-party spender of a
        token
    - approve(token_receiver, token_id, revoke): approve third party
        to spend a token
    - properties(token_id): returns a token's read-only data
    - supportedStandards(): returns a list of supported standards
        {"NEP-10"}
    - tokenData(token_id): returns a dictionary where token, property,
        and uri keys map to the corresponding data for the given
        `token_id`
    - tokensDataOfOwner(owner, starting_index): returns a dictionary
        that contains less than or equal to five of the tokens (where
        token, properties, and uri keys map to their corresponding data
        for each token id) owned by the specified address starting at
        the `starting_index`.
    - transferFrom(from, to, token_id, extra_arg): allows a third party
        to execute an approved transfer


    TOKEN_CONTRACT_OWNER operations:
        - mintToken(owner, properties, URI, extra_arg): create a new
            NFT token with the specified properties and URI and send it
            to the specified owner
        - modifyURI(token_id, token_data): modify specified token's
            URI data

        setters:
        - setName(name): sets the name of the token
        - setSymbol(symbol): sets the token's symbol
        - setSupportedStandards(supported_standards): sets the
            supported standards, 'NEP-10' is always the first element
            in the array
    """
    # The trigger determines whether this smart contract is being run
    # in 'verification' mode or 'application'
    trigger = GetTrigger()

    # 'Verification' mode is used when trying to spend assets
    # (eg NEO, Gas) on behalf of this contract's address
    if trigger == Verification():

        # if the script that sent this is the owner, we allow the spend
        if CheckWitness(TOKEN_CONTRACT_OWNER):
            return True

    elif trigger == Application():

        ctx = GetContext()

        if operation == 'name':
            name = Get(ctx, 'name')
            if name:
                return name
            else:
                return TOKEN_NAME

        elif operation == 'symbol':
            symbol = Get(ctx, 'symbol')
            if symbol:
                return symbol
            else:
                return TOKEN_SYMBOL

        elif operation == 'decimals':
            return TOKEN_DECIMALS

        elif operation == 'totalSupply':
            return Get(ctx, TOKEN_CIRC_KEY)

        if operation == 'allowance':
            if len(args) == 1:
                return Get(ctx, concat('approved/', args[0]))

            Notify(ARG_ERROR)
            return False

        elif operation == 'approve':
            if len(args) == 3:
                # GetCallingScriptHash() can't be done within the
                # function because the calling script hash changes
                # depending on where the function is called
                return do_approve(ctx, GetCallingScriptHash(), args[0],
                                  args[1], args[2])

            Notify(ARG_ERROR)
            return False

        elif operation == 'balanceOf':
            if len(args) == 1:
                if len(args[0]) == 20:
                    return Get(ctx, args[0])

                Notify(INVALID_ADDRESS_ERROR)
                return False

            Notify(ARG_ERROR)
            return False

        elif operation == 'ownerOf':
            if len(args) == 1:
                t_owner = Get(ctx, args[0])
                if len(t_owner) == 20:
                    return t_owner

                Notify(TOKEN_DNE_ERROR)
                return False

            Notify(ARG_ERROR)
            return False

        elif operation == 'properties':
            if len(args) == 1:
                token_properties = Get(ctx, concat('properties/', args[0]))
                if token_properties:
                    return token_properties

                Notify(TOKEN_DNE_ERROR)
                return False

            Notify(ARG_ERROR)
            return False

        elif operation == 'tokenData':
            if len(args) == 1:
                # check to make sure the token exists
                if len(Get(ctx, args[0])) == 20:
                    return Serialize(do_token_data(ctx, args[0]))

                Notify(TOKEN_DNE_ERROR)
                return False

            Notify(ARG_ERROR)
            return False

        elif operation == 'tokensDataOfOwner':
            if len(args) == 2:
                tokens_data_of_owner = do_tokens_data_of_owner(
                    ctx, args[0], args[1])
                if tokens_data_of_owner:
                    return Serialize(tokens_data_of_owner)

                return False

            Notify(ARG_ERROR)
            return False

        elif operation == 'tokensOfOwner':
            if len(args) == 2:
                tokens_of_owner = do_tokens_of_owner(ctx, args[0], args[1])
                if tokens_of_owner:
                    return Serialize(tokens_of_owner)

                return False

            Notify(ARG_ERROR)
            return False

        elif operation == 'transfer':
            if len(args) >= 2:
                # GetCallingScriptHash() can't be done within the
                # function because the calling script hash changes
                # depending on where the function is called
                return do_transfer(ctx, GetCallingScriptHash(), args)

            Notify(ARG_ERROR)
            return False

        elif operation == 'transferFrom':
            if len(args) >= 3:
                return do_transfer_from(ctx, args)

            Notify(ARG_ERROR)
            return False

        elif operation == 'uri':
            if len(args) == 1:
                token_uri = Get(ctx, concat('uri/', args[0]))
                if token_uri:
                    return token_uri

                Notify(TOKEN_DNE_ERROR)
                return False

            Notify(ARG_ERROR)
            return False

        # Administrative operations
        if CheckWitness(TOKEN_CONTRACT_OWNER):
            if operation == 'mintToken':
                if len(args) >= 3:
                    return do_mint_token(ctx, args)

                Notify(ARG_ERROR)
                return False

            elif operation == 'modifyURI':
                if len(args) == 2:
                    return do_modify_uri(ctx, args[0], args[1])

                Notify(ARG_ERROR)
                return False

            elif operation == 'setName':
                if len(args) == 1:
                    return do_set_config(ctx, 'name', args[0])

                Notify(ARG_ERROR)
                return False

            elif operation == 'setSymbol':
                if len(args) == 1:
                    return do_set_config(ctx, 'symbol', args[0])

                Notify(ARG_ERROR)
                return False

            elif operation == 'setSupportedStandards':
                if len(args) >= 1:
                    supported_standards = ['NEP-10']
                    for arg in args:
                        supported_standards.append(arg)

                    return do_set_config(ctx, 'supportedStandards',
                                         Serialize(supported_standards))

                Notify(ARG_ERROR)
                return False

        else:
            Notify(PERMISSION_ERROR)
            return False

        Notify('unknown operation')

    return False
Exemple #26
0
def Main(operation, args):
    """Entry point to the program

    :param str operation: The name of the operation to perform
    :param list args: A list of arguments along with the operation
    :return: The result of the operation
    :rtype: bytearray

    Token operations:
    - allowance(token_id): returns approved third-party spender of a
        token
    - approve(token_receiver, token_id, revoke): approve third party
        to spend a token
    - balanceOf(owner): returns owner's current total tokens owned
    - name(): returns name of token
    - decimals(): returns token decimal precision
    - ownerOf(token_id): returns the owner of the specified token.
    - properties(token_id): returns a token's read-only data
    - rwProperties(token_id): returns a token's read/write data
    - supportedStandards(): returns a list of supported standards
        {"NEP-10"}
    - symbol(): returns token symbol
    - token(token_id): returns a dictionary where token, property,
        and uri keys map to the corresponding data for the given
        `token_id`
    - tokensOfOwner(owner, starting_index): returns a dictionary that
        contains less than or equal to ten of the tokens owned by
        the specified address starting at the `starting_index`.
    - totalSupply(): Returns the total token supply deployed in the
        system.
    - transfer(to, token_id, extra_arg): transfers a token
    - transferFrom(spender, from, to, token_id): allows a third party
        to execute a pre-approved transfer
    - uri(token_id): Returns a distinct Uniform Resource Identifier
        (URI) for a given asset.
        The URI data of a token supplies a reference to get more
        information about a specific token or its data.

    TOKEN_CONTRACT_OWNER operations:
        - mintToken(owner, properties, URI, extra_arg): create a new
            NFT token with the specified properties and URI and send it
            to the specified owner
        - modifyURI(token_id, token_data): modify specified token's
            URI data

        setters:
        - setName(name): sets the name of the token
        - setSymbol(symbol): sets the token's symbol
        - setSupportedStandards(supported_standards): sets the
            supported standards, 'NEP-10' is always the first element
            in the array
    """
    # The trigger determines whether this smart contract is being run
    # in 'verification' mode or 'application'
    trigger = GetTrigger()

    # 'Verification' mode is used when trying to spend assets
    # (eg NEO, Gas) on behalf of this contract's address
    if trigger == Verification():

        # if the script that sent this is the owner, we allow the spend
        if CheckWitness(TOKEN_CONTRACT_OWNER):
            return True

    elif trigger == Application():

        # Need to get this at the top level
        caller = GetCallingScriptHash()
        ctx = GetContext()

        if operation == 'name':
            name = Get(ctx, 'name')
            if name:
                return name
            else:
                return TOKEN_NAME

        elif operation == 'symbol':
            symbol = Get(ctx, 'symbol')
            if symbol:
                return symbol
            else:
                return TOKEN_SYMBOL

        elif operation == 'supportedStandards':
            supported_standards = Get(ctx, 'supportedStandards')
            if supported_standards:
                return supported_standards
            else:
                return Serialize(['NEP-10'])

        elif operation == 'totalSupply':
            return Get(ctx, TOKEN_CIRC_KEY)

        elif operation == 'allowance':
            assert len(args) == 1, ARG_ERROR
            ownership = safe_deserialize(
                Get(ctx, concat('ownership/', args[0])))
            assert ownership, TOKEN_DNE_ERROR
            # don't fault here in case a calling contract is just checking allowance value
            if not has_key(ownership, 'approved'): return False
            if len(ownership['approved']) != 40: return False
            return ownership['approved']

        elif operation == 'balanceOf':
            assert len(args) == 1, ARG_ERROR
            assert len(args[0]) == 20, INVALID_ADDRESS_ERROR
            token_iter = Find(ctx, args[0])
            count = 0
            while token_iter.next():
                count += 1
            return count

        elif operation == 'ownerOf':
            assert len(args) == 1, ARG_ERROR
            ownership = safe_deserialize(
                Get(ctx, concat('ownership/', args[0])))
            assert ownership, TOKEN_DNE_ERROR
            assert has_key(ownership, 'owner'), TOKEN_DNE_ERROR
            assert len(ownership['owner']) == 20, TOKEN_DNE_ERROR
            return ownership['owner']

        elif operation == 'properties':
            assert len(args) == 1, ARG_ERROR
            return get_properties(ctx, args[0])

        elif operation == 'rwProperties':
            assert len(args) == 1, ARG_ERROR
            return get_rw_properties(ctx, args[0])

        elif operation == 'token':
            assert len(args) == 1, ARG_ERROR
            token = Get(ctx, concat('token/', args[0]))
            assert token, TOKEN_DNE_ERROR
            return token

        elif operation == 'tokensOfOwner':
            assert len(args) == 2, ARG_ERROR
            tokens_of_owner = do_tokens_of_owner(ctx, args[0], args[1])
            assert tokens_of_owner, 'address has no tokens'
            return Serialize(tokens_of_owner)

        elif operation == 'uri':
            assert len(args) == 1, ARG_ERROR
            token = safe_deserialize(Get(ctx, concat('token/', args[0])))
            assert token, TOKEN_DNE_ERROR
            assert has_key(token, 'uri'), TOKEN_DNE_ERROR
            return token['uri']

        elif operation == 'decimals':
            return TOKEN_DECIMALS

        #
        # User RW operations
        #

        if operation == 'approve':
            # args: from, spender, id, revoke
            # (NFT needs a fourth argument to revoke approval)
            assert len(args) > 2, ARG_ERROR
            assert args[2], TOKEN_DNE_ERROR
            return do_approve(ctx, caller, args)

        elif operation == 'transfer':
            assert len(args) > 1, ARG_ERROR
            return do_transfer(ctx, caller, args)

        elif operation == 'transferFrom':

            assert len(args) > 2, ARG_ERROR
            if len(args) == 3:
                # Nash-style (from, to, amount/id) transferFrom that can
                # be invoked only by whitelisted DEX to initiate a
                # pre-approved transfer

                return nash_do_transfer_from(ctx, caller, args)
            else:
                # Moonlight-style (spender, from, to, amount/id)
                # transfer where an authenticated spender/originator is
                # the only one who can initiate a transfer but can send
                # to an arbitrary third party (or themselves)

                return do_transfer_from(ctx, caller, args)

        #
        # dApp operations
        #
        if operation == 'setRWProperties':
            # args: token id, rwdata
            assert CheckWitness(DAPP_ADMIN), PERMISSION_ERROR
            assert len(args) == 2, ARG_ERROR
            return set_rw_properties(ctx, args[0], args[1])

        # Administrative operations
        if CheckWitness(TOKEN_CONTRACT_OWNER):
            if operation == 'mintToken':
                assert len(args) > 3, ARG_ERROR
                return do_mint_token(ctx, args)

            elif operation == 'modifyURI':
                assert len(args) == 2, ARG_ERROR
                return do_modify_uri(ctx, args)

            elif operation == 'setName':
                assert len(args) == 1, ARG_ERROR
                return do_set_config(ctx, 'name', args[0])

            elif operation == 'setSymbol':
                assert len(args) == 1, ARG_ERROR
                return do_set_config(ctx, 'symbol', args[0])

            elif operation == 'setSupportedStandards':
                assert len(args) >= 1, ARG_ERROR
                supported_standards = ['NEP-10']
                for arg in args:
                    supported_standards.append(arg)
                return do_set_config(ctx, 'supportedStandards',
                                     Serialize(supported_standards))

        AssertionError('unknown operation')
    return False
Exemple #27
0
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(get_owner_address(ctx))

        # 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()

        if attachments[4]:
            return False

        return can_exchange(ctx, attachments, True)

    elif trigger == Application():

        for op in NEP5_METHODS:
            if operation == op:
                return handle_nep51(ctx, operation, args)

        for op in MINING_METHODS:
            if operation == op:
                return handle_mining(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 == 'reallocate':
            return reallocate()

        elif operation == 'get_attachments':
            return get_asset_attachments()

        elif operation == 'supportedStandards':
            return ['NEP-5', 'NEP-10']

        elif operation == 'migrate':
            if len(args) != 9:
                return False
            if not CheckWitness(get_owner_address(ctx)):
                return False
            account = GetAccount(GetExecutingScriptHash())
            neo_balance = GetBalance(account, NEO)
            gas_balance = GetBalance(account, GAS)
            if neo_balance > 0:
                print("Cannot migrate yet.  Please transfer all neo/gas and tokens from contract address")
                return False
            if gas_balance > 0:
                print("Cannot migrate yet.  Please transfer all neo/gas and tokens from contract address")
                return False
            Migrate(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])
            return True

        elif operation == 'destroy':
            if not CheckWitness(get_owner_address(ctx)):   
                return False
            account = GetAccount(GetExecutingScriptHash())
            neo_balance = GetBalance(account, NEO)
            gas_balance = GetBalance(account, GAS)
            if neo_balance > 0:
                print("Cannot destroy yet.  Please transfer all neo/gas and tokens from contract address")
                return False
            if gas_balance > 0:
                print("Cannot destroy yet.  Please transfer all neo/gas and tokens from contract address")
                return False
            Destroy()
            return True
        
        elif operation == 'change_owner':
            if not CheckWitness(get_owner_address(ctx)):   
                return False
            if len(args) != 1:
                return False
            if not valid_address(args[0]):
                return False
            new_address = args[0]
            return set_owner_address(ctx, new_address)

        return 'unknown operation'

    return False
Exemple #28
0
def Main(operation, args):
    trigger = GetTrigger()

    if trigger == Verification():
        return CheckWitness(OWNER)

    if trigger == Application():
        nargs = len(args)

        if operation == 'createPublication':
            if nargs != 4:
                print('Required arguments: [sender] [name] [url] [category]')
                return [False, '4 arguments required']

            return CreatePublication(args)

        elif operation == 'deletePublication':
            if nargs != 2:
                print('Required arguments: [sender] [name]')
                return [False, '2 arguments required']

            return DeletePublication(args)

        elif operation == 'getUserPublications':
            if nargs != 1:
                print('Required arguments: [user]')
                return [False, '1 argument required']

            return GetUserPublications(args)

        elif operation == 'getNewPublications':
            # Cant evaluate 0 args

            return GetNewPublications()

        elif operation == 'getAuctionByMonth':
            if nargs != 3:
                print('Required arguments: [user] [name] [date]')
                return [False, '3 arguments required']

            return GetAuctionByMonth(args)

        elif operation == 'getAuctionByDate':
            if nargs != 3:
                print('Required arguments: [user] [name] [date]')
                return [False, '3 arguments required']

            return GetAuctionByDate(args)

        elif operation == 'placeNewBid':
            if nargs != 5:
                print(
                    'required arguments: [owner] [name] [date] [ad_url] [image_urls]'
                )
                return [False, '5 arguments required']

            return PlaceNewBid(args)

        elif operation == 'getAuctionWinner':
            if nargs != 3:
                print('Required arguments: [user] [name] [date]')
                return [False, '3 arguments required']

            return GetAuctionWinner(args)

        elif operation == 'getCurrentAuctionWinner':
            if nargs != 2:
                print('Required arguments: [user] [name]')
                return [False, '2 arguments required']

            return GetCurrentAuctionWinner(args)

        elif operation == 'getUserFunds':
            if nargs != 1:
                print('Required arguments: [user]')
                return [False, '1 arguments required']

            return GetUserFunds(args)

        elif operation == 'withdrawFunds':
            if nargs != 2:
                print('Required arguments: [sender] [amount]')
                return [False, '2 arguments required']

            return WithdrawFunds(args)

        elif operation == 'getWarpedTime':
            context = GetContext()

            return [True, getWarpedTime(context)]

        elif operation == 'setTimeMachine':
            if nargs != 1:
                print('Required arguments: [added_time]')
                return [False, '1 arguments required']

            return TimeMachine(args)

        elif operation == 'resetTimeMachine':
            return ResetTimeMachine()

    return [False, 'No operation selected']
Exemple #29
0
def Main(operation, args):
    """
    This is the main entry point for the dApp
    :param operation: the operation to be performed
    :type operation: str
    :param args: an optional list of arguments
    :type args: list
    :return: indicating the successful execution of the dApp
    :rtype: bool
    """
    trigger = GetTrigger()

    if trigger == Verification():

        # if the script that sent this is the owner
        # we allow the spend
        is_owner = CheckWitness(OWNER)

        if is_owner:
            return True

        return False

    elif trigger == Application():

        if operation == 'deploy':
            if len(args) == 6:
                dapp_name = args[0]
                oracle = args[1]
                time_margin = args[2]
                min_time = args[3]
                max_time = args[4]
                fee = args[5]
                d = Deploy(dapp_name, oracle, time_margin, min_time, max_time)

                Log("Dapp deployed")
                return d
            else:
                return False

        elif operation == 'name':
            context = GetContext()
            n = Get(context, 'dapp_name')
            return n

        elif operation == 'updateName':
            if len(args) == 1:
                new_name = args[0]
                n = UpdateName(new_name)
                Log("Name updated")
                return n

            else:
                return False

        elif operation == 'oracle':
            context = GetContext()
            o = Get(context, 'oracle')

            return o

        elif operation == 'updateOracle':
            if len(args) == 1:
                new_oracle = args[0]
                o = UpdateOracle(new_oracle)
                Log("Oracle updated")
                return o

            else:
                return False

        elif operation == 'time_margin':
            context = GetContext()
            time_margin = Get(context, 'time_margin')

            return time_margin

        elif operation == 'min_time':
            context = GetContext()
            min_time = Get(context, 'min_time')

            return min_time

        elif operation == 'max_time':
            context = GetContext()
            max_time = Get(context, 'max_time')

            return max_time

        elif operation == 'updateTimeLimits':
            if len(args) == 2:
                time_variable = args[0]
                value = args[1]
                t = UpdateTimeLimits(time_variable, value)
                Log("Time limits updated")
                return t

            else:
                return False

        elif operation == 'order':
            if len(args) == 13:
                # order_key = args[0]
                # timestamp = args[1]
                # src_currency = args[2]
                # dst_currency = args[3]
                # expire = args[4]
                # course = args[5]
                # amount = args[6]
                # src_wallet = args[7]
                # dst_wallet = args[8]
                # deposit_wallet = args[9]
                # dapp_name = args[11]
                # fee = args[12]

                o = Order(order_key, timestamp, src_currency, dst_currency,
                          expire, course, amount, src_wallet, dst_wallet,
                          deposit_wallet, dapp_name, fee)

                # TODO check if exchanges match
                Log("order added!")
                return o

            else:
                return False

        elif operation == 'resultNotice':
            if len(args) == 3:
                order_key = args[0]
                weather_param = args[1]
                oracle_cost = args[2]
                return ResultNotice(order_key, weather_param, oracle_cost)

            else:
                return False

        elif operation == 'deleteOrder':
            if len(args) == 1:
                order_key = args[0]
                return DeleteOrder(order_key)

            else:
                return False
        elif operation == 'match':
            if len(args) == 1:
                order_key = args[0]
                # TODO call match method
                return DoMatch(order_key)

            else:
                return False

        result = 'unknown operation'

        return result

    return False
Exemple #30
0
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()
        exchangeables = get_exchangeable(ctx, attachments[1], attachments[2],
                                         GetTime())
        return exchangeables[0] > 0

    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 == 'kyc_register':
            return kyc_register(ctx, args)

        elif operation == 'kyc_status':
            return kyc_status(ctx, args)

        elif operation == 'get_attachments':
            return get_asset_attachments()

        elif operation == 'get_config':
            if len(args) > 0:
                config_name = args[0]
                return get_config(ctx, config_name)

        elif operation == 'set_config':
            if not CheckWitness(TOKEN_OWNER):
                log = debug_log('Must be owner to update config')
                return False

            if len(args) == 2:
                config_name = args[0]
                config_value = args[1]
                set_config(ctx, config_name, config_value)
                return True

            return False

        elif operation == 'get_referrer':
            if len(args) > 0:
                address = args[0]
                return get_referrer(ctx, address)

            log = debug_log('Invalid arguments')
            return False

        elif operation == 'set_referrer':
            if not CheckWitness(TOKEN_OWNER):
                log = debug_log('Must be owner to update referrer')
                return False

            return set_referrer(ctx, args)

        elif operation == 'get_minted_tokens':
            if len(args) == 1:
                state = args[0]
                if state == IS_WHITELIST_SALE:
                    return get_minted_tokens(
                        ctx, STORAGE_PREFIX_PURCHASED_WHITELIST)
                if state == IS_PRESALE:
                    return get_minted_tokens(ctx,
                                             STORAGE_PREFIX_PURCHASED_PRESALE)
                if state == IS_CROWDSALE:
                    return get_minted_tokens(
                        ctx, STORAGE_PREFIX_PURCHASED_CROWDSALE)
                return 0
            return 0

        elif operation == 'get_contributed_neo':
            if len(args) == 2:
                state = args[0]
                address = args[1]
                if state == IS_WHITELIST_SALE:
                    return get_contributed_neo(
                        ctx, address, STORAGE_PREFIX_PURCHASED_WHITELIST)
                if state == IS_PRESALE:
                    return get_contributed_neo(
                        ctx, address, STORAGE_PREFIX_PURCHASED_PRESALE)
                if state == IS_CROWDSALE:
                    return get_contributed_neo(
                        ctx, address, STORAGE_PREFIX_PURCHASED_CROWDSALE)
                return 0
            return 0

        elif operation == 'get_affiliated_tokens':
            return get_affiliated_tokens(ctx)

        elif operation == 'get_exchangeable_amount':
            if len(args) == 3:
                sender_addr = args[0]
                sent_amount_neo = args[1]
                sending_time = args[2]
                exchangeables = get_exchangeable(ctx, sender_addr,
                                                 sent_amount_neo, sending_time)
                return exchangeables[0]

            log = debug_log('Invalid arguments')
            return 0

        elif operation == 'kyc_reject':
            return kyc_reject(ctx, args)

        elif operation == 'get_locked_until':
            if len(args) == 1:
                return get_locked_until(ctx, args[0])
            return 0

        return 'unknown operation'

    return False