コード例 #1
0
def Main(operation, args):
    Log(args)

    trigger = GetTrigger()

    storage = StorageAPI()

    arg_error = 'Incorrect Arg Length'

    if trigger == Verification():
        # todo maybe implement later
        return True

    elif trigger == Application():
        if operation != None:
            if operation == "balance":
                if len(args) == 1:
                    account = args[0]
                    balance = storage.get(account)
                    return balance
                Log(arg_error)
                return arg_error
            if operation == "accrue":
                if len(args) == 2:
                    account = args[0],
                    gain = args[1]
                    new_balance = storage.get(account) + gain
                    return storage.put(account, new_balance)
                Log(arg_error)
            return arg_error
        return False
コード例 #2
0
ファイル: hunt.py プロジェクト: localhuman/neo-scavenger-hunt
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():

        if CheckWitness(owner):
            return True

        return False

    storage = StorageAPI()

    questions = Questions()
    questions.owner = owner

    if operation == 'get_clue':
        addr = get_addr(clue_gas_req)
        cluenum = args[0]
        return questions.get_clue(storage, cluenum, addr)

    elif operation == 'set_clue':
        cluenum = args[0]
        clueval = args[1]
        return questions.set_clue(storage, cluenum, clueval)

    elif operation == 'set_answer':
        cluenum = args[0]
        answer = args[1]
        return questions.set_answer(storage, cluenum, answer)

    elif operation == 'submit_answer':
        addr = get_addr(answer_gas_req)
        if len(args) < 2:
            return b'Not enough arguments'
        cluenum = args[0]
        answer = args[1]
        return questions.submit_answer(storage, cluenum, answer, addr)

    elif operation == 'total_questions':
        return total_q

    elif operation == 'progress':
        addr = get_addr(progress_gas_req)
        key = concat('progress_', addr)
        return storage.getitem(key)

    elif operation == 'total_winners':
        return storage.getitem('total_winners')

    elif operation == 'first_place':
        return storage.getitem('first_place')

    elif operation == 'second_place':
        return storage.getitem('second_place')

    elif operation == 'third_place':
        return storage.getitem('third_place')

    return b'Method not found'
コード例 #3
0
def Main(a, b, c, d):
    """

    :param a:
    :param b:
    :param c:
    :param d:
    :return:
    """
    print("Executing Four Param Verification code")
    trigger = GetTrigger()

    if trigger == Verification():

        print("Running verification")
        is_owner = CheckWitness(OWNER)
        Notify(is_owner)
        return is_owner

    print("runnig app routine")

    result = a + b - c + d

    Notify(result)

    return result
コード例 #4
0
def Main(operation, args):
    trigger = GetTrigger()
    OWNER = b'6b1410519d09f00bde5121bab0b56a6c916095b2'

    if trigger == Verification():

        print("doing verification!")
        owner_len = len(OWNER)

        if owner_len == 20:
            res = CheckWitness(OWNER)
            print("owner verify result")
            return res

    elif trigger == Application():
        if operation == 'name':
            n = Name()
            return n
    return False
コード例 #5
0
def Main(args):

    print("Do Withdraw Test")

    trigger = GetTrigger()

    if trigger == Verification():

        print("doing verification")

        return True

        # check to see if the withdrawer is the owner

        is_owner = CheckWitness(OWNER)

        # always allow owner to withdraw

        if is_owner:
            can_widthraw = CanClaimGas()
            return can_widthraw

        else:
            can_widthraw = CanWithdrawNeo()
            return can_widthraw

    elif trigger == Application():
        print("doing application")

        operation = args[0]

        if operation == 'hodl':
            print("Hodling engaged!")
            deposit = DepositNeo()

            return deposit

        elif operation == 'info':
            print("Info requested")
            return Description()

    return False
コード例 #6
0
def Main(bytes):

    trigger = GetTrigger()

    if trigger == Verification():
        print("Verification!")
        return False

    elif trigger == Application():
        print("Application!")
        i = 0
        l = len(bytes)
        while i < l:
            c = substr(bytes, i, 1)
            i = i + 1
            if c == 0:
                print("Null")
            else:
                print("Not null")
                return True
コード例 #7
0
def Main():
    """

    :return:
    """
    trigger = GetTrigger()

    Notify(trigger)

    if trigger == Application():
        print("application!")

    elif trigger == Verification():
        print("verification!")

    k = 10

    print("hello")

    return k
コード例 #8
0
def Main(a):

    trigger = GetTrigger()

    if trigger == Verification():

        if not CheckWitness(owner):

            print("not owner!!")
            return False

        return True

    elif trigger == Application():

        print("do some other thing")

        m = 3

        j = a + m

        return j

    return 3
