Exemple #1
0
    def validate_block_timestamp(self, last_block_timestamp):
        if last_block_timestamp >= self.blockheader.timestamp:
            return False
        curr_time = ntp.getTime()
        if curr_time == 0:
            return False

        max_block_number = int((curr_time - last_block_timestamp) / c.block_creation_seconds)
        if self.blockheader.blocknumber > max_block_number:
            return False
Exemple #2
0
    def create(self, chain, blocknumber, hashchain_link, prev_blockheaderhash, number_transactions, hashedtransactions,
               number_stake, hashedstake, reveal_list=None, vote_hashes=None, last_block_number=-1):
        self.blocknumber = blocknumber
        self.hash = hashchain_link
        if self.blocknumber == 0:
            self.timestamp = 0
        else:
            self.timestamp = ntp.getTime()
            if self.timestamp == 0:
                printL(('Failed to get NTP timestamp'))
                return
        self.prev_blockheaderhash = prev_blockheaderhash
        self.number_transactions = number_transactions
        self.merkle_root_tx_hash = hashedtransactions
        self.number_stake = number_stake
        self.hashedstake = hashedstake
        self.reveal_list = reveal_list
        self.vote_hashes = vote_hashes
        self.epoch = self.blocknumber // c.blocks_per_epoch  # need to add in logic for epoch stake_list recalculation..

        if self.blocknumber == 0:
            self.stake_selector = ''
            self.stake_nonce = 0
            self.block_reward = 0
        elif self.blocknumber == 1:
            tmp_chain, _ = chain.select_hashchain(
                last_block_headerhash=chain.block_chain_buffer.get_strongest_headerhash(0), hashchain=chain.hash_chain,
                blocknumber=self.blocknumber)
            self.stake_nonce = c.blocks_per_epoch - tmp_chain.index(hashchain_link)
            self.stake_selector = chain.mining_address
            self.block_reward = self.block_reward_calc()
        else:
            for s in chain.block_chain_buffer.stake_list_get(self.blocknumber):
                if s[0] == chain.mining_address:
                    self.stake_nonce = s[2] + 1
            self.stake_selector = chain.mining_address
            self.block_reward = self.block_reward_calc()

        self.headerhash = sha256(
            self.stake_selector + str(self.epoch) + str(self.stake_nonce) + str(self.block_reward) + str(
                self.timestamp) + self.hash + str(self.blocknumber) + self.prev_blockheaderhash + str(
                self.number_transactions) + self.merkle_root_tx_hash + str(self.number_stake) + self.hashedstake)

        data = chain.my[0][1]
        S = data.SIGN(self.headerhash)
        self.i = S[0]
        self.signature = S[1]
        self.merkle_path = S[2]
        self.i_bms = S[3]
        self.pub = S[4]
        self.PK = S[5]