-
Notifications
You must be signed in to change notification settings - Fork 0
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
Solve weekly technical debt #13
Changes from 11 commits
10eebf1
c2c82ee
1cc8600
b7b0864
502013a
e79cd3b
2be33fb
52c8485
5b1c05b
21a83bb
52616d6
5fbb62d
4e63048
accbc1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exclude: | ||
- develop | ||
- master |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
* [Requirements](#getting-started-requirements) | ||
* [Installation](#installation) | ||
* [Usage](#usage) | ||
* [Nodes](#nodes) | ||
* [Configuration file](#configuration-file) | ||
* [Service](#service) | ||
* [Account](#account) | ||
|
@@ -39,6 +40,13 @@ $ pip3 install remme-core-cli | |
|
||
## Usage | ||
|
||
### Nodes | ||
|
||
You can use the following list of the addresses of the nodes to execute commands to: | ||
|
||
- `node-genesis-testnet.remme.io`, | ||
- `node-6-testnet.remme.io`. | ||
|
||
### Configuration file | ||
|
||
Using the command line interface, you will have an option to declare the `node URL` to send commands to as illustrated below: | ||
|
@@ -94,7 +102,7 @@ Get balance of the account by its address — ``remme account get-balance``: | |
|
||
| Arguments | Type | Required | Description | | ||
| :-------: | :----: | :-------: | --------------------------------------------------- | | ||
| address | String | Yes | Get balance of the account by its address. | | ||
| address | String | Yes | Account address to get a balance by. | | ||
| node-url | String | No | Apply the command to the specified node by its URL. | | ||
|
||
```bash | ||
|
@@ -187,7 +195,11 @@ $ git clone https://github.com/Remmeauth/remme-core-cli && cd remme-core-cli | |
$ pip3 install -r requirements.txt -r requirements-dev.txt -r requirements-tests.txt | ||
``` | ||
|
||
When you make changes, ensure your code pass [the checkers](https://github.com/Remmeauth/remme-core-cli/blob/develop/.travis.yml#L16) and is covered by tests using [pytest](https://docs.pytest.org/en/latest). | ||
When you make changes, ensure your code: | ||
|
||
* pass [the checkers](https://github.com/Remmeauth/remme-core-cli/blob/develop/.travis.yml#L16), | ||
* is covered by tests using [pytest](https://docs.pytest.org/en/latest), | ||
* follow team [code style](https://github.com/dmytrostriletskyi/nimble-python-code-style-guide). | ||
|
||
If you are new for the contribution, please read: | ||
|
||
|
@@ -198,10 +210,6 @@ If you are new for the contribution, please read: | |
### Request pull request's review | ||
|
||
If you want to your pull request to be review, ensure you: | ||
- `have wrote the description of the pull request`, | ||
- `have added at least 2 reviewers`, | ||
- `continuous integration has been passed`. | ||
|
||
![Example of the description and reviewers](https://habrastorage.org/webt/t1/py/cu/t1pycu1bxjslyojlpy50mxb5yie.png) | ||
|
||
![Example of the CI which passed](https://habrastorage.org/webt/oz/fl/-n/ozfl-nl-jynrh7ofz8yuz9_gapy.png) | ||
1. [Branch isn't out-of-date with the base branch](https://habrastorage.org/webt/ux/gi/wm/uxgiwmnft08fubvjfd6d-8pw2wq.png). | ||
2. [Have wrote the description of the pull request and have added at least 2 reviewers](https://github.com/camo/55c309334a8b61a4848a6ef25f9b0fb3751ae5e9/68747470733a2f2f686162726173746f726167652e6f72672f776562742f74312f70792f63752f7431707963753162786a736c796f6a6c707935306d7862357969652e706e67). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have wrote > Have written. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Art17, done. |
||
3. [Continuous integration has been passed](https://habrastorage.org/webt/oz/fl/-n/ozfl-nl-jynrh7ofz8yuz9_gapy.png). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
""" | ||
Provide implementation of the command line interface's account commands. | ||
""" | ||
import asyncio | ||
import sys | ||
import re | ||
|
||
import asyncio | ||
import click | ||
from remme import Remme | ||
|
||
from cli.account.forms import GetAccountBalanceForm | ||
from cli.account.help import GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE | ||
from cli.account.service import Account | ||
from cli.constants import ( | ||
ADDRESS_REGEXP, | ||
FAILED_EXIT_FROM_COMMAND, | ||
FAILED_EXIT_FROM_COMMAND_CODE, | ||
NODE_URL_ARGUMENT_HELP_MESSAGE, | ||
) | ||
from cli.utils import ( | ||
default_node_url, | ||
dict_to_pretty_json, | ||
) | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
|
@@ -28,24 +31,29 @@ def account_commands(): | |
|
||
|
||
@click.option('--address', type=str, required=True, help=GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--node-url', type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--node-url', type=str, required=False, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) | ||
@account_commands.command('get-balance') | ||
def get_balance(address, node_url): | ||
""" | ||
Get balance of the account by its address. | ||
""" | ||
if re.match(pattern=ADDRESS_REGEXP, string=address) is None: | ||
click.echo('The following address `{address}` is not valid.'.format(address=address)) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND) | ||
arguments, errors = GetAccountBalanceForm().load({ | ||
'address': address, | ||
'node_url': node_url, | ||
}) | ||
|
||
if errors: | ||
click.echo(dict_to_pretty_json(errors)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stylize please error output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Alladin9393, your approach has:
We could remove additional function, and just do the following: pprint(dict_to_pretty_json(errors)) And the result would be the same but without library's dependency using already created custom code in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmytrostriletskyi, ok, I think its better |
||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
if node_url is None: | ||
node_url = 'localhost' | ||
address = arguments.get('address') | ||
node_url = arguments.get('node_url') | ||
|
||
remme = Remme(private_key_hex=None, network_config={ | ||
remme = Remme(network_config={ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a function that returns Remme object, because its code reuses all functions in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Alladin9393, there is no:
anymore. The initialization of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Alladin9393, maybe we could write the code in the following way:
To make it smaller. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmytrostriletskyi, Ok, let it be as it is now. |
||
'node_address': str(node_url) + ':8080', | ||
}) | ||
|
||
account = Account(service=remme) | ||
balance = loop.run_until_complete(account.get_balance(address=address)) | ||
account_service = Account(service=remme) | ||
balance = loop.run_until_complete(account_service.get_balance(address=address)) | ||
|
||
click.echo(balance) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Provide forms for command line interface's account commands. | ||
""" | ||
import re | ||
|
||
from marshmallow import ( | ||
Schema, | ||
ValidationError, | ||
fields, | ||
validates, | ||
) | ||
|
||
from cli.constants import ( | ||
ADDRESS_REGEXP, | ||
DOMAIN_NAME_REGEXP, | ||
) | ||
|
||
|
||
class GetAccountBalanceForm(Schema): | ||
""" | ||
Get balance of the account form. | ||
""" | ||
|
||
address = fields.String(required=True) | ||
node_url = fields.String(allow_none=True, required=False) | ||
|
||
@validates('address') | ||
def validate_address(self, address): | ||
""" | ||
Validate account address. | ||
""" | ||
if re.match(pattern=ADDRESS_REGEXP, string=address) is None: | ||
raise ValidationError(f'The following address `{address}` is invalid.') | ||
|
||
@validates('node_url') | ||
def validate_node_url(self, node_url): | ||
""" | ||
Validate node URL. | ||
|
||
If node URL is localhost, it means client didn't passed any URL, so nothing to validate. | ||
""" | ||
if node_url == 'localhost': | ||
return | ||
|
||
if 'http' in node_url or 'https' in node_url: | ||
raise ValidationError(f'Pass the following node URL `{node_url}` without protocol (http, https, etc.).') | ||
|
||
if re.match(pattern=DOMAIN_NAME_REGEXP, string=node_url) is None: | ||
raise ValidationError(f'The following node URL `{node_url}` is invalid.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
Provide help messages for command line interface's account commands. | ||
""" | ||
GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE = 'Get balance of the account by its address.' | ||
GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a balance by.' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
""" | ||
Provide constants for command line interface. | ||
""" | ||
ADDRESS_REGEXP = '[0-9a-f]{70}' | ||
ADDRESS_REGEXP = r'^[0-9a-f]{70}$' | ||
DOMAIN_NAME_REGEXP = r'(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]' | ||
|
||
FAILED_EXIT_FROM_COMMAND = -1 | ||
PASSED_EXIT_FROM_COMMAND_CODE = 0 | ||
FAILED_EXIT_FROM_COMMAND_CODE = -1 | ||
|
||
NODE_URL_ARGUMENT_HELP_MESSAGE = 'Apply the command to the specified node by its URL.' | ||
|
||
CLI_CONFIG_FILE_NAME = 'remme-core-cli' | ||
|
||
NODE_IP_ADDRESS_FOR_TESTING = '159.89.104.9' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ accessify==0.3.1 | |
asyncio==3.4.3 | ||
click==7.0 | ||
remme==1.0.0 | ||
marshmallow==2.19.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# Check if isort show difference. | ||
|
||
ISORT_OUTPUT=$(isort -rc . --diff) | ||
IS_ISORT_DIFF=$(echo ${ISORT_OUTPUT} | grep '+') | ||
|
||
if [ -z "$IS_ISORT_DIFF" ] | ||
then | ||
exit 0 | ||
else | ||
echo "${ISORT_OUTPUT}" | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node URL to apply the command to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Art17, done.