コード例 #9
0
ファイル: krypton.py プロジェクト: Shootle/KRYPTON
def Main(operation, args):
    """
    Main definition for the KRYPTON smart contact

    :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 smart contract
    :rtype: bool
    """

    trigger = GetTrigger()

    if trigger == Verification():
        is_owner = CheckWitness(KRYPTON)

        if is_owner:
            return True

        return False

    elif trigger == Application():
        # Check the version for compatability
        if operation == 'version':
            version = VERSION
            Notify(version)
            return version

        # Let the provider deploy on the blockchain
        elif operation == 'deploy':
            if (len(args) == 2):
                # Read arguments
                provider = args[0]
                location = args[1]

                # Deploy the provider
                Log('FUNC_DEPLOY')
                deploy = Deploy(provider, location)
                return deploy

            else:
                Log('INVALID_ARGUMENTS')
                return False

        # Let the provider undeploy on the blockchain
        elif operation == 'undeploy':
            if (len(args) == 1):
                # Read arguments
                provider = args[0]

                # Undeploy the provider
                Log('FUNC_UNDEPLOY')
                undeploy = Undeploy(provider)
                return undeploy

            else:
                Log('INVALID_ARGUMENTS')
                return False

        # Let the user register to a provider
        elif operation == 'register':
            if (len(args) == 3):
                # Read arguments
                user = args[0]
                provider = args[1]
                uuid = args[2]

                # Register the user
                Log('FUNC_REGISTER')
                register = Register(user, provider, uuid)
                return register

            else:
                Log('INVALID_ARGUMENTS')
                return False

        # Let the user unregister to a provider
        elif operation == 'unregister':
            if (len(args) == 1):
                user = args[0]

                # Unregister the user
                Log('FUNC_UNREGISTER')
                unregister = Unregister(user)
                return unregister

            else:
                Log('INVALID_ARGUMENTS')
                return False

        # Query a user for UUID or provider
        elif operation == 'query':
            if (len(args) == 2):
                # Read arguments
                query = args[0]
                user = args[1]

                # Query the user for UUID or provider
                Log('FUNC_QUERY')
                queryuser = QueryUser(query, user)
                return queryuser

            else:
                Log('INVALID_ARGUMENTS')
                return False

        Log('INVALID_FUNCTION')
        return False

    Log('FORBIDDEN')
    return False
コード例 #10
0
def Main(operation, args):
    trigger = GetTrigger()

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

    elif trigger == Application():
        # seller action
        if operation == 'create':
            if len(args) == 8:
                creator = args[0]  # public key
                promo_id = args[1]
                title = args[2]
                description = args[3]
                price_per_person = args[4]  # price in GAS
                expiration = args[5]
                min_count = args[6]
                max_count = args[7]

                success = CreatePromo(creator, promo_id, title, description,
                                      price_per_person, expiration, min_count,
                                      max_count)

                if success:
                    Log('Promo created successfully')
                    return True
                else:
                    Log('Error in creating promo')
                    return False
            else:
                Log('incorrect number of arguments')
                return False

        # seller action
        elif operation == 'delete':
            if len(args) == 1:
                promo_id = args[0]

                authorize = IsPromoCreator(promo_id)
                if authorize:
                    success = DeletePromo(promo_id)
                    if success:
                        Log('Promo deleted successfully')
                        return True
                    else:
                        Log('Error in deleting promo')
                        return False
                else:
                    Log('Permission denied')
                    return False
            else:
                Log('incorrect number of arguments')
                return False

        # seller action
        elif operation == 'claim':
            if len(args) == 1:
                promo_id = args[0]

                authorize = IsPromoCreator(promo_id)
                if authorize:
                    success = ClaimFunds(promo_id)
                    if success:
                        Log('Promo funds claimed successfully')
                    else:
                        Log('Error in claiming funds')
                        return False
                else:
                    Log('Permission denied')
                    return False
            else:
                Log('incorrect number of arguments')
                return False

        # buyer action
        elif operation == 'buy':
            if len(args) == 3:
                buyer = args[0]
                promo_id = args[1]
                quantity = args[2]

                success = BuyPromo(buyer, promo_id, quantity)

                if success:
                    Log('Promo purchased successfully')
                    return True
                else:
                    Log('Error in purchasing promo')
                    return False
            else:
                Log('incorrect number of arguments')
                return False

        # buyer action
        elif operation == 'refund':
            if len(args) == 2:
                buyer = args[0]
                promo_id = args[1]

                authorize = CheckWitness(buyer)
                if authorize:
                    success = RefundPromo(buyer, promo_id)

                    if success:
                        Log('Promo refunded successfully')
                        return True
                    else:
                        Log('Error in refund')
                        return False
                else:
                    Log('Permission denied')
                    return False
            else:
                Log('incorrect number of arguments')
                return False

        # buyer/seller action
        elif operation == 'details':
            if len(args) == 1:
                promo_id = args[0]
                Details(promo_id)
                return True
            else:
                Log('incorrect number of arguments')
                return False

        else:
            Log('operation not found')
            return False

    return False
コード例 #11
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 == 'agreement':
            if len(args) == 10:
                agreement_key = args[0]
                customer = args[1]
                insurer = args[2]
                location = args[3]
                timestamp = args[4]
                utc_offset = args[5]
                amount = args[6]
                premium = args[7]
                dapp_name = args[8]
                fee = args[9]
                a = Agreement(agreement_key, customer, insurer, location,
                              timestamp, utc_offset, amount, premium,
                              dapp_name, fee)

                Log("Agreement added!")
                return a

            else:
                return False

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

            else:
                return False

        elif operation == 'claim':
            if len(args) == 1:
                agreement_key = args[0]
                return Claim(agreement_key)

            else:
                return False

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

            else:
                return False

        elif operation == 'refundAll':
            if len(args) == 1:
                agreement_key = args[0]
                return RefundAll(agreement_key)

            else:
                return False

        elif operation == 'deleteAgreement':
            if len(args) == 1:
                agreement_key = args[0]
                return DeleteAgreement(agreement_key)

            else:
                return False

        result = 'unknown operation'

        return result

    return False
