Exemplo n.º 1
0
 def get_receipt(self, tx_hash):
     lookup = Lookup.transaction(tx_hash)
     if lookup in self.db:
         height, seek_index = loads(self.db.get(lookup))
         header = self.get_header_from_height(height)
         receipt_root = header.hash_receipt_root
         trie = prepare_trie(receipt_root, self.db)
         trie_key = get_trie_key(int_to_bytes32(seek_index))
         receipt = trie.get(trie_key)
         return receipt
Exemplo n.º 2
0
 def get_transaction_from_lookup(self, tx_hash) -> BaseTransaction:
     lookup = Lookup.transaction(tx_hash)
     if lookup in self.db:
         height, seek_index = loads(self.db.get(lookup))
         header = self.get_header_from_height(height)
         tx_root = header.hash_transaction_root
         trie = prepare_trie(tx_root, self.db)
         trie_key = get_trie_key(int_to_bytes32(seek_index))
         tx = trie.get(trie_key)
         return tx
Exemplo n.º 3
0
 def get_vote_from_lookup(self, vote_hash) -> BaseVote:
     lookup = Lookup.vote(vote_hash)
     if lookup in self.db:
         height, seek_index = loads(self.db.get(lookup))
         header = self.get_header_from_height(height)
         vote_root = header.hash_vote_root
         trie = prepare_trie(vote_root, self.db)
         trie_key = get_trie_key(int_to_bytes32(seek_index))
         vote = trie.get(trie_key)
         return vote
Exemplo n.º 4
0
 def _get_const_validator(self):
     # update coming soon TODO
     trie_key = get_trie_key(Lookup.constant_rep())
     validators = self._trie.get(trie_key)
     list_validators = []
     for rep in validators:
         ex = extract_values(rep, REP_DICT)
         rep_obj = prepare_rep(node_id=ex.node_id.encode(),
                               account=ex.account.encode(),
                               delegate=ex.delegated)
         list_validators.append(rep_obj)
     return list_validators
Exemplo n.º 5
0
 def _set_const_validator(self, address, rep_id):
     # update coming soon TODO
     trie_key = get_trie_key(Lookup.constant_rep())
     rep = prepare_rep(node_id=rep_id,
                       account=address,
                       delegate=self.get_delegated_balance(address))
     try:
         qualify = self.get_const_validator_list()
         qualify.append(rep.to_dict())
         self._trie.put(trie_key, qualify)
     except KeyError:
         self._trie.put(trie_key, [rep.to_dict()])
Exemplo n.º 6
0
    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
            )
Exemplo n.º 7
0
 def set_minimum(self, value):
     self._db.put(Lookup.minimum(), int_to_bytes32(value))
Exemplo n.º 8
0
 def get_minimum(self):
     return bytes_to_int(self._db.get(Lookup.minimum()))
Exemplo n.º 9
0
 def _get_const_validator_list(self):
     trie_key = get_trie_key(Lookup.constant_rep())
     reps = self._trie.get(trie_key)
     return reps
Exemplo n.º 10
0
 def _set_vote_from_lookup(self, height, seek_index, vote):
     lookup_key = Lookup.vote(vote.hash)
     leaf_key = dumps((height, seek_index))
     self.db.put(lookup_key, leaf_key)
Exemplo n.º 11
0
 def _set_transaction_from_lookup(self, height, seek_index, transaction):
     lookup_key = Lookup.transaction(transaction.hash)
     leaf_key = dumps((height, seek_index))
     self.db.put(lookup_key, leaf_key)
Exemplo n.º 12
0
 def has_transaction(self, tx_hash):
     lookup = Lookup.transaction(tx_hash)
     return lookup in self.db
Exemplo n.º 13
0
 def get_current_height(self):
     return bytes_to_int(self.db.get(Lookup.top_header()))