示例#1
0
def Main():
    current_height = GetHeight()
    currentBlock = GetHeader(current_height)
    time = currentBlock.Timestamp

    # # Or just use GetTime Function
    # time = GetTime()
    return time
示例#2
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
示例#3
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
示例#4
0
def ResultNotice(order_key, funds_transfered, oracle_cost):
    """
    Method to signal results by oracle

    :param order_key: the key of the exchange
    :type order_key: bytearray

    :param funds_transfered: funds on external blockchain transfered
    :type weather_param: int

    :param oracle_cost: costs made by the oracle to do this assignment
    :type oracle_cost: int

    :return: whether a pay out to the customer is done
    :rtype: bool
    """

    # Check if the method is triggered by the oracle for this exchange
    context = GetContext()
    order_data = Get(context, order_key)
    oracle = order_data[8]

    if not CheckWitness(oracle):
        Log("Must be oracle to notice results")
        return False

    timestamp = order_data[3]
    utc_offset = order_data[4]
    status = order_data[12]

    if not status == 'initialized':
        Log("Contract has incorrect status to do a result notice")
        return False

    order_data[12] = 'funds-transfered'  # order status
    order_data[13] = funds_transfered
    order_data[14] = oracle_cost

    # Get timestamp of current block
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    current_time = currentBlock.Timestamp
    Put(context, order_key, order_data)

    timezone_timestamp = timestamp + (3600 * utc_offset)
    timezone_current_time = current_time + (3600 * utc_offset)

    if timezone_current_time < timezone_timestamp:
        Log("Datetime of result notice is lower than agreed datetime")
        return False
    else:
        DispatchResultNoticeEvent(order_key, funds_transfered, oracle_cost)
        return True
示例#5
0
def CurrentSwapRate():
    """
    Method to calculate the current 'going rate' or exchange ratio of NEO to NEP5 tokens

    :return: the current rate
    :rtype: int

    """
    basic = 1000 * FACTOR
    duration = ICO_END_TIME - ICO_START_TIME
    print("getting swap rate")
    context = GetContext()
    print("got context")

    total_supply = Get(context, 'totalSupply')
    print("got total supply")
    if total_supply >= TOTAL_AMOUNT:
        return False
    print("getting current height...")
    currentHeight = GetHeight()
    print("got current height")
    currentBlock = GetHeader(currentHeight)
    print("got current block...")
    time = currentBlock.Timestamp - ICO_START_TIME

    if time < 0:

        return 0

    elif time < 86400:
        return basic * 130 / 100

    elif time < 259200:
        return basic * 120 / 100

    elif time < 604800:
        return basic * 110 / 100

    elif time < duration:
        return basic

    return 0
示例#6
0
def getLucky():

    numbers = [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
        39
    ]

    winning_numbers = []

    currentHeight = GetHeight()
    currentHeader = GetHeader(currentHeight)
    randomNumber = GetConsensusData(currentHeader)
    randomNumber = randomNumber * GetTime()

    for i in range(1, 6):

        percentage = (randomNumber * i) % (39 - i)

        winning_numbers.append(numbers[percentage])

        numbers.remove(percentage)

    return serialize_array(winning_numbers)
示例#7
0
def Order(order_key, timestamp, src_currency, dst_currency, course, amount,
          src_wallet, dst_wallet, deposit_wallet, dapp_name, fee):
    """
    Method to create an order to change currencies

    :param order_key: unique identifier for the exchange
    :type order_key: str

    :param customer: customer party of the exchange
    :type customer: bytearray

    :param insurer: insurer party of the exchange
    :type insurer: bytearray

    :param location: location were the event occurs, typically a city
    :type location: str

    :param timestamp: timezone naive datetime of the day of the event
    :type timestamp: int

    :param amount: the insured amount of NEO
    :type amount: int

    :param premium: the amount of NEO to be paid as a premium to the insurer
    :type premium: int

    :param dapp_name: the name of the dApp
    :type dapp_name: str

    :param fee: the fee to be charged
    :type fee: int

    :return: whether the exchange was successful
    :rtype: bool
    """

    if not CheckWitness(OWNER):
        Log("Must be owner to add an exchange")
        return False

    # Check if amount is not zero or below
    if amount <= 0:
        Log("Exchange amount is zero or negative")
        return False

    # TODO add checks for wallets
    # TODO checks for expire
    # TODO add checks for course

    # Check if the contract is deployed
    context = GetContext()
    if not Get(context, dapp_name):
        Log("Must first deploy contract with the deploy operation")
        return False

    # Get timestamp of current block
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    current_time = currentBlock.Timestamp
    # Compute timezone adjusted time
    timezone_timestamp = timestamp + (utc_offset * 3600)
    timezone_current_time = current_time + (utc_offset * 3600)

    # Get contract settings
    dapp_name = Get(context, 'dapp_name')
    oracle = Get(context, 'oracle')
    time_margin = Get(context, 'time_margin')
    min_time = Get(context, 'min_time')
    max_time = Get(context, 'max_time')

    # Check if timestamp is not out of boundaries
    if timezone_timestamp < (timezone_current_time + min_time - time_margin):
        Log("Datetime must be > 1 day ahead")
        return False

    elif timezone_timestamp > (timezone_current_time + max_time + time_margin):
        Log("Datetime must be < 30 days ahead")
        return False

    status = 'initialized'

    # Set place holder variables
    weather_param = 0
    oracle_cost = 0

    # TODO deposit value depends on oracle that returns a deposit amount depends on source_currency
    deposit_amount = GetCurrencyRate(src_currency)[1] * amount
    d = DoTransfer(QUARK_WALLET, DEPOSIT_WALLET, deposit_amount)

    order_data = [
        timestamp, utc_offset, expire, src_currency, dst_currency, course,
        amount, src_wallet, dst_wallet, deposit_wallet, deposit_amount, fee,
        oracle, time_margin, min_time, max_time, status, oracle_cost
    ]

    if d == True:
        Put(context, order_key, order_data)
        DispatchOrderEvent(order_key)
        return True

    return False