コード例 #12
0
def Main(operation, args):
    trigger = GetTrigger()

    if trigger == Verification():
        # Verification is done when sending money out of the contract.
        #
        # We need to check the sender's balance to make sure they have enough to allow them
        # to send what they're trying to send
        #
        # Note: Contract owner has no special privileges here.

        tx = GetScriptContainer()

        valid = False

        # Go through all the outputs and make sure there's only one output destination.
        # This will be used if we're auto-rescinding the assets (ie sending back to the original
        # sender after a week goes by without the recipient picking up). We'll make sure there's only
        # one output script hash and it matches the stored script hash of the original sender
        #
        # Also we make sure not outputs are going to the contract script hash because we don't support
        # change.
        output_script_hash = None
        contract_script_hash = GetExecutingScriptHash()
        for output in tx.Outputs:
            shash = GetScriptHash(output)
            if shash == contract_script_hash:
                return False

            if output_script_hash == None:
                output_script_hash = shash
            elif shash != output_script_hash:
                return False

        for input in tx.Inputs:
            hash = InputGetHash(input)
            context = GetContext()
            tx_info_serialized = Get(context, hash)
            tx_info = deserialize_bytearray(tx_info_serialized)

            escrow = tx_info[0]
            sender = tx_info[1]
            time = tx_info[2]

            is_escrow = CheckWitness(escrow)

            if is_escrow != True:
                if sender != output_script_hash:
                    return False

                current_time = GetCurrentTimestamp()
                seven_days = 604800
                minimum_time = time + seven_days
                if current_time < minimum_time:
                    return False

            # We have at least one. We'll keep checking if there are more.
            print('That input was valid')
            valid = True

        print('All good')
        return valid

    elif trigger == Application():
        if operation == 'name':
            n = "Sendeo"
            return n

        elif operation == 'deposit':
            if len(args) != 2:
                return False

            recipient = args[0]
            note = args[1]

            deposit = Deposit(recipient, note)

            return deposit

    return False
コード例 #13
0
ファイル: bcschain_op.py プロジェクト: Taburu/bcschainstore
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        is_owner = CheckWitness(BCSCHAIN)

        if is_owner:
            return True

        return False

    elif trigger == Application():
        # Check the version for compatability
        if operation == 'ownArea':
            if (len(args) == 3):
                addr = args[0]
                lat = args[1]
                lon = args[2]

                Log('Owning_Area')
                res = own_area(addr, lat, lon)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'createProduct':
            if (len(args) == 3):
                addr = args[0]
                uuid = args[1]
                p_name = args[2]

                Log('Creating_Product')
                res = create_product(addr, uuid, p_name)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'activateProduct':
            if (len(args) == 2):
                addr = args[0]
                uuid = args[1]

                Log('Activating_Product')
                res = activate_product(addr, uuid)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'setPrice':
            if (len(args) == 3):
                addr = args[0]
                uuid = args[1]
                price = args[2]

                Log('Setting_Price')
                res = set_price(addr, uuid, price)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'buyProduct':
            if (len(args) == 2):
                addr = args[0]
                uuid = args[1]

                Log('Buying_Product')
                res = buy_product(addr, uuid)
                return res

            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'deactivateProduct':
            if (len(args) == 2):
                addr = args[0]
                uuid = args[1]

                Log('Deactivating_Product')
                res = deactivate_product(addr, uuid)
                return res

            else:
                Log('INVALID_ARGUMENTS')
            return False

        Log('INVALID_FUNCTION')
        return False

    Log('FORBIDDEN')
    return False
コード例 #14
0
def Main(operation, args):
    """
    This is the main entry point for the Smart Contract

    :param operation: the operation to be performed ( eg `mintTokens`, `transfer`, etc)
    :type operation: str

    :param args: an optional list of arguments
    :type args: list

    :return: indicating the successful execution of the smart contract
    :rtype: bool
    """

    trigger = GetTrigger()

    if trigger == Verification():

        print("doing verification!")
        owner_len = len(OWNER)

        if owner_len == 20:

            res = CheckWitness(OWNER)
            print("owner verify result")
            return res


#        elif owner_len == 33:
#            #res = verify_signature(operation, OWNER)
#            Log("verify signature not understood by me yet")

    elif trigger == Application():

        print("doing application!")

        if operation == 'deploy':
            out = Deploy()
            print("deployed!")
            return out
        elif operation == 'mintTokens':
            domint = MintTokens()
            print("minted token!")
            return domint
        elif operation == 'totalSupply':
            supply = TotalSupply()
            print("got total supply")
            Notify(supply)
            return supply
        elif operation == 'name':
            n = Name()
            return n
        elif operation == 'decimals':
            d = Decimals()
            return d
        elif operation == 'symbol':
            sym = Symbol()
            return sym

        elif operation == 'transfer':
            print("do transfers")
            if len(args) == 3:
                t_from = args[0]
                t_to = args[1]
                t_amount = args[2]
                return DoTransfer(t_from, t_to, t_amount)

            else:
                return False

        elif operation == 'balanceOf':
            if len(args) == 1:

                print("do balance")

                account = args[0]

                balance = BalanceOf(account)
                print("got balance")
                Notify(balance)

                return balance

            else:

                return 0

    return False
