|
1 | 1 | # coding=utf-8 |
2 | 2 | # Distributed under the MIT software license, see the accompanying |
3 | 3 | # file LICENSE or http://www.opensource.org/licenses/mit-license.php. |
4 | | -from typing import Dict # noqa |
| 4 | +from typing import Dict, Optional # noqa |
| 5 | +from pyqrllib.pyqrllib import bin2hstr |
5 | 6 |
|
6 | 7 | from qrl.core.AddressState import AddressState # noqa |
7 | 8 | from qrl.core.Block import Block |
@@ -36,6 +37,9 @@ def __init__(self, |
36 | 37 | self.hash_chain = hash_chain |
37 | 38 | self.voted_weight = 0 |
38 | 39 | self.total_stake_amount = 0 |
| 40 | + self.approved_txns = dict() |
| 41 | + for tx in block.transactions: |
| 42 | + self.approved_txns[bin2hstr(tx.transaction_hash)] = tx |
39 | 43 |
|
40 | 44 | def update_vote_metadata(self, prev_stake_validators_tracker): |
41 | 45 | self.total_stake_amount = prev_stake_validators_tracker.get_total_stake_amount() |
@@ -73,3 +77,16 @@ def update_stxn_state(self, pstate): |
73 | 77 | self.address_state_dict[addr].pubhashes == addr_state.pubhashes and \ |
74 | 78 | self.address_state_dict[addr].tokens == addr_state.tokens: |
75 | 79 | del self.address_state_dict[addr] |
| 80 | + |
| 81 | + def contains_txn(self, transaction_hash: bytes) -> bool: |
| 82 | + if bin2hstr(transaction_hash) in self.approved_txns: |
| 83 | + return True |
| 84 | + |
| 85 | + return False |
| 86 | + |
| 87 | + def get_txn(self, transaction_hash: bytes) -> Optional[bool]: |
| 88 | + txhash = bin2hstr(transaction_hash) |
| 89 | + if txhash in self.approved_txns: |
| 90 | + return self.approved_txns[txhash] |
| 91 | + |
| 92 | + return None |
0 commit comments