Beispiel #1
0
def Main(operation, key, stop):

    context = GetContext()

    height = GetHeight()

    header = GetHeader(height)

    now = header.Timestamp()

    if operation == 'create':

        Put(context, key, stop)
        print(now)
        return stop

    if operation == 'end':

        out = Get(context, key)

        if now > out:

            print('money returned!')
            return out

    return False
Beispiel #2
0
def Main():
    """

    :return:
    """
    header = GetHeader(1234)

    m2 = header.Timestamp + header.Timestamp

    Notify(m2)

    bheight = 32

    block = GetBlock(bheight)

    Notify(block)

    tx = block.Transactions[0]

    Notify(tx.Hash)

    #    Notify(tx)
    #    tx = block.Transactions[0] #  this doesnt seem to work
    #    txhash = tx.Hash

    #    Notify(txhash)

    return 1
Beispiel #3
0
def Main(block_index):
    """

    :param block_index:
    :return:
    """
    header = GetHeader(block_index)

    print("got block!")

    ts = header.Timestamp

    print("got timestamp")

    block = GetBlock(block_index)

    for tx in block.Transactions:

        type = GetType(tx)
        hash = GetHash(tx)
        Notify(type)
        is_invoke = False
        if type == INVOKE_TX_TYPE:
            is_invoke = True

        if hash == b'\xa0ljY\xd8n\x1b\xb5\xdb\xa0\xf5d\xd8\xb3\xd8\xec\xf2\xfb\xe3E\xe3|3\xba\x83\xf2$jW\xa24':
            print("correct hash!")
        else:
            print("hash does not match")

    return ts
Beispiel #4
0
def Main():

    #    blockhash = b'\xe9F.\xbd\x83\x99\xb4\xa3Z\xdc\xdde\xe5^\xed\xf6\x9f\x82\xa3\x14\xc9y\x04\xb8\xfe\x8cb\xafO.\xe7\xd9'
    """

    :return:
    """

    print("hello?")
    block = GetCurrentBlock()

    index = block.Index
    print("hello")

    hash = block.Hash

    header = GetHeader(index)

    Notify(hash)

    Notify(header)

    Notify(header.Index)

    return index
Beispiel #5
0
def CheckTimestamp(timestamp_normalised):
    # Checks if TS() > T_n + deadline
    height = GetHeight()
    hdr = GetHeader(height)
    ts = GetTimestamp(hdr)
    if ts > timestamp_normalised + deadline:
        return True
    return False
Beispiel #6
0
def CheckTimestamp(timestamp_normalised):
    # Checks if TS() > T_n + 8 minutes
    height = GetHeight()
    hdr = GetHeader(height)
    ts = GetTimestamp(hdr)
    if ts > timestamp_normalised + 480:
        return True
    return False
Beispiel #7
0
def _TimeHasExpired():
    context = GetContext()
    currentHeight = GetHeight()
    print("got current height")
    currentHeader = GetHeader(currentHeight)
    print("got current block...")
    endTime = Get(context, 'endTime')
    return endTime < currentHeader.Timestamp
Beispiel #8
0
def submitPost(args):
    # Default args
    user = args[0]
    postHash = args[1]
    category = args[2]
    """
  Validation
  Validating that the IPFS_Hash is not yet used
  """
    postDataDomain = concat("post.data.", postHash)
    condition = Get(GetContext, postDataDomain)
    if condition != '':
        return False
    """
  Adding to post domain
  post.latest                     Latest index of a post in common
  post.{postIndex}                Getting a post by index
  post.data.{IPFS_PostHash}       Getting a post by Hash From IPFS
  """

    # Add to post domain
    addToDomain("post", postHash)

    # Setting post.data.{postHash} = {serializedPostData}
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    time = currentBlock.Timestamp

    postData = [user, category, time]
    to_save = serialize_array(postData)

    Put(GetContext, postDataDomain, to_save)
    """
    Adding to user domain
    user.{userAddress}              User address of a user (Public key/hash)
    user.{userAddress}.latest       Getting the latest post index of a certain user
    user.{userAddress}.{postIndex}  Getting a post from a certain user by index
  """

    # Creating user domain
    userDomain = concat("user.", user)

    # Add to user domain - {user}.latest && {user}.{latestIndex}
    addToDomain(userDomain, postHash)
    """
    Adding to category domain
    category.{category}.latest       Getting the latest post index of a certain category
    category.{category}.{postIndex}  Getting a post from a certain category by index
  """

    # Creating category domain
    categoryDomain = concat("category.", category)

    # Add to category domain - {category}.latest && {category}.{latestIndex}
    addToDomain(categoryDomain, postHash)

    return True
