def commit(self, block: BaseBlock): self.db.put(Lookup.top_header(), int_to_bytes32(block.header.num_height)) # not padding. self.db.put(int_to_bytes32(block.header.num_height), self.serialize(block.header)) self.db.put(block.hash, self.serialize(block)) # Lookup(height, index) -> # block tx root -> Trie.root = root hash -> Trie.get(index-key) for index, tx in enumerate(block.list_transactions): self._set_transaction_from_lookup( block.height, index, tx ) for index, vote in enumerate(block.list_vote): self._set_vote_from_lookup( block.height, index, vote )
def get_current_height(self): return bytes_to_int(self.db.get(Lookup.top_header()))