def _commit_block(self, height, block_id, hash_of_previous, bits, timestamp, target): cursor = self.db.cursor() cursor.execute('''SELECT totalWork FROM blocks WHERE height=?''', (height-1,)) total_work = cursor.fetchone()[0] + CBlockHeader.calc_difficulty(bits) cursor = self.db.cursor() cursor.execute('''INSERT INTO blocks(totalWork, height, blockID, hashOfPrevious, timestamp, target) VALUES (?,?,?,?,?,?)''', (total_work, height, block_id, hash_of_previous, timestamp, target)) self.db.commit() self._cull()
def _commit_block(self, height, block_id, hash_of_previous, bits, timestamp, target): cursor = self.db.cursor() cursor.execute('''SELECT totalWork FROM blocks WHERE height=?''', (height - 1, )) total_work = cursor.fetchone()[0] + CBlockHeader.calc_difficulty(bits) cursor = self.db.cursor() cursor.execute( '''INSERT INTO blocks(totalWork, height, blockID, hashOfPrevious, timestamp, target) VALUES (?,?,?,?,?,?)''', (total_work, height, block_id, hash_of_previous, timestamp, target)) self.db.commit() self._cull()
def difficulty(self): """Returns the block's difficulty target as a float""" if self._difficulty is None: self._difficulty = CBlockHeader.calc_difficulty(self.bits) return self._difficulty