コード例 #15
0
def Main(operation, args):
    """
    The entry point for the smart contract.

    :param operation: str The operation to invoke.
    :param args: list A list of arguments for the operation.
    :return:
        bytearray: The result of the operation.
    """

    print("LootMarkets: Version 1.0: testnet deployment")

    trigger = GetTrigger()

    if trigger == Application():

        # ======== Marketplace Operations =========
        # For each marketplace operation, Notify the details of the
        # operation so the API can catch and handle the events.

        # Give items to an address on a marketplace.
        if operation == "give_items":
            marketplace = args[0]
            address = args[1]
            operation_result = give_items(args)
            transaction_details = ["give_items", marketplace, address, operation_result]
            Notify(transaction_details)
            return operation_result

        # Remove an item from an address on a marketplace.
        if operation == "remove_item":
            if len(args) == 3:
                marketplace = args[0]
                address = args[1]
                item_id = args[2]
                operation_result = remove_item(marketplace, address, item_id)
                transaction_details = ["remove_item", marketplace, address, operation_result]
                Notify(transaction_details)
                return operation_result

        # Transfer an item from an address to another address on a marketplace.
        if operation == "transfer_item":
            if len(args) == 4:
                marketplace = args[0]
                address_from = args[1]
                address_to = args[2]
                item_id = args[3]
                operation_result = transfer_item(marketplace, address_from, address_to, item_id)
                transaction_details = ["transfer_item", marketplace, address_from, address_to, item_id, operation_result]
                Notify(transaction_details)
                return operation_result

        # Query the inventory of an address on a marketplace.
        if operation == "get_inventory":
            if len(args) == 2:
                marketplace = args[0]
                address = args[1]
                inventory_s = get_inventory(marketplace, address)
                inventory = deserialize_bytearray(inventory_s)
                transaction_details = ["get_inventory", marketplace, address, inventory]
                Notify(transaction_details)
                return True

        # Query the owner address of a marketplace.
        if operation == "marketplace_owner":
            if len(args) == 1:
                marketplace = args[0]
                owner = marketplace_owner(marketplace)
                transaction_details = ["marketplace_owner", marketplace, owner]
                Notify(transaction_details)
                return True

        # Put an offer on a marketplace.
        if operation == "put_offer":
            if len(args) == 4:
                marketplace = args[0]
                address = args[1]
                item_id = args[2]
                price = args[3]
                operation_result = put_offer(marketplace, address, item_id, price)
                transaction_details = ["put_offer", marketplace, address, operation_result]
                Notify(transaction_details)
                return operation_result

        # Buy an offer on a marketplace.
        if operation == "buy_offer":
            if len(args) == 3:
                marketplace = args[0]
                address_to = args[1]
                offer_id = args[2]
                operation_result = buy_offer(marketplace, address_to, offer_id)
                transaction_details = ["buy_offer", marketplace, address_to, operation_result]
                Notify(transaction_details)
                return operation_result

        # Cancel an offer on a marketplace.
        if operation == "cancel_offer":
            if len(args) == 3:
                marketplace = args[0]
                address = args[1]
                offer_id = args[2]
                operation_result = cancel_offer(marketplace, address, offer_id)
                transaction_details = ["cancel_offer", marketplace, address, operation_result]
                Notify(transaction_details)
                return operation_result

        # Query the details of an offer on a marketplace.
        if operation == "get_offer":
            if len(args) == 2:
                marketplace = args[0]
                offer_id = args[1]
                offer_s = get_offer(marketplace, offer_id)
                offer = deserialize_bytearray(offer_s)
                transaction_details = ["get_offer", marketplace, offer]
                Notify(transaction_details)
                return True

        # Query all the offer ids on a marketplace.
        if operation == "get_all_offers":
            if len(args) == 1:
                marketplace = args[0]
                offers_s = get_all_offers(marketplace)
                offers = deserialize_bytearray(offers_s)
                transaction_details = ["get_all_offers", marketplace, offers]
                Notify(transaction_details)
                return True

        """
        Ommited create item functionality due to not having a strong argument to store details of items on the 
        blockchain. Item details are best stored off chain by the registerer of the marketplace.
        This code serves as an example.

        # Create a new item.
        if operation == "create_item":
            if len(args) == 5:
                marketplace = args[0]
                item_id = args[1]
                item_type = args[2]
                item_rarity = args[3]
                item_damage = args[4]
                operation_result = create_item(marketplace, item_id, item_type, item_rarity, item_damage)
                transaction_details = ["create_item", marketplace, item_id, operation_result]
                Notify(transaction_details)
                return operation_result

        # Query the details of an item.
        if operation == "get_item":
            if len(args) == 2:
                marketplace = args[0]
                item_id = args[1]
                item_s = get_item(item_id)
                item = deserialize_bytearray(item_s)
                transaction_details = ["get_item", marketplace, item]
                Notify(transaction_details)
                return True
        """

        # ========= Administration, Crowdsale & NEP-5 Specific Operations ==========

        # Commands only the owner can invoke.
        if CheckWitness(contract_owner):

            # Register a new marketplace on the blockchain.
            if operation == "register_marketplace":
                if len(args) == 2:
                    marketplace = args[0]
                    address = args[1]
                    return register_marketplace(marketplace, address)

            # Register a list of addresses for KYC.
            if operation == "kyc_register":
                return kyc_register(args)

            # Deploy LOOT.
            if operation == "deploy_token":
                return deploy_token()

            # Transfer LOOT from an address, to another address.
            if operation == "transfer":
                if len(args) == 3:
                    address_from = args[0]
                    address_to = args[1]
                    amount = args[2]
                    return transfer_token(address_from, address_to, amount)

        # Check the KYC status of an address.
        if operation == "kyc_status":
            if len(args) == 1:
                address = args[0]
                return kyc_status(address)

        # Query the LOOT balance of an address.
        if operation == "balance_of":
            if len(args) == 1:
                address = args[0]
                balance = balance_of(address)
                # Notify the API with the LOOT balance of the address.
                transaction_details = ["balance_of", address, balance]
                Notify(transaction_details)
                return balance

        # Mint tokens during the crowdsale period.
        if operation == "mint_tokens":
            return mint_tokens()

        # Query the circulating supply of the token.
        if operation == "get_circulation":
            return get_circulation()

        # Query the name of the token.
        if operation == "get_name":
            return name

        # Query the symbol of the token.
        if operation == "get_symbol":
            return symbol

        # Query how many decimals the token has.
        if operation == "get_decimals":
            return decimals

        # Query the total supply of the token.
        if operation == "get_total_supply":
            return total_supply

    # Verification portion of the contract to determine whether the transfer
    # of system assets (NEO/Gas) involving this contracts address can proceed.
    if trigger == Verification():

        is_owner = CheckWitness(contract_owner)
        # If is the owner, proceed.
        if is_owner:
            return True
        return False

    return False
