Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle chaincode pagination #352

Merged
merged 5 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion backend/substrapp/ledger/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,19 @@ def call_ledger(channel_name, call_type, fcn, *args, **kwargs):
ts = time.time()
error = None
try:
return _call_ledger(channel_name, call_type, fcn, *args, **kwargs)
response = _call_ledger(channel_name, call_type, fcn, *args, **kwargs)

if isinstance(response, dict) and 'bookmark' in response:
results = response['results'] # first results
while response['results'] and len(response['bookmark']) > 0:
inelgnu marked this conversation as resolved.
Show resolved Hide resolved
kwargs['args'] = {'bookmark': response['bookmark']}
response = _call_ledger(channel_name, call_type, fcn, *args, **kwargs)
results.extend(response['results']) # following results
else:
response = results

return response

except Exception as e:
error = e.__class__.__name__
raise
Expand Down
14 changes: 13 additions & 1 deletion backend/substrapp/tests/tests_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from substrapp.ledger.exceptions import LedgerAssetNotFound, LedgerInvalidResponse

from substrapp.ledger.api import get_object_from_ledger, log_fail_tuple, log_start_tuple, \
log_success_tuple, query_tuples
log_success_tuple, query_tuples, call_ledger

from .assets import traintuple

import os

Expand Down Expand Up @@ -136,3 +138,13 @@ def test_path_traversal(self):
with self.assertRaises(Exception):
model_dst_path = os.path.join(DIRECTORY, 'model/../../hackermodel')
raise_if_path_traversal([model_dst_path], os.path.join(DIRECTORY, 'model/'))

def test_call_ledger_with_bookmark(self):

with patch('substrapp.ledger.api._call_ledger') as m_call_ledger:
m_call_ledger.side_effect = [
{'results': traintuple[i:i + 2], 'bookmark': f'bookmark_{i}'}
for i in range(0, len(traintuple), 2)
] + [{'results': "", 'bookmark': 'bookmark_end'}]
response = call_ledger(CHANNEL, 'query', 'queryTraintuples')
self.assertEqual(response, traintuple)