nistbeacon/nistbeacon.py
def chain_check(cls, timestamp: int) -> bool:
        """
        Given a record timestamp, verify the chain integrity.

        :param timestamp: UNIX time / POSIX time / Epoch time
        :return: 'True' if the timestamp fits the chain. 'False' otherwise.
        """

        # Creation is messy.
        # You want genius, you get madness; two sides of the same coin.
        # ... I'm sure this can be cleaned up. However, let's test it first.

        record = cls.get_record(timestamp)

        if isinstance(record, NistBeaconValue) is False:
            # Don't you dare try to play me
            return False

        prev_record = cls.get_previous(record.timestamp)
        next_record = cls.get_next(record.timestamp)

        if prev_record is None and next_record is None:
            # Uh, how did you manage to do this?
            # I'm not even mad, that's amazing.
            return False

        if (
                isinstance(prev_record, NistBeaconValue) and
                isinstance(next_record, NistBeaconValue)
        ):
            # Majority case, somewhere in the middle of the chain
            # True if:
            #   - All three records have proper signatures
            #   - The requested record's previous output equals previous
            #   - The next possible record's previous output equals the record
            return (
                record.valid_signature and
                prev_record.valid_signature and
                next_record.valid_signature and
                record.previous_output_value == prev_record.output_value and
                next_record.previous_output_value == record.output_value
            )

        if (
                prev_record is None and
                isinstance(next_record, NistBeaconValue)
        ):
            # Edge case, this was potentially the first record of all time
            return (
                record.valid_signature and
                next_record.valid_signature and
                cls._INIT_RECORD == record and
                next_record.previous_output_value == record.output_value
            )

        if (
                isinstance(prev_record, NistBeaconValue) and
                next_record is None
        ):
            # Edge case, this was potentially the latest and greatest
            return (
                record.valid_signature and
                prev_record.valid_signature and
                record.previous_output_value == prev_record.output_value
            )
def chain_check(cls, timestamp: int) -> bool:
        # Creation is messy.
        # You want genius, you get madness; two sides of the same coin.
        # ... I'm sure this can be cleaned up. However, let's test it first.

        record = cls.get_record(timestamp)

        if isinstance(record, NistBeaconValue) is False:
            # Don't you dare try to play me
            return False

        prev_record = cls.get_previous(record.timestamp)
        next_record = cls.get_next(record.timestamp)

        if prev_record is None and next_record is None:
            # Uh, how did you manage to do this?
            # I'm not even mad, that's amazing.
            return False

        if (
                isinstance(prev_record, NistBeaconValue) and
                isinstance(next_record, NistBeaconValue)
        ):
            # Majority case, somewhere in the middle of the chain
            # True if:
            #   - All three records have proper signatures
            #   - The requested record's previous output equals previous
            #   - The next possible record's previous output equals the record
            return (
                record.valid_signature and
                prev_record.valid_signature and
                next_record.valid_signature and
                record.previous_output_value == prev_record.output_value and
                next_record.previous_output_value == record.output_value
            )

        if (
                prev_record is None and
                isinstance(next_record, NistBeaconValue)
        ):
            # Edge case, this was potentially the first record of all time
            return (
                record.valid_signature and
                next_record.valid_signature and
                cls._INIT_RECORD == record and
                next_record.previous_output_value == record.output_value
            )

        if (
                isinstance(prev_record, NistBeaconValue) and
                next_record is None
        ):
            # Edge case, this was potentially the latest and greatest
            return (
                record.valid_signature and
                prev_record.valid_signature and
                record.previous_output_value == prev_record.output_value
            )
def chain_check ( cls , timestamp : int ) -> bool : # Creation is messy. # You want genius, you get madness; two sides of the same coin. # ... I'm sure this can be cleaned up. However, let's test it first. record = cls . get_record ( timestamp ) if isinstance ( record , NistBeaconValue ) is False : # Don't you dare try to play me return False prev_record = cls . get_previous ( record . timestamp ) next_record = cls . get_next ( record . timestamp ) if prev_record is None and next_record is None : # Uh, how did you manage to do this? # I'm not even mad, that's amazing. return False if ( isinstance ( prev_record , NistBeaconValue ) and isinstance ( next_record , NistBeaconValue ) ) : # Majority case, somewhere in the middle of the chain # True if: #   - All three records have proper signatures #   - The requested record's previous output equals previous #   - The next possible record's previous output equals the record return ( record . valid_signature and prev_record . valid_signature and next_record . valid_signature and record . previous_output_value == prev_record . output_value and next_record . previous_output_value == record . output_value ) if ( prev_record is None and isinstance ( next_record , NistBeaconValue ) ) : # Edge case, this was potentially the first record of all time return ( record . valid_signature and next_record . valid_signature and cls . _INIT_RECORD == record and next_record . previous_output_value == record . output_value ) if ( isinstance ( prev_record , NistBeaconValue ) and next_record is None ) : # Edge case, this was potentially the latest and greatest return ( record . valid_signature and prev_record . valid_signature and record . previous_output_value == prev_record . output_value )
Given a record timestamp, verify the chain integrity.

        :param timestamp: UNIX time / POSIX time / Epoch time
        :return: 'True' if the timestamp fits the chain. 'False' otherwise.
Given a record timestamp verify the chain integrity .