コード例 #16
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: string
    """
    trigger = GetTrigger()

    if trigger == Verification():
        is_owner = CheckWitness(BCSCHAIN)

        if is_owner:
            return True

        return False

    elif trigger == Application():
        # Check the version for compatability
        if operation == 'ownArea':
            if (len(args) == 3):
                addr = args[0]
                lat = args[1]
                lon = args[2]
                width = args[3]
                length = args[4]
                height = args[5]

                Log('Owning_Area')
                res = own_area(addr,lat,lon,width,length,height)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'regisProduct':
            if (len(args) == 3):
                seller_addr = args[0]
                product_hash = args[1]

                Log('Registering_Product')
                res = create_product(seller_addr,product_hash)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False
                
        elif operation == 'activateProduct':
            if (len(args) == 2):
                seller_addr = args[0]
                product_hash = args[1]

                Log('Activating_Product')
                res = activate_product(seller_addr ,product_hash)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False
        
        elif operation == 'setPrice':
            if (len(args) == 3):
                seller_addr = args[0]
                product_hash = args[1]
                price = args[2]

                Log('Setting_Price')
                res = set_price(seller_addr,product_hash,price)
                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False


        elif operation == 'buyProduct':
            if (len(args) == 2):
                buyer_addr = args[0]
                product_hash = args[1]

                Log('Buying_Product')
                res = buy_product(buyer_addr,product_hash)
                return res

            else:
                Log('INVALID_ARGUMENTS')
                return False

        elif operation == 'deactivateProduct':
            if (len(args) == 2):
                seller_addr = args[0]
                product_hash = args[1]

                Log('Deactivating_Product')
                res = deactivate_product(seller_addr,product_hash)
                return res

            else:
                Log('INVALID_ARGUMENTS')
            return False

        Log('INVALID_FUNCTION')
        return False

    Log('FORBIDDEN')
    return False
コード例 #17
0
def Main(operation, args):

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

        storage = StorageAPI()
        attachments = get_asset_attachments()

        approval_storage_location = 'claim:approval:' + attachments.sender_addr
        approval = storage.get(approval_storage_location)

        if approval == GetValue():
            storage.delete(approval_storage_location)
            return True

        return False

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

        if operation == 'setBounty':
            if len(args) == 1:
                issue_url = args[0]
                result = SetBounty(issue_url)
                return result
            else:
                return False

        elif operation == 'revokeBounty':
            if len(args) == 1:
                issue_url = args[0]
                result = RevokeBounty(issue_url)
                return result
            else:
                return False

        elif operation == 'claimBounty':
            if len(args) == 1:
                issue_url = args[0]
                result = ClaimBounty(issue_url)
                return result
            else:
                return False

        elif operation == 'approveClaim':
            if len(args) == 2:
                issue_url = args[0]
                claimee_address = args[1]
                result = ApproveClaim(issue_url, claimee_address)
                return result
            else:
                return False

        result = 'unknown operation'

        return result

    return False
コード例 #18
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
    """

    markets = Markets()

    trigger = GetTrigger()

    if trigger == Verification():

        # check if the invoker is the owner of this contract
        is_owner = CheckWitness(OWNER)

        # If owner, proceed
        #print("owner verify result")
        return is_owner

    elif trigger == Application():

        if operation == 'createCategoricalEvent':
            if len(args) != 6:
                #print('Incorrect Arg Length')
                return False
            ipfsHash = args[0]
            spreadMultiplier = args[1]
            challengePeriod = args[2]
            challengeAmount = args[3]
            frontRunnerPeriod = args[4]
            endTime = args[5]

            r = markets.createCategoricalEvent(ipfsHash, spreadMultiplier,
                                               challengePeriod,
                                               challengeAmount,
                                               frontRunnerPeriod, endTime)
            CreateCategoricalEvent(r)
            #print("createCategoricalEvent done!")
            return r
        elif operation == 'betOnOutcome':
            if len(args) != 5:
                #print('Incorrect Arg Length')
                return False
            ipfsHash = args[0]
            outcome = args[1]
            amount = args[2]
            owner = args[3]
            contractAddress = args[4]
            r = markets.betOnOutcome(ipfsHash, outcome, amount, owner,
                                     contractAddress)
            BetOnOutcome(r)
            #print('betOnOutcome done!')
            return r
        elif operation == 'isFinalOutcomeSet':
            if len(args) != 1:
                #print('Incorrect Arg Length')
                return False
            ipfsHash = args[0]
            r = markets.isFinalOutcomeSet(ipfsHash)
            IsFinalOutcomeSet(r)
            #print('isFinalOutcomeSet done!')
            return r
        elif operation == 'getFinalOutcome':
            if len(args) != 1:
                #print('Incorrect Arg Length')
                return False
            ipfsHash = args[0]
            r = markets.getFinalOutcome(ipfsHash)
            GetFinalOutcome(r)
            #print('getFinalOutcome done!')
            return r
        elif operation == 'redeemWinnings':
            if len(args) != 2:
                #print('Incorrect Arg Length')
                return False
            ipfsHash = args[0]
            owner = args[1]
            r = markets.redeemWinnings(ipfsHash, owner)
            RedeemWinnings(r)
            #print('redeemWinnings done!')
            return r
        return False
    return False
