-
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
Implement getting node configurations #25
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ed2d50
Implement transfer tokens to address
dmytrostriletskyi ee6bfa6
Implement getting node configurations
dmytrostriletskyi c348666
Merge branch 'develop' of github.com:Remmeauth/remme-core-cli into tr…
dmytrostriletskyi c26799a
Merge branch 'transfer-tokens' into get-node-configs
dmytrostriletskyi 36cd046
Fix tests and documentation
dmytrostriletskyi d2b225a
Merge branch 'develop' of github.com:Remmeauth/remme-core-cli into tr…
dmytrostriletskyi 9b77b81
Merge branch 'transfer-tokens' of github.com:Remmeauth/remme-core-cli…
dmytrostriletskyi a532eac
Create node configurations fixture
dmytrostriletskyi 0710491
Merge branch 'develop' of github.com:Remmeauth/remme-core-cli into ge…
dmytrostriletskyi a2848a0
Add catching bare exception
dmytrostriletskyi d03ebdd
Merge branch 'develop' of github.com:Remmeauth/remme-core-cli into ge…
dmytrostriletskyi d13366b
Fix documentation typos
dmytrostriletskyi 0ed94c7
Merge branch 'develop' into get-node-configs
dmytrostriletskyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||
* [Configuration file](#configuration-file) | ||||||
* [Service](#service) | ||||||
* [Account](#account) | ||||||
* [Node](#node) | ||||||
* [Development](#development) | ||||||
* [Requirements](#development-requirements) | ||||||
* [Docker](#docker) | ||||||
|
@@ -45,7 +46,8 @@ $ pip3 install remme-core-cli | |||||
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`. | ||||||
- `node-6-testnet.remme.io`, | ||||||
- `node-1-testnet.remme.io`. | ||||||
|
||||||
### Configuration file | ||||||
|
||||||
|
@@ -112,6 +114,42 @@ $ remme account get-balance \ | |||||
368440.0 | ||||||
``` | ||||||
|
||||||
Transfer tokens to address — ``remme account transfer-tokens``: | ||||||
|
||||||
| Arguments | Type | Required | Description | | ||||||
| :--------------: | :-----: | :-------: | ---------------------------------------------- | | ||||||
| private-key-from | String | Yes | Account's private key to transfer tokens from. | | ||||||
| address-to | String | Yes | Account address to transfer tokens to. | | ||||||
| amount | Integer | Yes | Amount to transfer. | | ||||||
| node-url | String | No | Node URL to apply a command to. | | ||||||
|
||||||
```bash | ||||||
$ remme account transfer-tokens \ | ||||||
--private-key-from=1067b42e24b4c533706f7c6e62278773c8ec7bf9e78bf570e9feb58ba8274acc \ | ||||||
--address-to=112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202 \ | ||||||
--amount=1000 \ | ||||||
--node-url=node-genesis-testnet.remme.io | ||||||
{ | ||||||
"batch_id": "37809770b004dcbc7dae116fd9f17428255ddddee3304c9b3d14609d2792e78f08f5308af03fd4aa18ff1d868f043b12dd7b0a792e141f000a2505acd4b7a956" | ||||||
} | ||||||
``` | ||||||
|
||||||
### Node | ||||||
|
||||||
Get node configurations — ``remme node get-configurations``: | ||||||
|
||||||
| Arguments | Type | Required | Description | | ||||||
| :-------: | :----: | :-------: | ------------------------------------ | | ||||||
| node-url | String | No | Node URL to apply a command to. | | ||||||
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.
Suggested change
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. @anastasiia-bilova, done. |
||||||
|
||||||
```bash | ||||||
$ remme node get-configurations --node-url=node-genesis-testnet.remme.io | ||||||
{ | ||||||
"node_address": "1168296ecf036e857f42129b58303bcf1e03723764a1702cbe98529802aad8514ee3cf", | ||||||
"node_public_key": "03738df3f4ac3621ba8e89413d3ff4ad036c3a0a4dbb164b695885aab6aab614ad" | ||||||
} | ||||||
``` | ||||||
|
||||||
## Development | ||||||
|
||||||
<h3 id="development-requirements">Requirements</h4> | ||||||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
""" | ||
Provide help messages for command line interface's account commands. | ||
""" | ||
ADDRESS_TO_ARGUMENT_HELP_MESSAGE = 'Account address to transfer tokens to.' | ||
AMOUNT_ARGUMENT_HELP_MESSAGE = 'Amount to transfer.' | ||
GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a balance by.' | ||
PRIVATE_KEY_FROM_ARGUMENT_HELP_MESSAGE = 'Account\'s private key to transfer tokens from.' |
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.
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,31 @@ | ||
""" | ||
Provide generic form fields. | ||
""" | ||
import re | ||
|
||
from marshmallow import ( | ||
ValidationError, | ||
fields, | ||
) | ||
|
||
from cli.constants import PRIVATE_KEY_REGEXP | ||
|
||
|
||
class PrivateKeyField(fields.Field): | ||
""" | ||
Implements validation of the private key. | ||
|
||
References: | ||
- https://marshmallow.readthedocs.io/en/3.0/custom_fields.html | ||
""" | ||
|
||
def _deserialize(self, value, attr, data, **kwargs): | ||
""" | ||
Validate data (private key) that was passed to field. | ||
""" | ||
private_key = value | ||
|
||
if re.match(pattern=PRIVATE_KEY_REGEXP, string=private_key) is None: | ||
raise ValidationError(f'The following private key `{private_key}` is invalid.') | ||
|
||
return value |
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,59 @@ | ||
""" | ||
Provide implementation of the command line interface's node commands. | ||
""" | ||
import asyncio | ||
import sys | ||
|
||
import click | ||
from remme import Remme | ||
|
||
from cli.constants import ( | ||
FAILED_EXIT_FROM_COMMAND_CODE, | ||
NODE_URL_ARGUMENT_HELP_MESSAGE, | ||
) | ||
from cli.node.forms import GetNodeConfigurationsForm | ||
from cli.node.service import Node | ||
from cli.utils import ( | ||
default_node_url, | ||
print_errors, | ||
print_result, | ||
) | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
|
||
@click.group('node', chain=True) | ||
def node_commands(): | ||
""" | ||
Provide commands for working with node. | ||
""" | ||
pass | ||
|
||
|
||
@click.option('--node-url', type=str, required=False, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) | ||
@node_commands.command('get-configurations') | ||
def transfer_tokens(node_url): | ||
""" | ||
Get node configurations. | ||
""" | ||
arguments, errors = GetNodeConfigurationsForm().load({ | ||
'node_url': node_url, | ||
}) | ||
|
||
if errors: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
node_url = arguments.get('node_url') | ||
|
||
remme = Remme(network_config={ | ||
'node_address': str(node_url) + ':8080', | ||
}) | ||
|
||
result, errors = Node(service=remme).get_configurations() | ||
|
||
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,37 @@ | ||
""" | ||
Provide forms for command line interface's node commands. | ||
""" | ||
import re | ||
|
||
from marshmallow import ( | ||
Schema, | ||
ValidationError, | ||
fields, | ||
validates, | ||
) | ||
|
||
from cli.constants import DOMAIN_NAME_REGEXP | ||
|
||
|
||
class GetNodeConfigurationsForm(Schema): | ||
""" | ||
Get node configurations. | ||
""" | ||
|
||
node_url = fields.String(allow_none=True, required=False) | ||
|
||
@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.') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
@anastasiia-bilova, done.