Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
def Main(block_height):
    """

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

    Log("got header")

    merkle = GetMerkleRoot(header)

    version = GetVersion(header)

    Notify(version)

    hash = GetHash(header)

    Notify(hash)

    print("got merkle")

    Notify(header)

    a = 1

    Notify(merkle)

    print("getting timestamp")
    ts = GetTimestamp(header)

    Notify(ts)

    if ts == 1494640540:

        return 9

    return a
Exemplo n.º 7
0
    def Timestamp(self):
        """

        :return:
        """
        return GetTimestamp(self)
Exemplo n.º 8
0
    def SubmitPrediction(self, oracle, game_type, instance_ts, prediction,
                         gas_submission):

        #Add in auto-judging
        prev_instance = instance_ts - Game_rules.timestep
        self.JudgeInstance(game_type, prev_instance)

        # Trivial TODO
        # ADD IN GAME_TYPE CHECK

        Log("gas_submission")
        Log(gas_submission)

        # Check T_n relative to current TS()
        height = GetHeight()
        hdr = GetHeader(height)
        ts = GetTimestamp(hdr)
        Log(ts)
        t_n_plus_one = instance_ts + Game_rules.timestep
        Log(t_n_plus_one)
        Log(instance_ts)
        if ts > t_n_plus_one:
            #return 1  # expired
            Log("expired")
        elif ts < instance_ts:
            #return 2  # too early to submit, ignore
            Log("too early")
        else:
            #return 0  # all good
            Log("Sweet spot")

        Log(instance_ts)

        if self.isGameInstanceJudged(game_type, instance_ts):
            return "Game Instance already judged"  # Ignore submission
        else:

            # ASSERT: current timestamp is in the sweet spot between T_n and T_n+1

            # Check if Oracle already registered
            if self.isOracleRegisteredForInstance(game_type, instance_ts,
                                                  oracle):
                return "Already registered"
            current_oracle_balance = self.GetOracleBalance(oracle)
            n_oracles_for_instance = self.GetOracleCountForInstance(
                game_type, instance_ts)
            Log(gas_submission)
            if gas_submission == 0:
                if current_oracle_balance >= Game_rules.collateral_requirement:
                    new_count = n_oracles_for_instance + 1
                    self.RegisterOracle(game_type, instance_ts, oracle,
                                        new_count)
                else:
                    # No assets sent and existing balance too low
                    return "Not enough balance to register"
            elif gas_submission == 5:
                Log(current_oracle_balance)
                current_oracle_balance = current_oracle_balance + gas_submission
                Log(current_oracle_balance)
                key = concat(key_prefix_agent_available_balance, oracle)
                Log("updating balance")
                # Updates Balance of Oracle
                context = GetContext()
                Put(context, key, current_oracle_balance)
                new_count = n_oracles_for_instance + 1
                Log(new_count)
                self.RegisterOracle(game_type, instance_ts, oracle, new_count)
                Log("registered oracle")
            else:
                return "Wrong amount of NEO GAS Sent"

            locked = self.GetOracleLockedBalance(oracle)
            new_locked = locked + 5
            self.UpdateLockedBalance(oracle, new_locked)
            new_available = current_oracle_balance - 5
            self.UpdateAvailableBalance(oracle, new_available)

            # Now to submit prediction if no errors
            self.RegisterPrediction(game_type, instance_ts, oracle, prediction)
            p_count = self.IncrementCountForPrediction(game_type, instance_ts,
                                                       prediction)
            Log("Registered and incremented pcount")
            max_so_far = self.GetCurrentMax(game_type, instance_ts)
            Log("max and pcount:")
            Log(max_so_far)
            Log(p_count)
            if p_count > max_so_far:
                # New Current Winner
                self.UpdateMaxVotes(game_type, instance_ts, p_count)
                self.UpdatePrediction(game_type, instance_ts, prediction)
            return True
Exemplo n.º 9
0
def blockTimeStamp():
    current_height = GetHeight()
    current_header = GetHeader(current_height)
    current_time = GetTimestamp(current_header)

    return current_time
Exemplo n.º 10
0
def GetNormalisedTimestamp():
    height = GetHeight()
    hdr = GetHeader(height)
    ts = GetTimestamp(hdr)
    rem = ts % 300
    return ts - rem
Exemplo n.º 11
0
 def now(self):
     height = GetHeight()
     header = GetHeader(height)
     now = GetTimestamp(header)
     return now