示例#8
0
文件: test5.py 项目: kambit/test5
def Main(height):
    header = GetHeader(height)
    hash_val = GetHash(header)
    return hash_val
示例#9
0
def get_current_time():
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    current_time = currentBlock.Timestamp

    return current_time
示例#10
0
def Main(height):
    header = GetHeader(height)
    consensus = header.ConsensusData
    return consensus
示例#11
0
def get_now():
    height = GetHeight()
    current_block = GetHeader(height)
    return current_block.Timestamp
def RandomNumber(blockHeight):
    return GetConsensusData(GetHeader(blockHeight))
示例#13
0
def get_height_hash():
    currentHeight = GetHeight()
    currentHeader = GetHeader(currentHeight)
    currentHash = GetHash(currentHeader)

    return currentHash
示例#14
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
示例#15
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        # This should never be necessary but just in case someone
        # accidentally sends non-MCT assets to the contract they
        # can be recovered instead of being burned forever

        if CheckWitness(PARTY1):
            return True

        return False

    elif trigger == Application():

        # setNewPayee(newPayee) - if the current payee wants to assign
        # the tokens to another party, the contract payee can be changed
        # but only if both the depositor and current payee agree

        if operation == 'setNewPayee':
            if len(args) != 1:
                print('New payee scripthash not specified')
                return False

            new_payee = args[0]

            if len(new_payee) != 20:
                print('Incorrect new payee scripthash length')
                return False

            current_payee = Get('payee')

            if len(current_payee) != 20:
                current_payee = PARTY2

            if CheckWitness(PARTY1):  # depositor approval
                party2_payee = Get('Party2_Payee_Change_Approval')
                if new_payee == party2_payee:
                    Put('payee', new_payee)
                    Delete('Party1_Payee_Change_Approval')
                    Delete('Party2_Payee_Change_Approval')
                else:
                    Put('Party1_Payee_Change_Approval', new_payee)
                return True

            if CheckWitness(current_payee):  # current payee approval
                party1_payee = Get('Party1_Payee_Change_Approval')
                if new_payee == party1_payee:
                    Put('payee', new_payee)
                    Delete('Party1_Payee_Change_Approval')
                    Delete('Party2_Payee_Change_Approval')
                else:
                    Put('Party1_Payee_Change_Approval', new_payee)
                return True

            print('Not authorized to approve payee change')
            return False

        # getCurrentPayee() - return currently set payee value

        if operation == 'getCurrentPayee':
            current_payee = Get('payee')

            if len(current_payee) != 20:
                current_payee = PARTY2

            return current_payee

        # getUnlockTime() - return hard-coded unlock timestamp

        if operation == 'getUnlockTime':
            return unlockTime

        # withdraw() - if this operation is called after the unlock
        # period, the entire contract balance will be automatically
        # transferred to the current payee

        if operation == 'withdraw':
            header = GetHeader(GetHeight())
            if header.Timestamp < unlockTime:
                print('unlock period has not yet expired')
                return False

            # This contract's script hash, owner of the locked MCT tokens
            myhash = GetExecutingScriptHash()

            # Payout to current payee address
            payee = Get('payee')

            if len(payee) != 20:
                payee = PARTY2

            t_amount = MCTContract('balanceOf', [myhash])

            if t_amount > 0:
                print('Transferring all funds in contract to payee')
                return MCTContract('transfer', [myhash, payee, t_amount])
            else:
                print('No funds in contract')
            return False

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

        caller = GetCallingScriptHash()

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

        if operation == 'onTokenTransfer':
            if CheckWitness(PARTY1):
                return True  # this is how party 1 deposits stake+locked tokens

            print('onTokenTransfer() called from address other than party 1')

    return False