コード例 #19
0
def Main(args):

    print("RUNNING WITHDRAW TEST!!!!")

    trigger = GetTrigger()

    if trigger == Verification():

        print("doing verification")

        # check to see if the withdrawer is the owner

        is_owner = CheckWitness(OWNER)

        # always allow owner to withdraw
        if is_owner:
            return True

        else:

            # if it is not the owner, we need to verify a few things
            can_widthraw = CanWithdrawNeo()

            print("can withdraw neo?")
            Notify(can_widthraw)

            return can_widthraw

    elif trigger == Application():
        print("doing application")

        # no matter what happens, we need to reconcile balances
        # so if, for example, someone has sucessfully made a withdrawl
        # the verification portion of this contract checked it all out
        # but the application part of the contract needs to sync the balance

        # we don't really care what operation is called
        # no matter what we will try to reconcile
        did_withdraw = ReconcileBalances()

        operation = args[0]

        if operation == 'deposit':

            if not did_withdraw:
                deposit = DepositNeo()

                return deposit
            else:

                print("cannot withdraw and deposit at the same time")
                return False

        elif operation == 'balanceOf':

            if len(args) != 2:
                return False

            account = args[1]
            getbalance = BalanceOf(account)

            return getbalance

    return False
コード例 #20
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 == 'name':
            n = 'Milestone'
            return n

        elif operation == 'fee':
            context = GetContext()
            f = Get(context, 'fee')

            if len(f) == 0:
                f = INITIAL_FEE

            return f

        elif operation == 'setFee':
            if len(args) == 1:
                new_fee = args[0]
                context = GetContext()
                Delete(context, 'fee')
                Put(context, 'fee', new_fee)
                DispatchFeeUpdateEvent(new_fee)
                return True
            else:
                return False

        elif operation == 'milestone':
            if len(args) == 11:
                milestone_key = args[0]
                agreement = args[1]
                customer = args[2]
                assignee = args[3]
                platform = args[4]
                timestamp = args[5]
                utc_offset = args[6]
                oracle = args[7]
                pay_out = args[8]
                asset = args[9]
                threshold = args[10]
                a = Milestone(milestone_key, agreement, customer, assignee, platform, timestamp, utc_offset, pay_out, oracle, asset, threshold)

                Notify("Milestone added!")
                return a

            else:
                return False

        elif operation == 'review':
            if len(args) == 2:
                milestone_key = args[0]
                review_score = args[1]
                return Review(milestone_key, review_score)

            else:
                return False

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

            else:
                return False

        elif operation == 'refund':
            if len(args) == 2:
                milestone_key = args[0]
                fee_refund = args[1]
                return Refund(milestone_key, fee_refund)

            else:
                return False

        elif operation == 'deleteMilestone':
            if len(args) == 1:
                milestone_key = args[0]
                return DeleteMilestone(milestone_key)

            else:
                return False

        result = 'unknown operation'

        return result

    return False
コード例 #21
0
def Main(operation, args):

    trigger = GetTrigger()

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

    elif trigger == Application():
        context = GetContext()
        l = len(args)
        if l == 1:
            key = args[0]
        elif l == 2:
            key = args[0]
            value = args[1]
        else:
            Log("Bad invocation argument count")
            Log(l)
            return False

        if operation == 'getvalue':
            return Get(context, key)
  
        elif operation == 'putvalue':
            prefix = take(key, 6)
            if BADPREFIX == prefix:
                Log("Hacking attempt!")
                return False

            if CheckWitness(OWNER):
                Log("Owner found, bypassing payment")
                Put(context, key, value)
                return True
            else:
                # check if we got paid
                tx = GetScriptContainer()
                refs = tx.References
                if len(refs) < 1:
                    Log("No payment sent in transaction")
                    return False
                ref = refs[0]
                sentAsset = GetAssetId(ref)
                if sentAsset == GAS_ASSET_ID:
                    sender = GetScriptHash(ref)
                    receiver = GetExecutingScriptHash();
                    totalGasSent = 0
            
                    for output in tx.Outputs:
                        shash = GetScriptHash(output)
                        if shash == receiver:
                            totalGasSent = totalGasSent + output.Value

                    Log ("Total GAS sent:")
                    Log (totalGasSent)
                    pkey = concat('price/', key)
                    keyprice = Get(context, pkey)

                    if totalGasSent == keyprice:
                        Log("Price met, setting value and sending notification")
                        notification=[sender,key,value]
                        Notify(notification)
                        Put(context, key, value)
                        return True
                   
                    Log("Price not met!")
                    return False
            
            return False
        elif operation == 'getprice':
            key = concat('price/', key)
            return Get(context, key)

        elif operation == 'putprice':
            if CheckWitness(OWNER):
                key = concat('price/', key)
                Put(context, key, value)
                return True
            else:
                Log("Access denied")
                return False
        else:
            Log("Invalid operation")
            return False
    return False
