Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Remmeauth/remme-core-cli
Browse files Browse the repository at this point in the history
…into f-list-batches
  • Loading branch information
Artem Saprykin committed May 10, 2019
2 parents 8ba1c05 + fe48493 commit daa5b65
Show file tree
Hide file tree
Showing 34 changed files with 2,085 additions and 5 deletions.
295 changes: 293 additions & 2 deletions README.md

Large diffs are not rendered by default.

72 changes: 71 additions & 1 deletion cli/batch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import click
from remme import Remme

from cli.batch.forms import GetBatchesListForm
from cli.batch.forms import (
GetBatchesListForm,
GetBatchForm,
GetBatchStatusForm,
)
from cli.batch.help import (
BATCH_HEAD_ARGUMENT_HELP_MESSAGE,
BATCH_ID_ARGUMENT_HELP_MESSAGE,
BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE,
BATCH_LIMIT_ARGUMENT_HELP_MESSAGE,
BATCH_REVERSE_ARGUMENT_HELP_MESSAGE,
BATCH_START_ARGUMENT_HELP_MESSAGE,
BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE,
)
from cli.batch.service import Batch
from cli.constants import (
Expand All @@ -34,6 +40,70 @@ def batch_commands():
pass


@click.option('--id', required=True, type=str, help=BATCH_ID_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')
def get_batch(id, node_url):
"""
Get a batch by its identifier.
"""
arguments, errors = GetBatchForm().load({
'id': id,
'node_url': node_url,
})

if errors:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

batch_id = arguments.get('id')
node_url = arguments.get('node_url')

remme = Remme(network_config={
'node_address': str(node_url) + ':8080',
})

batch, errors = Batch(service=remme).get(id=batch_id)

if errors is not None:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

print_result(result=batch)


@click.option('--id', required=True, type=str, help=BATCH_STATUS_IDENTIFIER_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-status')
def get_batch_status(id, node_url):
"""
Get a batch status by its identifier.
"""
arguments, errors = GetBatchStatusForm().load({
'id': id,
'node_url': node_url,
})

if errors:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

batch_id = arguments.get('id')
node_url = arguments.get('node_url')

remme = Remme(network_config={
'node_address': str(node_url) + ':8080',
})

result, errors = Batch(service=remme).get_status(id=batch_id)

if errors is not None:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

print_result(result=result)


@click.option('--ids', required=False, type=str, help=BATCH_IDENTIFIERS_ARGUMENT_HELP_MESSAGE)
@click.option('--start', required=False, type=str, help=BATCH_START_ARGUMENT_HELP_MESSAGE)
@click.option('--limit', required=False, type=int, help=BATCH_LIMIT_ARGUMENT_HELP_MESSAGE)
Expand Down
18 changes: 18 additions & 0 deletions cli/batch/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
)


class GetBatchForm(Schema):
"""
Get a batch by its identifier form.
"""

id = BatchIdentifierField(allow_none=False, required=True)
node_url = NodeUrlField(required=False)


class GetBatchStatusForm(Schema):
"""
Get a batch status by its identifier form.
"""

id = BatchIdentifierField(required=True)
node_url = NodeUrlField(required=False)


class GetBatchesListForm(Schema):
"""
Get a list of batches form.
Expand Down
2 changes: 2 additions & 0 deletions cli/batch/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
BATCH_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of batches to return.'
BATCH_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of batches from.'
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.'
18 changes: 18 additions & 0 deletions cli/batch/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ class BatchInterface:
Implements batch interface.
"""

def get(self, id):
"""
Get a batch by its identifier.
Arguments:
id (string, required): batch identifier.
"""
pass

def get_status(self, id):
"""
Get a batch status by its identifier.
Arguments:
id (string, required): batch identifier.
"""
pass

def get_list(self, ids, start, limit, head, reverse):
"""
Get a list of batches.
Expand Down
38 changes: 38 additions & 0 deletions cli/batch/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ def __init__(self, service):
"""
self.service = service

def get(self, id):
"""
Get a batch by its identifier.
Arguments:
id (string, required): batch identifier.
"""
try:
batch = loop.run_until_complete(
self.service.blockchain_info.get_batch_by_id(batch_id=id),
)

except RpcGenericServerDefinedError as error:
return None, str(error.message)

except Exception as error:
return None, str(error)

return batch.get('data'), None

def get_status(self, id):
"""
Get a batch status by its identifier.
Arguments:
id (string, required): batch identifier.
"""
try:
batch_status = loop.run_until_complete(self.service.blockchain_info.get_batch_status(batch_id=id))

except RpcGenericServerDefinedError as error:
return None, str(error.message)

except Exception as error:
return None, str(error)

return batch_status, None

def get_list(self, ids, start, limit, head, reverse):
"""
Get a list of batches.
Expand Down
Empty file added cli/block/__init__.py
Empty file.
60 changes: 60 additions & 0 deletions cli/block/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Provide implementation of the command line interface's block commands.
"""
import sys

import click
from remme import Remme

from cli.block.forms import GetBlockByIdentifierForm
from cli.block.help import BLOCK_IDENTIFIER_ARGUMENT_HELP_MESSAGE
from cli.block.service import Block
from cli.constants import (
FAILED_EXIT_FROM_COMMAND_CODE,
NODE_URL_ARGUMENT_HELP_MESSAGE,
)
from cli.utils import (
default_node_url,
print_errors,
print_result,
)


@click.group('block', chain=True)
def block_commands():
"""
Provide commands for working with block.
"""
pass


@click.option('--id', type=str, required=True, help=BLOCK_IDENTIFIER_ARGUMENT_HELP_MESSAGE)
@click.option('--node-url', type=str, required=False, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url())
@block_commands.command('get')
def get_block(id, node_url):
"""
Get a block by its identifier.
"""
arguments, errors = GetBlockByIdentifierForm().load({
'id': id,
'node_url': node_url,
})

if errors:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

identifier = arguments.get('id')
node_url = arguments.get('node_url')

remme = Remme(network_config={
'node_address': str(node_url) + ':8080',
})

result, errors = Block(service=remme).get(identifier=identifier)

if errors is not None:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

print_result(result=result)
18 changes: 18 additions & 0 deletions cli/block/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Provide forms for command line interface's block commands.
"""
from marshmallow import Schema

from cli.generic.forms.fields import (
BlockIdentifierField,
NodeUrlField,
)


class GetBlockByIdentifierForm(Schema):
"""
Get a block by its identifier form.
"""

id = BlockIdentifierField(required=True)
node_url = NodeUrlField(required=True)
4 changes: 4 additions & 0 deletions cli/block/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Provide help messages for command line interface's block commands.
"""
BLOCK_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier of the block to fetch information about by.'
15 changes: 15 additions & 0 deletions cli/block/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Provide implementation of the block interfaces.
"""


class BlockInterface:
"""
Implements block interface.
"""

def get(self, identifier):
"""
Get a block by its identifier.
"""
pass
44 changes: 44 additions & 0 deletions cli/block/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Provide implementation of the block.
"""
import asyncio

from accessify import implements
from aiohttp_json_rpc import RpcGenericServerDefinedError

from cli.block.interfaces import BlockInterface

loop = asyncio.get_event_loop()


@implements(BlockInterface)
class Block:
"""
Implements block.
"""

def __init__(self, service):
"""
Constructor.
Arguments:
service: object to interact with Remme core API.
"""
self.service = service

def get(self, identifier):
"""
Get a block by its identifier.
"""
try:
block = loop.run_until_complete(
self.service.blockchain_info.get_block_by_id(block_id=identifier),
)

except RpcGenericServerDefinedError as error:
return None, str(error.message)

except Exception as error:
return None, str(error)

return block.get('data'), None
2 changes: 2 additions & 0 deletions cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from remme.models.utils.family_name import RemmeFamilyName

ADDRESS_REGEXP = r'^[0-9a-f]{70}$'
BLOCK_IDENTIFIER_REGEXP = r'^[0-9a-f]{128}$'
BATCH_ID_REGEXP = r'^[0-9a-f]{128}$'
PUBLIC_KEY_REGEXP = r'^[0-9a-f]{66}$'
PRIVATE_KEY_REGEXP = r'^[a-f0-9]{64}$'
Expand Down Expand Up @@ -31,6 +32,7 @@
NODE_IP_ADDRESS_FOR_TESTING = '159.89.104.9'
LATEST_RELEASE_NODE_IP_ADDRESS_FOR_TESTING = '165.22.75.163'
RELEASE_0_9_0_ALPHA_NODE_ADDRESS = '165.227.169.119'
NODE_1_IN_TESTNET_ADDRESS = 'node-1-testnet.remme.io'
NODE_27_IN_TESTNET_ADDRESS = 'node-27-testnet.remme.io'

PRIVATE_KEY_FOR_TESTING = 'b03e31d2f310305eab249133b53b5fb3270090fc1692c9b022b81c6b9bb6029b'
Expand Down
6 changes: 6 additions & 0 deletions cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from cli.account.cli import account_commands
from cli.atomic_swap.cli import atomic_swap_commands
from cli.batch.cli import batch_commands
from cli.block.cli import block_commands
from cli.node.cli import node_commands
from cli.node_account.cli import node_account_commands
from cli.public_key.cli import public_key_commands
from cli.receipt.cli import receipt_commands
from cli.state.cli import state_command
from cli.transaction.cli import transaction_command

Expand All @@ -25,7 +28,10 @@ def cli():
cli.add_command(account_commands)
cli.add_command(atomic_swap_commands)
cli.add_command(batch_commands)
cli.add_command(block_commands)
cli.add_command(node_commands)
cli.add_command(node_account_commands)
cli.add_command(public_key_commands)
cli.add_command(receipt_commands)
cli.add_command(state_command)
cli.add_command(transaction_command)
Loading

0 comments on commit daa5b65

Please sign in to comment.