Skip to content

Commit

Permalink
Release v0.4.0: node account info, list of blocks, batch status by id…
Browse files Browse the repository at this point in the history
…entifier commands (#55)
  • Loading branch information
dmytrostriletskyi authored May 20, 2019
1 parent a8a5079 commit 6eaa1fc
Show file tree
Hide file tree
Showing 79 changed files with 5,436 additions and 360 deletions.
578 changes: 545 additions & 33 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GetAccountBalanceForm(Schema):
"""

address = AccountAddressField(required=True)
node_url = NodeUrlField(required=False)
node_url = NodeUrlField(required=True)


class TransferTokensForm(Schema):
Expand All @@ -37,4 +37,4 @@ class TransferTokensForm(Schema):
validate.Range(min=1, error='Amount must be greater than 0.'),
],
)
node_url = NodeUrlField(required=False)
node_url = NodeUrlField(required=True)
2 changes: 1 addition & 1 deletion cli/atomic_swap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def atomic_swap_commands():
@atomic_swap_commands.command('get-public-key')
def get_public_key(node_url):
"""
Get public key of atomic swap.
Get the public key of atomic swap.
"""
arguments, errors = GetAtomicSwapPublicKeyForm().load({
'node_url': node_url,
Expand Down
6 changes: 3 additions & 3 deletions cli/atomic_swap/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class GetAtomicSwapInformationForm(Schema):
"""

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


class GetAtomicSwapPublicKeyForm(Schema):
"""
Get public key of the atomic swap form.
Get the public key of the atomic swap form.
"""

node_url = NodeUrlField(required=False)
node_url = NodeUrlField(required=True)
2 changes: 1 addition & 1 deletion cli/atomic_swap/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AtomicSwapInterface:

def get_public_key(self):
"""
Get public key of atomic swap.
Get the public key of atomic swap.
"""
pass

Expand Down
2 changes: 1 addition & 1 deletion cli/atomic_swap/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, service):

def get_public_key(self):
"""
Get public key of atomic swap.
Get the public key of atomic swap.
"""
try:
public_key = loop.run_until_complete(self.service.swap.get_public_key())
Expand Down
File renamed without changes.
159 changes: 159 additions & 0 deletions cli/batch/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
"""
Provide implementation of the command line interface's batch commands.
"""
import sys

import click
from remme import Remme

from cli.batch.forms import (
GetBatchesListForm,
GetBatchForm,
GetBatchStatusForm,
)
from cli.batch.help import (
BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE,
BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE,
BATCHES_HEAD_ARGUMENT_HELP_MESSAGE,
BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE,
BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE,
BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE,
BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE,
BATCHES_START_ARGUMENT_HELP_MESSAGE,
)
from cli.batch.service import Batch
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('batch', chain=True)
def batch_commands():
"""
Provide commands for working with batch.
"""
pass


@click.option('--id', required=True, type=str, help=BATCH_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')
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=BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE)
@click.option('--start', required=False, type=str, help=BATCHES_START_ARGUMENT_HELP_MESSAGE)
@click.option('--limit', required=False, type=int, help=BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE)
@click.option('--head', required=False, type=str, help=BATCHES_HEAD_ARGUMENT_HELP_MESSAGE)
@click.option('--reverse', required=False, is_flag=True, help=BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE)
@click.option('--ids-only', required=False, is_flag=True, help=BATCHES_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, ids_only, node_url):
"""
Get a list of batches.
"""
arguments, errors = GetBatchesListForm().load({
'ids': ids,
'start': start,
'limit': limit,
'head': head,
'reverse': reverse,
'ids_only': ids_only,
'node_url': node_url,
})

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

batch_ids = arguments.get('ids')
start = arguments.get('start')
limit = arguments.get('limit')
head = arguments.get('head')
reverse = arguments.get('reverse')
ids_only = arguments.get('ids_only')
node_url = arguments.get('node_url')

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

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)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

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

from cli.generic.forms.fields import (
BatchIdentifierField,
BatchIdentifiersListField,
NodeUrlField,
)


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

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


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

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


class GetBatchesListForm(Schema):
"""
Get a list of batches form.
"""

ids = BatchIdentifiersListField(allow_none=True, required=False)
start = BatchIdentifierField(allow_none=True, required=False)
head = BatchIdentifierField(allow_none=True, required=False)
limit = fields.Integer(
allow_none=True,
strict=True,
required=False,
validate=[
validate.Range(min=1, error='Limit must be greater than 0.'),
],
)
reverse = fields.Boolean(required=False)
ids_only = fields.Boolean(required=False)
node_url = NodeUrlField(required=True)
11 changes: 11 additions & 0 deletions cli/batch/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Provide help messages for command line interface's batch commands.
"""
BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch by.'
BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch status by.'
BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.'
BATCHES_START_ARGUMENT_HELP_MESSAGE = 'Batch identifier to get a list of batches starting from.'
BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of batches to return.'
BATCHES_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of batches to.'
BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.'
BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of batches\' identifiers.'
59 changes: 59 additions & 0 deletions cli/batch/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Provide implementation of the batch interfaces.
"""


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.
A list of batches 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

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
Loading

0 comments on commit 6eaa1fc

Please sign in to comment.