-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Remmeauth/remme-core-cli …
…into f-list-batches
- Loading branch information
Showing
34 changed files
with
2,085 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.