diff --git a/README.md b/README.md index de885ed..4577694 100644 --- a/README.md +++ b/README.md @@ -236,81 +236,6 @@ $ remme node-account get \ ### Block -Get a list of blocks — ``remme block get-list``: - -| Arguments | Type | Required | Description | -| :---------: | :-----: | :-------: | -------------------------------------------------- | -| ids | String | No | Identifiers to get a list of blocks by. | -| limit | Integer | No | Maximum amount of blocks to return. | -| head | Integer | No | Block identifier to get a list of transactions to. | -| reverse | Bool | No | Parameter to reverse result. | -| node-url | String | No | Node URL to apply a command to. | - -```bash -$ remme block get-list \ - --ids='fe56a16dab009cc96e7125c647b6c71eb1063818cf8dece283b125423ecb184f7f1e61802bf66382da904698413f80831031f8a1b29150260c3fa4db537fdf4c, - 56100bf24eed12d2f72fe3c3ccf75fe2f53d87c224d9dda6fb98a1411070b06a40fcf97fccc61cb9c88442953af6ae50344ad7773f1becc6bae108443c18c551' \ - --head=fe56a16dab009cc96e7125c647b6c71eb1063818cf8dece283b125423ecb184f7f1e61802bf66382da904698413f80831031f8a1b29150260c3fa4db537fdf4c \ - --limit=2 \ - --reverse \ - --node-url=node-genesis-testnet.remme.io -{ - "result": [ - { - "batches": [ - { - "header": { - "signer_public_key": "02d1fbda50dbcd0d3c286a6a9fa71aa7ce2d97159b90ddd463e0816422d621e135", - "transaction_ids": [ - "6593d21046519022ba32c98e934d7dfc81e8b4edf6c064dbf70feb13db4310873ec00816bce8660cafd4fa2a8c80d0147d63cf616c624babd03142c694272017" - ] - }, - "header_signature": "fa2d1a209ad04fd2ad7fb5183976e647cc47b4c08e2e578097afc2566a0284e760eb3f2ff8f72f290765211d4da3341f23091cc7a16805025a17c04a90818a44", - "trace": false, - "transactions": [ - { - "header": { - "batcher_public_key": "02d1fbda50dbcd0d3c286a6a9fa71aa7ce2d97159b90ddd463e0816422d621e135", - "dependencies": [], - "family_name": "block_info", - "family_version": "1.0", - "inputs": [ - "00b10c0100000000000000000000000000000000000000000000000000000000000000", - "00b10c00" - ], - "nonce": "", - "outputs": [ - "00b10c0100000000000000000000000000000000000000000000000000000000000000", - "00b10c00" - ], - "payload_sha512": "1b2cdc6ecfb575b926abea76b44e6988617e945e0f3d84b7624ee228cf35252a7cd186eabe5126c5f967ff54d0b1001e2c07716a7d9e00b5710e836400a913d5", - "signer_public_key": "02d1fbda50dbcd0d3c286a6a9fa71aa7ce2d97159b90ddd463e0816422d621e135" - }, - "header_signature": "6593d21046519022ba32c98e934d7dfc81e8b4edf6c064dbf70feb13db4310873ec00816bce8660cafd4fa2a8c80d0147d63cf616c624babd03142c694272017", - "payload": "CtMCCLwBEoABOWI4Y2NhODk3Nzk2NDJiYWEyMGMwZWUyZjEzOWVlMGNlMWNjYjEwMjY5OTVjNDY3NDYzZDEzOTI0ZDg3YTg3NjNlODMzOWI2YzIyMzNmMTZiY2I5ZDVjNjEwMzVmNzAzY2FiNjBiNzQxMGJlMjJkZjkzNWEyYWE4YmIzNGE1NTcaQjAyZDFmYmRhNTBkYmNkMGQzYzI4NmE2YTlmYTcxYWE3Y2UyZDk3MTU5YjkwZGRkNDYzZTA4MTY0MjJkNjIxZTEzNSKAAWZkNzgwY2UwNzY0MGJhNDExMjI0ODY5MTU4MWE1OTU4NDVmZTc2MmJmM2ZlYjQ5Yjg0Mzk3NGFhZTU3ODQ3OGM2YmY1MTg3MzllY2RjNDlkNzAxOTM4M2QzYmQ5ZTNhYTZmYTBhZjgzODRiNDQ5MThmMGJmZjM3NDAyYjUxMGIyKMzfgeYF" - } - ] - }, - ... - ], - "header": { - "batch_ids": [ - "fa2d1a209ad04fd2ad7fb5183976e647cc47b4c08e2e578097afc2566a0284e760eb3f2ff8f72f290765211d4da3341f23091cc7a16805025a17c04a90818a44", - "661492181b838636b11ee347312bf5346b4231e0510c5c5bec27ea999ea389a66a1264696ea53e3b30e29b03192154bed8d160f035706da4f0da7f0be107a2b2" - ], - "block_num": "189", - "consensus": "RGV2bW9kZdG76dVw7Q7VRgkNr6HxHnnJxNwI+iySmLepFZPJXvDa", - "previous_block_id": "fd780ce07640ba4112248691581a595845fe762bf3feb49b843974aae578478c6bf518739ecdc49d7019383d3bd9e3aa6fa0af8384b44918f0bff37402b510b2", - "signer_public_key": "02d1fbda50dbcd0d3c286a6a9fa71aa7ce2d97159b90ddd463e0816422d621e135", - "state_root_hash": "693d08c1520c9c1b2dba54ae147bf689f6209f74e304f8ed44e1ec818a08072e" - }, - "header_signature": "fe56a16dab009cc96e7125c647b6c71eb1063818cf8dece283b125423ecb184f7f1e61802bf66382da904698413f80831031f8a1b29150260c3fa4db537fdf4c" - }, - ... - ] -} -``` - Get information about the block by its identifier — ``remme block get``: | Arguments | Type | Required | Description | @@ -530,6 +455,7 @@ Get a list of batches — ``remme batch get-list``: | limit | Integer| No | Maximum amount of batches to return. | | head | String | No | Block identifier to get a list of batches from. | | reverse | Bool | No | Parameter to reverse result. | +| ids-only | Bool | No | The flag to get a list of batches' identifiers. | | node-url | String | No | Node URL to apply a command to. | ```bash @@ -577,7 +503,15 @@ $ remme batch get-list \ } ] } - +Get a list of batch identifiers (can be combined with other parameters like --limit): +$ remme batch get-list --ids-only --node-url=node-6-testnet.remme.io +{ + "result": [ + "e4d5089f2ef1...6b0f185b3b6ca", + "df5e555f...317f039501", + ... + ] +} ``` ### Node @@ -736,7 +670,6 @@ Get a list of transactions — ``remme transaction get-list``: | limit | Integer| No | Maximum amount of transactions to return. | | head | String | No | Block identifier to get a list of transactions from. | | reverse | Bool | No | Parameter to reverse result. | -| ids-only | Bool | No | The flag to get a list of transactions' identifiers. | | node-url | String | No | Node URL to apply a command to. | | family-name | String | No | List of transactions by its family name. | @@ -785,20 +718,6 @@ $ remme transaction get-list \ } ``` -Get a list of transactions' identifiers (can be combined with other parameters like `--limit`): - -```bash -$ remme transaction get-list --ids-only --node-url=node-6-testnet.remme.io -{ - "result": [ - "eb662acc48d313c9bba4a72359b0462d607bba8fc66aeb3d169d02fafd21849b6bf8bea8396b54b6fc907e1cce2a386f76bd19889d0f3e496b45b8440b161ebc", - "206a3767f368c1db9d07b273f80d4824d201ae61b9ced8a6aeedac58032c5557544ac622d5e3fd59f6d9873d97af1c6114d0131b4b1a191cbba7d5a8aa5a3caf", - "63ed3259b6067525ae241a12f66b5be1e1502cdbd6f475b139bf94cf4ba842643577835fcef0482d25190243b8dfab3a1f9913f7fd0edc425ad0c19333d8bd4b", - ... - ] -} -``` - Get a transaction by identifier — ``remme transaction get``: | Arguments | Type | Required | Description | diff --git a/cli/batch/cli.py b/cli/batch/cli.py index a4cf0b0..5f99ac6 100644 --- a/cli/batch/cli.py +++ b/cli/batch/cli.py @@ -15,6 +15,7 @@ BATCH_HEAD_ARGUMENT_HELP_MESSAGE, BATCH_ID_ARGUMENT_HELP_MESSAGE, BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE, + BATCH_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE, BATCH_LIMIT_ARGUMENT_HELP_MESSAGE, BATCH_REVERSE_ARGUMENT_HELP_MESSAGE, BATCH_START_ARGUMENT_HELP_MESSAGE, @@ -109,9 +110,10 @@ def get_batch_status(id, node_url): @click.option('--limit', required=False, type=int, help=BATCH_LIMIT_ARGUMENT_HELP_MESSAGE) @click.option('--head', required=False, type=str, help=BATCH_HEAD_ARGUMENT_HELP_MESSAGE) @click.option('--reverse', required=False, is_flag=True, help=BATCH_REVERSE_ARGUMENT_HELP_MESSAGE) +@click.option('--ids-only', required=False, is_flag=True, help=BATCH_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE) @click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) @batch_commands.command('get-list') -def get_batches(ids, start, limit, head, reverse, node_url): +def get_batches(ids, start, limit, head, reverse, ids_only, node_url): """ Get a list of batches. """ @@ -121,6 +123,7 @@ def get_batches(ids, start, limit, head, reverse, node_url): 'limit': limit, 'head': head, 'reverse': reverse, + 'ids_only': ids_only, 'node_url': node_url, }) @@ -132,19 +135,29 @@ def get_batches(ids, start, limit, head, reverse, node_url): start = arguments.get('start') limit = arguments.get('limit') head = arguments.get('head') + ids_only = arguments.get('ids_only') node_url = arguments.get('node_url') remme = Remme(network_config={ 'node_address': str(node_url) + ':8080', }) - result, errors = Batch(service=remme).get_list( - ids=batch_ids, - start=start, - limit=limit, - head=head, - reverse=reverse, - ) + if ids_only: + result, errors = Batch(service=remme).get_list_ids( + ids=batch_ids, + start=start, + limit=limit, + head=head, + reverse=reverse, + ) + else: + result, errors = Batch(service=remme).get_list( + ids=batch_ids, + start=start, + limit=limit, + head=head, + reverse=reverse, + ) if errors is not None: print_errors(errors=errors) diff --git a/cli/batch/forms.py b/cli/batch/forms.py index af8a9f9..eead417 100644 --- a/cli/batch/forms.py +++ b/cli/batch/forms.py @@ -48,4 +48,5 @@ class GetBatchesListForm(Schema): validate.Range(min=1, error='Limit must be greater than 0.'), ], ) + ids_only = fields.Boolean(required=False) node_url = NodeUrlField(required=False) diff --git a/cli/batch/help.py b/cli/batch/help.py index 07ad55b..bcb7433 100644 --- a/cli/batch/help.py +++ b/cli/batch/help.py @@ -8,3 +8,4 @@ BATCH_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.' BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch status by.' BATCH_ID_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch by.' +BATCH_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of batches\' identifiers.' diff --git a/cli/batch/interfaces.py b/cli/batch/interfaces.py index fc5f99b..bc591ca 100644 --- a/cli/batch/interfaces.py +++ b/cli/batch/interfaces.py @@ -41,3 +41,19 @@ def get_list(self, ids, start, limit, head, reverse): reverse (bool, optional): parameter to reverse result. """ pass + + def get_list_ids(self, ids, start, limit, head, reverse): + """ + Get a list of batches' identifiers. + + A list of batch identifiers could be filtered by batch identifiers, start identifier, limit, head identifier, + reverse. + + Arguments: + ids (list, optional): identifiers to get a list of batches by. + start (string, optional): batch identifier to get a list of batches starting from. + limit (int, optional): maximum amount of batches to return. + head (string, optional): block identifier to get a list of batches from. + reverse (bool, optional): parameter to reverse result. + """ + pass diff --git a/cli/batch/service.py b/cli/batch/service.py index acb58b7..9541607 100644 --- a/cli/batch/service.py +++ b/cli/batch/service.py @@ -93,3 +93,27 @@ def get_list(self, ids, start, limit, head, reverse): return None, str(error) return batches.get('data'), None + + def get_list_ids(self, ids, start, limit, head, reverse): + """ + Get a list of batch identifiers. + + Arguments: + ids (list, optional): identifiers to get a list of batches by. + start (string, optional): batch identifier to get a list of batches starting from. + limit (int, optional): maximum amount of batches to return. + head (string, optional): block identifier to get a list of batches from. + reverse (bool, optional): parameter to reverse result. + """ + batches, errors = self.get_list(ids=ids, start=start, head=head, limit=limit, reverse=reverse) + + if errors is not None: + return None, errors + + batch_identifiers = [] + + for batch in batches: + batch_identifier = batch.get('header_signature') + batch_identifiers.append(batch_identifier) + + return batch_identifiers, None diff --git a/tests/batch/test_get_list_batches.py b/tests/batch/test_get_list_batches.py index 4e79917..20cc46e 100644 --- a/tests/batch/test_get_list_batches.py +++ b/tests/batch/test_get_list_batches.py @@ -9,6 +9,7 @@ from cli.constants import ( BLOCK_IDENTIFIER_REGEXP, + HEADER_SIGNATURE_REGEXP, DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, FAILED_EXIT_FROM_COMMAND_CODE, PASSED_EXIT_FROM_COMMAND_CODE, @@ -86,6 +87,28 @@ def test_get_list_batches_with_ids(): assert block_identifier in COMMITTED_BATCH_IDENTIFIERS +def test_get_batches_identifiers(): + """ + Case: get a list of batches' identifiers. + Expect: a list of batches' identifiers is returned. + """ + runner = CliRunner() + result = runner.invoke(cli, [ + 'batch', + 'get-list', + '--ids-only', + '--node-url', + DEV_BRANCH_NODE_IP_ADDRESS_FOR_TESTING, + ]) + + batches = json.loads(result.output).get('result') + + assert PASSED_EXIT_FROM_COMMAND_CODE == result.exit_code + + for batch_identifier in batches: + assert re.match(pattern=HEADER_SIGNATURE_REGEXP, string=batch_identifier) is not None + + def test_get_list_batches_with_invalid_ids(): """ Case: get a list of batches by invalid identifiers.