コード例 #22
0
def Main(operation, args):
    """
    :param operation
    :param args: optional arguments (up to 3 max)
    :return: Object: Bool (success or failure) or Prediction
    """

    Log("NEO-FUTURES - Oracle Judge Smart Contract")
    trigger = GetTrigger()
    arg_len = len(args)
    if arg_len > 5:
        # Only 5 args max
        return False

    if trigger == Verification():
        Log("trigger: Verification")
        is_owner = CheckWitness(Game_rules.owner)
        if is_owner:
            return True
    elif trigger == Application():
        Log("trigger: Application")
        Log(operation)

        # create_new_game {{client}} {{game_type}}
        if operation == 'create_new_game':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            client_hash = args[0]
            game_type = args[1]
            if not CheckWitness(client_hash):
                Log("Unauthorised hash")
                return False
            return CreateNewGame(client_hash, game_type)

        # submit_prediction {{oracle}} {{game_type}} {{instance_ts}} {{prediction}} {{gas-submission}}
        if operation == 'submit_prediction':
            if arg_len != 5:
                Log("Wrong arg length")
                return False
            oracle = args[0]
            game_type = args[1]
            instance_ts = args[2]
            prediction = args[3]
            gas_submission = args[4]
            if not CheckWitness(oracle):
                Log("Unauthorised hash")
                return False

            # Check instance_ts is correctly timestepped
            if not CheckTimestamp(instance_ts):
                Log("Not correct timestamp format")
                return False
            return client_hash.SubmitPrediction(oracle, game_type, instance_ts, prediction, gas_submission)

        # judge_instance {{game_type}} {{instance_ts}}
        if operation == 'judge_instance':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            game_type = args[0]
            instance_ts = args[1]
            if client_hash.isGameInstanceJudged(game_type, instance_ts):
                Log("Already Judged")
                return False
            return client_hash.JudgeInstance(game_type, instance_ts)

        # get_prediction {{game_type}} {{instance_ts}}
        if operation == 'get_prediction':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            game_type = args[0]
            instance_ts = args[1]
            # Try judging to make sure judged
            client_hash.JudgeInstance(game_type, instance_ts)
            return client_hash.GetPrediction(game_type, instance_ts)

        # get_available_balance_oracle {{oracle}}
        if operation == 'get_available_balance_oracle':
            if arg_len != 1:
                Log("Wrong arg length")
                return False
            oracle = args[0]
            return client_hash.GetOracleBalance(oracle)

        # get_correct_oracles_for_instance {{game_type}} {{instance_ts}}
        if operation == 'get_correct_oracles_for_instance':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            game_type = args[0]
            instance_ts = args[1]
            # Try judging to make sure judged
            client_hash.JudgeInstance(game_type, instance_ts)
            return client_hash.GetCorrectOracleCountForInstance(game_type, instance_ts)

        # debug_get_value {{key}}
        if operation == 'debug_get_value':
            if arg_len != 1:
                Log("Wrong arg length")
                return False
            key = args[0]
            context = GetContext()
            return Get(context, key)
        else:
            Log("unknown op")
            return False
コード例 #23
0
def Main(operation, args):
    """ Main entrypoint for the smart contract.

    :param operation: the operation to be performed
    :param args: a list of arguments (which may be empty, but not absent)
    :type operation: str
    :type args: list
    :return: a boolean, a string or a byte array indicating the result of the execution of the SC
    :rtype: bool, string or bytearray

    """

    arg_length_error = 'Incorrect number of arguments'

    # Uses the trigger to dertermine whether this smart contract is being run in 'verification' mode
    # or 'application' mode.
    trigger = GetTrigger()

    # The 'Verification' mode is used when trying to spend assets (eg. NEO, Gas) on behalf of this
    # contract's address.
    if trigger == Verification():
        # Checks whether the script that sent this is the owner. If so we can allow the operation.
        is_owner = CheckWitness(OWNER)
        if is_owner:
            return True
        return False
    elif trigger == Application():
        if operation == 'deploy':
            result = deploy()
            return result
        elif operation == 'addURL':
            if len(args) == 1:
                url = args[0]
                result = add_url(url)
                return result
            return arg_length_error
        elif operation == 'getShortenerURL':
            url = get_shortener_url()
            return url
        elif operation == 'getURL':
            if len(args) == 1:
                code = args[0]
                result = get_url(code)
                return result
            return arg_length_error
        elif operation == 'getURLInfo':
            if len(args) == 1:
                code = args[0]
                result = get_url_info(code)
                return result
            return arg_length_error
        elif operation == 'setShortenerURL':
            if len(args) == 1:
                url = args[0]
                result = set_shortener_url(url)
                return result
            return arg_length_error

        result = 'unknown operation'
        return result

    return False
コード例 #24
0
def Main(operation, args, sender=None):

    trigger = GetTrigger()

    if trigger == Application():

        context = GetContext()
        """
            Standard Operations

            No Permissions Required
        """

        event = Event()

        if operation == 'validateActiveEvent':
            return event.ValidateActiveEvent(args)

        elif operation == 'checkEventOutcome':
            return event.CheckEventOutcome(args)
        """
            Oracle Operations

            Requires Oracle Permissions 
        """

        oracle = Oracle()

        if operation == "addEvent":
            return oracle.AddEvent(args, sender)

        elif operation == "updateEventOutcome":
            return oracle.UpdateEventOutcome(args, sender)

        elif operation == "deleteSelf":
            return True
        """
            Admin Operations

            Requires Owner Permissions
        """

        admin = Admin()

        if operation == 'addOracle':
            return admin.AddOracle(args)

        elif operation == 'removeOracle':
            return admin.RemoveOracle(args)

        elif operation == 'killAdmin':
            return True

        elif operation == 'initContract':
            return admin.InitialiseContract()

    elif trigger == Verification():
        admin = Admin()

        return admin.ValidateOwner()

    return False
