|
| 1 | +try: |
| 2 | + import ujson as json |
| 3 | +except ImportError: |
| 4 | + import json |
| 5 | +from copy import deepcopy |
| 6 | + |
1 | 7 | from sovtoken import TokenTransactions |
2 | | -from sovtoken.constants import ADDRESS, OUTPUTS, TOKEN_LEDGER_ID |
| 8 | +from sovtoken.constants import ADDRESS, OUTPUTS, TOKEN_LEDGER_ID, NEXT_SEQNO, UTXO_LIMIT |
3 | 9 | from sovtoken.messages.txn_validator import txt_get_utxo_validate |
4 | 10 | from sovtoken.request_handlers.token_utils import parse_state_key |
5 | 11 | from sovtoken.types import Output |
|
13 | 19 | from plenum.server.database_manager import DatabaseManager |
14 | 20 | from plenum.server.request_handlers.handler_interfaces.read_request_handler import ReadRequestHandler |
15 | 21 | from state.trie.pruning_trie import rlp_decode |
| 22 | +from stp_core.config import MSG_LEN_LIMIT |
16 | 23 |
|
17 | 24 |
|
18 | 25 | class GetUtxoHandler(ReadRequestHandler): |
@@ -56,10 +63,21 @@ def get_result(self, request: Request): |
56 | 63 | continue |
57 | 64 | outputs.add(Output(addr, int(seq_no), int(amount))) |
58 | 65 |
|
| 66 | + utxos = outputs.sorted_list |
| 67 | + next_seqno = None |
| 68 | + if len(utxos) > UTXO_LIMIT: |
| 69 | + next_seqno = utxos[UTXO_LIMIT].seqNo |
| 70 | + utxos = utxos[:UTXO_LIMIT] |
| 71 | + |
59 | 72 | result = {f.IDENTIFIER.nm: request.identifier, |
60 | | - f.REQ_ID.nm: request.reqId, OUTPUTS: outputs.sorted_list} |
61 | | - if proof: |
62 | | - result[STATE_PROOF] = proof |
| 73 | + f.REQ_ID.nm: request.reqId, OUTPUTS: utxos} |
63 | 74 |
|
64 | 75 | result.update(request.operation) |
| 76 | + if next_seqno: |
| 77 | + result[NEXT_SEQNO] = next_seqno |
| 78 | + if proof: |
| 79 | + res_sub = deepcopy(result) |
| 80 | + res_sub[STATE_PROOF] = proof |
| 81 | + if len(json.dumps(res_sub)) <= MSG_LEN_LIMIT: |
| 82 | + result = res_sub |
65 | 83 | return result |
0 commit comments