def reward_user(address):
    """
    Raise the user level corresponding to address and reward him/her.
    """
    token = Token()
    if not CheckWitness(token.owner):
        print("Must be owner to reward")
        return False

    nep = NEP5Handler()
    storage = StorageAPI()
    level = level_up(
        address
    )  ### you might wanna just set this constant for debugging purposes
    reward = calculate_reward(level)
    success = nep.do_transfer(storage, token.owner, address, reward)
    return success
Example #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()
    token = Token()

    #print("Executing ICO Template")

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

        storage = StorageAPI()

        crowdsale = Crowdsale()

        return crowdsale.can_exchange(token, attachments, storage, True)


    elif trigger == Application:

        if operation != None:

            nep = NEP5Handler()

            for op in nep.get_methods():
                if operation == op:
                    return nep.handle_nep51(operation, args, token)

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

            if operation == 'circulation':
                storage = StorageAPI()
                return token.get_circulation(storage)

            # the following are handled by crowdsale

            sale = Crowdsale()

            if operation == 'mintTokens':
                return sale.exchange(token)

            if operation == 'crowdsale_register':
                return sale.kyc_register(args, token)

            if operation == 'crowdsale_status':
                return sale.kyc_status(args)

            if operation == 'crowdsale_available':
                return token.crowdsale_available_amount()

            return 'unknown operation'

    return False
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()
    token = Token()

    #print("Executing ICO Template")

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

        storage = StorageAPI()

        crowdsale = Crowdsale()

        return crowdsale.can_exchange(token, attachments, storage, True)


    elif trigger == Application:

        if operation != None:

            nep = NEP5Handler()

            for op in nep.get_methods():
                if operation == op:
                    return nep.handle_nep51(operation, args, token)

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

            if operation == 'circulation':
                storage = StorageAPI()
                return token.get_circulation(storage)

            # the following are handled by crowdsale

            sale = Crowdsale()

            if operation == 'mintTokens':
                return sale.exchange(token)

            # if operation == 'crowdsale_register':
            #     return sale.kyc_register(args, token)

            # if operation == 'crowdsale_status':
            #     return sale.kyc_status(args)

            if operation == 'crowdsale_available':
                return token.crowdsale_available_amount()

            if operation == 'crowdfunding_create':
                return crowdfunding_create(args)

            if operation == 'crowdfunding_total':
                storage = StorageAPI()
                crowdfunding_address = args[0]
                crowdfunding_total_key = storage.get_crowdfunding_total_key(crowdfunding_address)
                crowdfunding_total = storage.get(crowdfunding_total_key)
                msg = ["crowdfunding_total", crowdfunding_total]
                Notify(msg)
                return crowdfunding_total

            if operation == 'crowdfunding_numcontrib':
                storage = StorageAPI()
                crowdfunding_address = args[0]
                crowdfunding_numcontrib_key = storage.get_crowdfunding_numcontrib_key(crowdfunding_address)
                crowdfunding_numcontrib = storage.get(crowdfunding_numcontrib_key)
                msg = ["crowdfunding_numcontrib", crowdfunding_numcontrib]
                Notify(msg)
                return crowdfunding_numcontrib

            if operation == 'crowdfunding_test':
                crowdfunding_address = args[0]
                member_addresses = crowdfunding_get_members(crowdfunding_address)
                if not member_addresses:
                    return False

                Notify("Member addresses:")
                Notify(member_addresses)
                return True

            if operation == 'level':
                address = args[0]
                level = level_of(address)
                Notify("Level:")
                Notify(level)
                return level

            if operation == 'reward_user':
                address = args[0]
                success = reward_user(address)
                if success:
                    Notify("User was rewarded:")
                    Notify(address)
                return success

            return 'unknown operation'

    return False
Example #4
0
def Main(operation, args):
    """

    :param operation: str Der Name der Aufgabe die ausgeführt werden soll
    :param args: list Eine Liste der Argumente für die Ausführung
    :return:
        bytearray: Das Ergebnis der Ausführung
    """

    trigger = GetTrigger()
    token = Token()

    #print("Executing ICO Template")

    # Dies wird in der Verification portion des Contract benutzt
    # um festzustellen ob ein Transfer System Assets ( NEO/GAS) beinhaltet.
    # Diese Contract´s Adresse kann fortfahren
    if trigger == Verification:

        # Überprüfen Sie ob die aufrufende Instanz der Besitzer des Contracs ist
        is_owner = CheckWitness(token.owner)

        # Wenn Besitzer, fortfahren
        if is_owner:

            return True

        # Andernfalls, müssen Sie einen Lookup der Adresse machen und feststellen
        # ob der Anhang des Assets okay ist
        attachments = get_asset_attachments()  # type:Attachments

        storage = StorageAPI()

        crowdsale = Crowdsale()

        return crowdsale.can_exchange(token, attachments, storage)

    elif trigger == Application:

        if operation != None:

            nep = NEP5Handler()

            for op in nep.get_methods():
                if operation == op:
                    return nep.handle_nep51(operation, args, token)

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

            if operation == 'circulation':
                storage = StorageAPI()
                return token.get_circulation(storage)

            # Das folgende wird von Crowdsale verarbeitet

            sale = Crowdsale()

            if operation == 'mintTokens':
                return sale.exchange(token)

            if operation == 'crowdsale_register':
                return sale.kyc_register(args, token)

            if operation == 'crowdsale_status':
                return sale.kyc_status(args)

            if operation == 'crowdsale_available':
                return token.crowdsale_available_amount()

            return 'unknown operation'

    return False