Пример #1
0
def test_blocks_to_seconds():
    import terracoinlib
    from decimal import Decimal

    precision = Decimal('0.001')
    assert Decimal(terracoinlib.blocks_to_seconds(0)) == Decimal(0.0)
    assert Decimal(terracoinlib.blocks_to_seconds(2)).quantize(precision) \
        == Decimal(314.4).quantize(precision)
    assert int(terracoinlib.blocks_to_seconds(16616)) == 2612035
Пример #2
0
    def is_expired(self, superblockcycle=None):
        from constants import SUPERBLOCK_FUDGE_WINDOW
        import terracoinlib

        if not superblockcycle:
            raise Exception("Required field superblockcycle missing.")

        printdbg("In Proposal#is_expired, for Proposal: %s" % self.__dict__)
        now = misc.now()
        printdbg("\tnow = %s" % now)

        # half the SB cycle, converted to seconds
        # add the fudge_window in seconds, defined elsewhere in Sentinel
        expiration_window_seconds = int(
            (terracoinlib.blocks_to_seconds(superblockcycle) / 2) +
            SUPERBLOCK_FUDGE_WINDOW)
        printdbg("\texpiration_window_seconds = %s" %
                 expiration_window_seconds)

        # "fully expires" adds the expiration window to end time to ensure a
        # valid proposal isn't excluded from SB by cutting it too close
        fully_expires_at = self.end_epoch + expiration_window_seconds
        printdbg("\tfully_expires_at = %s" % fully_expires_at)

        if (fully_expires_at < now):
            printdbg("\tProposal end_epoch [%s] < now [%s] , returning True" %
                     (self.end_epoch, now))
            return True

        printdbg("Leaving Proposal#is_expired, Expired = False")
        return False
Пример #3
0
    def estimate_block_time(self, height):
        import terracoinlib
        """
        Called by block_height_to_epoch if block height is in the future.
        Call `block_height_to_epoch` instead of this method.

        DO NOT CALL DIRECTLY if you don't want a "Oh Noes." exception.
        """
        current_block_height = self.rpc_command('getblockcount')
        diff = height - current_block_height

        if (diff < 0):
            raise Exception("Oh Noes.")

        future_seconds = terracoinlib.blocks_to_seconds(diff)
        estimated_epoch = int(time.time() + future_seconds)

        return estimated_epoch