Beispiel #9
0
def Main():
    """
    :return: Current block timestamp
    :rtype: int
    """
    current_height = GetHeight()
    current_block = GetHeader(current_height)
    timestamp = current_block.Timestamp
    return timestamp
def Main(height):
    """
    :param height: The input block height
    :type height: int
    :return: Block hash of the input block height
    :rtype: bytearray
    """
    header = GetHeader(height)
    hash_val = GetHash(header)
    return hash_val
Beispiel #11
0
def Main(height):
    """
    :param height: The input block height
    :type height: int
    :return: Block consensus data of the input block height
    :rtype: bytearray
    """
    header = GetHeader(height)
    consensus = header.ConsensusData
    return consensus
def Main(height):
    """
    :param height: The input block height
    :type height: int
    :return: Next consensus data of the input block height
    :rtype: bytearray
    """
    header = GetHeader(height)
    next_consensus = header.NextConsensus
    return next_consensus
Beispiel #13
0
def Main(height):
    """
    :param height: The input block height
    :type height: int
    :return: Block timestamp of the input block height
    :rtype: int
    """
    header = GetHeader(height)
    timestamp = header.Timestamp
    return timestamp
def Main(height):
    """
    :param height: The input block height
    :type height: int
    :return: Block merkle root of the input block height
    :rtype: bytearray
    """
    header = GetHeader(height)
    merkle_root = GetMerkleRoot(header)
    return merkle_root
Beispiel #15
0
def SetTime():
    if _TimeHasExpired():
        context = GetContext()
        currentHeight = GetHeight()
        currentHeader = GetHeader(currentHeight)
        time = currentHeader.Timestamp + TWOWEEKS
        print('setting time')
        print(time)
        Put(context, "endTime", time)
        return time
    return 0