コード例 #25
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: an optional list of arguments
    :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

        # The following method is not a part of the NEP5 Standard
        # But is used to 'mint' the original tokens
        elif operation == 'deploy':
            result = Deploy()
            return result

        result = 'unknown operation'

        return result

    return False
コード例 #26
0
def Main(operation, args):

    trigger = GetTrigger()

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

        if is_owner:
            return True

        return False

    elif trigger == Application():
        # Check the version for compatability
        if operation == 'initial':
            res = False
            if (len(args) == 0):
                print('checking if its the owner')
                isowner = CheckWitness(OWNER)
                if isowner:
                    print('it is the owner')
                    context = GetContext()
                    owner_value = Get(context, OWNER)
                    if (owner_value == 0):
                        Put(context, 'name', dApp_name)
                        Put(context, OWNER, 1000)
                        res = True
                    else:
                        print('You are Already Initialize')

            else:
                Log('INVALID_ARGUMENTS')

            return res

        elif operation == 'regis':
            res = False
            if (len(args) == 1):
                addr = args[0]
                Log('Registration')
                context = GetContext()
                addr_regis = Get(context, addr)
                if (addr_regis == 0):
                    Put(context, addr, 100)
                    res = True
                else:
                    print('You are Already Register')
            else:
                Log('INVALID_ARGUMENTS')
                return False

            return res

        elif operation == 'value':
            res = 0
            if (len(args) == 1):
                addr = args[0]
                isowner = CheckWitness(addr)
                if isowner:
                    context = GetContext()
                    value = Get(context, addr)
                    if not (value == 0):
                        res = value
                    else:
                        print('You are not Registration')

                return res
            else:
                Log('INVALID_ARGUMENTS')
                return False

            return False

        elif operation == 'add':
            if (len(args) == 2):
                addr = args[0]
                value_added = args[1]
                isowner = CheckWitness(OWNER)
                if isowner:
                    context = GetContext()
                    value = Get(context, addr)
                    if not (value == 0):
                        data = value_added + value
                        Put(context, addr, data)
                        print('value added')
                        return True
                    else:
                        print('The Addresss no Register yet')
                else:
                    print('You are not Owner')
                return False
            else:
                Log('INVALID_ARGUMENTS')
                return False

            return False

        Log('INVALID_FUNCTION')
        return False

    Log('FORBIDDEN')
    return False
コード例 #27
0
def Main(operation, args):
    """
    :param operation
    :param args: optional arguments (up to 3 max)
    :return: Object: Bool (success or failure) or Prediction
    """

    Log("ORACLE JUDGE")
    trigger = GetTrigger()
    arg_len = len(args)
    if arg_len > 5:
        # Only 5 args max
        return False

    if trigger == Verification():
        Log("trigger: Verification")
        is_owner = CheckWitness(owner)
        if is_owner:
            return True
    elif trigger == Application():
        Log("trigger: Application")
        Log(operation)

        # create_new_game {{client}} {{game_type}}
        if operation == 'create_new_game':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            client_hash = args[0]
            game_type = args[1]
            if not CheckWitness(client_hash):
                Log("Unauthorised hash")
                return False
            return CreateNewGame(client_hash, game_type)

        # create_new_game_instance {{client}} {{game_type}} {{instance_ts}}
        if operation == 'create_new_game_instance':
            if arg_len != 3:
                Log("Wrong arg length")
                return False
            client_hash = args[0]
            game_type = args[1]
            instance_ts = args[2]
            if not CheckWitness(client_hash):
                Log("Unauthorised hash")
                return False
            return CreateNewGameInstance(client_hash, game_type, instance_ts)

        # submit_prediction {{oracle}} {{game_type}} {{instance_ts}} {{prediction}} (--attach-gas=5)
        if operation == 'submit_prediction':
            if arg_len != 4:
                Log("Wrong arg length")
                return False
            oracle = args[0]
            game_type = args[1]
            instance_ts = args[2]
            prediction = args[3]
            if not CheckWitness(oracle):
                Log("Unauthorised hash")
                return False
            return SubmitPrediction(oracle, game_type, instance_ts, prediction)

        # judge_instance {{game_type}} {{instance_ts}}
        if operation == 'judge_instance':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            game_type = args[0]
            instance_ts = args[1]
            if isGameInstanceJudged(game_type, instance_ts):
                Log("Already Judged")
                return False
            return JudgeInstance(game_type, instance_ts)

        # get_prediction_for_instance {{game_type}} {{instance_ts}}
        if operation == 'get_prediction_for_instance':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            game_type = args[0]
            instance_ts = args[1]
            if not isGameInstanceJudged(game_type, instance_ts):
                JudgeInstance(game_type, instance_ts)
            return GetPrediction(game_type, instance_ts)

        # get_available_balance_oracle {{oracle}}
        if operation == 'get_available_balance_oracle':
            if arg_len != 1:
                Log("Wrong arg length")
                return False
            oracle = args[0]
            return GetOracleBalance(oracle)

        # get_correct_oracles_for_instance {{game_type}} {{instance_ts}}
        if operation == 'get_correct_oracles_for_instance':
            if arg_len != 2:
                Log("Wrong arg length")
                return False
            game_type = args[0]
            instance_ts = args[1]
            if not isGameInstanceJudged(game_type, instance_ts):
                Log("Game not yet Judged")
                return False
            return GetCorrectOracleCountForInstance(game_type, instance_ts)

        # debug_get_value {{key}}
        if operation == 'debug_get_value':
            if arg_len != 1:
                Log("Wrong arg length")
                return False
            key = args[0]
            return Get(GetContext(), key)
        else:
            Log("unknown op")
            return False
コード例 #28
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()
        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