示例#1
0
def has_started(ctx):
    sale_t = crowdsale_time(ctx)
    if sale_t:
        current_height = GetHeight()
        current_header = GetHeader(current_height)
        current_timestamp = GetTimestamp(current_header)
        if current_timestamp < sale_t:
            return False
        else:
            return True
    return False
示例#2
0
def get_header_timestamp():
    """
    :returns current block timestamp:
    """
    height = GetHeight()
    header = GetHeader(height)
    if height > 0:  # seems like while testing height is zero
        timestamp = GetTimestamp(header)
    else:
        timestamp = 1400000000
    return timestamp
示例#3
0
    def Timestamp(self):
        """

        :return:
        """
        return GetTimestamp(self)
示例#4
0
    def Timestamp(self):
        """Get the timestamp of the block

        :return:
        """
        return GetTimestamp(self)
示例#5
0
def perform_exchange(ctx):
    """

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

    attachments = get_asset_attachments()  # [receiver, sender, neo, gas]

    # this looks up whether the exchange can proceed
    exchange_ok = can_exchange(ctx, attachments, False)

    if not exchange_ok:
        # 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[2] > 0:
            OnRefund(attachments[1], attachments[2])
        # 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 = Get(ctx, attachments[1])

    # calculate the amount of tokens the attached neo will earn
    exchanged_tokens = attachments[2] * TOKENS_PER_NEO / 100000000

    # TODO: make sure the bonus rate here are correct
    crowdsale_ts = crowdsale_time(ctx)
    height = GetHeight()
    header = GetHeader(height)
    ts = GetTimestamp(header)
    ts_48hrs = crowdsale_ts + 172800  # 48 * 60 * 60
    ts_week1 = crowdsale_ts + 604800  # 7 * 24 * 60 * 60 / 15
    ts_week2 = crowdsale_ts + 1209600  # 14 * 24 * 60 * 60 / 15
    ts_week3 = crowdsale_ts + 1814400  # 21 * 24 * 60 * 60 / 15

    bonus_48hrs = 20
    bonus_week1 = 10
    bonus_week2 = 7
    bonus_week3 = 3

    if ts < ts_48hrs:
        exchanged_tokens = exchanged_tokens * (100 + bonus_48hrs) / 100
    elif ts < ts_week1:
        exchanged_tokens = exchanged_tokens * (100 + bonus_week1) / 100
    elif ts < ts_week2:
        exchanged_tokens = exchanged_tokens * (100 + bonus_week2) / 100
    elif ts < ts_week3:
        exchanged_tokens = exchanged_tokens * (100 + bonus_week3) / 100

    # if you want to exchange gas instead of neo, use this
    # exchanged_tokens += attachments[3] * TOKENS_PER_GAS / 100000000

    # add it to the the exchanged tokens and persist in storage
    new_total = exchanged_tokens + current_balance
    Put(ctx, attachments[1], new_total)

    # update the in circulation amount
    result = add_to_circulation(ctx, exchanged_tokens)

    # dispatch transfer event
    OnTransfer(attachments[0], attachments[1], exchanged_tokens)

    return True