Beispiel #16
0
def ResultNotice(agreement_key, weather_param, oracle_cost):
    """
    Method to signal resulte by oracle

    :param agreement_key: the key of the agreement
    :type agreement_key: bytearray

    :param weather_param: weather parameter that the contract is depending on
    :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 agreement
    context = GetContext()
    agreement_data = Get(context, agreement_key)
    oracle = agreement_data[8]

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

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

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

    agreement_data[12] = 'result-noticed'
    agreement_data[13] = weather_param
    agreement_data[14] = oracle_cost

    # Get timestamp of current block
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    current_time = currentBlock.Timestamp

    Put(context, agreement_key, agreement_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(agreement_key, weather_param, oracle_cost)
        return True
def do_current_timestamp() -> bytearray:
    Log('do_current_timestamp triggered.')
    current_height = GetHeight()
    Log('current_height:')
    Log(current_height)
    current_block = GetHeader(current_height)
    # Log('current_block:')
    # Log(current_block)
    timestamp = current_block.Timestamp
    Log('timestamp:')
    Log(timestamp)  # Example b'\xc1\xc7|Z'
    return timestamp
Beispiel #18
0
def GetCurrentTimestamp():
    """
    Get the current timestamp from the block's info

    :return: Unix timestamp.
    :rtype: int

    """
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    time = currentBlock.Timestamp
    return time
Beispiel #19
0
def Main(a, b):

    c = a + b

    header = GetHeader(345)

    header2 = GetHeader(2321)

    # this does not work
    #    header3 = GetHeader( get_block_height())

    # this does work?
    header3 = GetHeader(get_block_height)

    # this does not work
    #    header4 = GetHeader( get_block_height_again(4) )

    # test wether you can pass an object property to method calls
    res = process_hash(header.Hash, header2.Hash)
    # expect bytearray(b'\x86\xdce\x18\x13\x90\x8d\x9f\x8bsi\x87l\x06x\xd6\xc6g\x13\xc7E\x83\xc9\xf4>P\xbc\x18\xfd\xcd\xec\xc7\xa3\xd5B\xe6{G\x84d\xa5\xc3!\xc5_\xe3\x8aE*C\x98r\xd7k\x8f3Q6y\xf3\x95\xc5\xc1;')

    # test compairing object properties
    if header2.Timestamp > header.Timestamp:
        print("header 2 is less")
    else:
        print("header 1 is less")

    # this messes things up
    # method_without_return()

    # this is ok, even if method doesnt return anything


#    n = method_without_return()

# this also works
    n = method_without_return

    # test returning the results of object properties
    return header.Timestamp + header2.Timestamp
def do_get_timestamp(args: list) -> bytearray:
    Log('do_get_timestamp triggered.')
    if len(args) > 0:
        height = args[0]
        Log('height:')
        Log(height)
        header = GetHeader(height)
        timestamp = header.Timestamp
        Log('timestamp:')
        Log(timestamp)
        return timestamp
    Notify('invalid argument length')
    return False
def do_get_next_consensus(args: list) -> bytearray:
    Log('do_get_next_consensus triggered.')
    if len(args) > 0:
        height = args[0]
        Log('height:')
        Log(height)
        header = GetHeader(height)
        next_consensus = header.NextConsensus
        Log('next_consensus:')
        Log(next_consensus)
        return next_consensus
    Notify('invalid argument length')
    return False
Beispiel #22
0
def CheckTimestamp(timestamp_normalised):
    # Checks if TS() > T_n + deadline
    height = GetHeight()
    hdr = GetHeader(height)
    ts = GetTimestamp(hdr)
    Log(ts)
    Log(timestamp_normalised)
    nd = ts - deadline
    Log(nd)
    diff = nd - timestamp_normalised
    Log(diff)
    if nd > timestamp_normalised:
        return True
    return False
def do_get_block_hash(args: list) -> bytearray:
    Log('do_get_block_hash triggered.')
    if len(args) > 0:
        height = args[0]
        Log('height:')
        Log(height)
        header = GetHeader(height)
        # version = GetVersion(header)
        hash_val = GetHash(header)
        Log('hash_val:')
        Log(hash_val)
        return hash_val
    Notify('invalid argument length')
    return False
Beispiel #24
0
def CheckTiming(timestamp_normalised):
    # Check T_n relative to current TS()
    height = GetHeight()
    hdr = GetHeader(height)
    ts = GetTimestamp(hdr)
    Log(ts)
    t_n_plus_one = timestamp_normalised + Game_rules.timestep
    Log(t_n_plus_one)
    Log(timestamp_normalised)
    if ts > t_n_plus_one:
        return 1 # expired
    elif ts < timestamp_normalised:
        return 2 # too early to submit, ignore
    else:
        return 0 # all good
Beispiel #25
0
def Main(operation):
    """
    :param operation: get or put
    :param args: optional arguments
    :return: Bool
    """

    trigger = GetTrigger()
    if trigger == Application:
        Log("trigger: Application")
        height = GetHeight()
        hdr = GetHeader(height)
        ts = GetTimestamp(hdr)
        Log(ts)
        return True
    return False
def do_get_merkle_root(args: list) -> bytearray:
    Log('do_get_merkle_root triggered.')
    if len(args) > 0:
        height = args[0]
        Log('height:')
        Log(height)
        header = GetHeader(height)
        version = GetVersion(header)
        Log('version:')
        Log(version)
        merkle_root = GetMerkleRoot(header)
        Log('merkle_root:')
        Log(merkle_root)
        return merkle_root
    Notify('invalid argument length')
    return False
Beispiel #27
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
Beispiel #28
0
def IsPromoExpired(promo_id):
    """
    Check if promo has expired or not

    Args:
        promo_id (str): promo unique id

    Returns:
        (bool): True if promotion has expired
    """
    context = GetContext()
    expiration_key = concat(promo_id, 'expiration')
    expiration = Get(context, expiration_key)

    height = GetHeight()
    current_block = GetHeader(height)
    current_time = current_block.Timestamp

    expired = current_time > expiration
    return expired
Beispiel #29
0
def _getWinner():
    entries = GetEntries()
    numEntries = len(entries)
    # Notify(numEntries)
    if numEntries == 0:
        return 0

    currentHeight = GetHeight()
    # Notify(currentHeight)

    currentHeader = GetHeader(currentHeight)
    # Notify(currentHeader)

    currentHash = GetHash(currentHeader)
    # Notify(currentHash)

    winningIndex = currentHash % numEntries
    # Notify(winningIndex)

    winningEntry = entries[winningIndex]

    return winningEntry
Beispiel #30
0
def Main():
    """

    :return:
    """
    height = 1242
    header = GetHeader(height)

    m2 = header.Timestamp + header.Timestamp

    root = header.MerkleRoot

    #    Notify(root)

    hash = header.Hash

    prev = header.PrevHash

    #    Notify(hash)

    #    Notify(prev)

    bheight = 32566

    block = GetBlock(bheight)

    tx = block.Transactions[0]

    Notify(tx)

    #    tx = GetTransaction(block, 0)
    #    tx = GetTransaction(block, 0)
    #    Notify(tx)
    #    tx = block.Transactions[0] #  this doesnt seem to work
    txhash = tx.Hash

    Notify(txhash)

    return 1