Ejemplo n.º 1
0
    def exchange(self, token: Token):

        attachments = get_asset_attachments()

        storage = StorageAPI()

        can_exchange = self.can_exchange(token, attachments, storage, False)

        if not can_exchange:
            print("Cannot exchange value")

            if attachments.neo_attached > 0:
                OnRefund(attachments.sender_addr, attachments.neo_attached)

        return False

        current_balance = storage.get(attachments.sender_addr)

        exchanged_tokens = attachments.neo_attached * token.tokens_per_neo / 100000000

        new_total = exchanged_tokens + current_balance
        storage.put(attachments.sender_addr, new_total)

        token.add_to_circulation(exchanged_tokens, storage)

        OnTransfer(attachments.receiver_addr, attachments.sender_addr,
                   exchanged_tokens)

        return True
Ejemplo n.º 2
0
    def exchange(self, token: Token):
        """

        :param token:Token The token object with NEP5/sale settings
        :return:
            bool: Whether the exchange was successful
        """

        attachments = get_asset_attachments()  # type:  Attachments

        storage = StorageAPI()

        # this looks up whether the exchange can proceed
        can_exchange = self.can_exchange(token, attachments, storage, False)

        if not can_exchange:
            print("Cannot exchange value")
            # This should only happen in the case that there are a lot of TX on the final
            # block before the total amount is reached.  An amount of TX will get through
            # the verification phase because the total amount cannot be updated during that phase
            # because of this, there should be a process in place to manually refund tokens
            if attachments.neo_attached > 0:
                OnRefund(attachments.sender_addr, attachments.neo_attached)
            # if you want to exchange gas instead of neo, use this
            #if attachments.gas_attached > 0:
            #    OnRefund(attachments.sender_addr, attachments.gas_attached)
            return False

        # lookup the current balance of the address
        current_balance = storage.get(attachments.sender_addr)

        # calculate the amount of tokens the attached neo will earn
        exchanged_tokens = attachments.neo_attached * token.tokens_per_neo / 100000000

        # if you want to exchange gas instead of neo, use this
        # exchanged_tokens += attachments.gas_attached * token.tokens_per_gas / 100000000

        # add it to the the exchanged tokens and persist in storage
        new_total = exchanged_tokens + current_balance
        storage.put(attachments.sender_addr, new_total)

        # update the in circulation amount
        token.add_to_circulation(exchanged_tokens, storage)

        # dispatch transfer event
        OnTransfer(attachments.receiver_addr, attachments.sender_addr,
                   exchanged_tokens)

        return True
Ejemplo n.º 3
0
def Main(operation, args):
    trigger = GetTrigger()
    token = Token()

    if trigger == Verification:

        is_owner = CheckWitness(token.owner)
        if is_owner:
            return True

        attachments = get_asset_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)

            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
Ejemplo n.º 4
0
    def exchange(self, token: Token):
        """

        :param token:Token The token object with NEP5/sale settings
        :return:
            bool: Whether the exchange was successful
        """

        attachments = get_asset_attachments()  # type:  Attachments

        storage = StorageAPI()

        # this looks up whether the exchange can proceed
        can_exchange = self.can_exchange(token, attachments, storage)

        if not can_exchange:
            print("Cannot exchange value")
            # This should only happen in the case that there are a lot of TX on the final
            # block before the total amount is reached.  An amount of TX will get through
            # the verification phase because the total amount cannot be updated during that phase
            # because of this, there should be a process in place to manually refund tokens
            OnRefund(attachments.sender_addr, attachments.neo_attached)
            return False


        # lookup the current balance of the address
        current_balance = storage.get(attachments.sender_addr)

        # calculate the amount of tokens the attached neo will earn
        exchanged_tokens = attachments.neo_attached * token.tokens_per_neo / 100000000

        # if you want to exchange gas instead of neo, use this
        # exchanged_tokens += attachments.gas_attached * token.tokens_per_gas / 100000000


        # add it to the the exchanged tokens and persist in storage
        new_total = exchanged_tokens + current_balance
        storage.put(attachments.sender_addr, new_total)

        # update the in circulation amount
        token.add_to_circulation(exchanged_tokens, storage)

        # dispatch transfer event
        OnTransfer(attachments.receiver_addr, attachments.sender_addr, exchanged_tokens)

        return True
Ejemplo n.º 5
0
    def exchange(self, token: Token):
        """

        :param token:Token Das Token Objekt mit NEP5/sale Einstellungen
        :return:
            bool: Ob der exchange erfolgreich war
        """

        attachments = get_asset_attachments()  # type:  Attachments

        storage = StorageAPI()

        # Dies überprüft ob der exchange ausgeführt werden kann
        can_exchange = self.can_exchange(token, attachments, storage)

        if not can_exchange:
            print("Cannot exchange value")
            # Dies sollte nur passieren im Fall das viele TX auf dem Final Block sind bevor 
            # der total amount erreicht ist. Nur eine Teilmenge der TX wird durch die Verification
            # Phase kommen und da die Gesamtmenge während dieser Phase nicht erhöht werden kann,
            # sollte es einen Prozess zur manuellen Erstattung der Tokens geben.
            OnRefund(attachments.sender_addr, attachments.neo_attached)
            return False


        # Suche den aktuellen Kontostand einer Adresse
        current_balance = storage.get(attachments.sender_addr)

        # Kalkuliere den Wert an Tokens die die angehängten NEO Wert sind
        exchanged_tokens = attachments.neo_attached * token.tokens_per_neo / 100000000

        # Wenn Sie anstatt Neo, Gas verwenden wollen benutzen Sie dies hier
        # exchanged_tokens += attachments.gas_attached * token.tokens_per_gas / 100000000


        # Fügen Sie die erhaltenen Tokens zu dem Persisten Storage hinzu
        new_total = exchanged_tokens + current_balance
        storage.put(attachments.sender_addr, new_total)

        # Updaten Sie den im Umlauf befindenden Wert 
        token.add_to_circulation(exchanged_tokens, storage)

        # Dispatch Transfer Event
        OnTransfer(attachments.receiver_addr, attachments.sender_addr, exchanged_tokens)

        return True
Ejemplo n.º 6
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
Ejemplo n.º 8
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)


    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
Ejemplo n.º 9
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