Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Remmeauth/remme-core-cli into ge…
Browse files Browse the repository at this point in the history
…t-swap-public-key
  • Loading branch information
anastasiia-bilova committed Apr 25, 2019
2 parents 078a3d7 + e036a9c commit 04d1ede
Show file tree
Hide file tree
Showing 44 changed files with 1,632 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .github/delete-merged-branch-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude:
- develop
- master
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ script:
- pypi-version check
- cat requirements.txt requirements-tests.txt requirements-dev.txt | safety check --stdin
- radon cc cli -nb --total-average
- isort -rc cli --diff && isort -rc tests --diff
- ./scripts/isort-diff.sh
- flake8 cli && flake8 tests
- coverage run -m pytest -vv tests

Expand Down
112 changes: 96 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
* [Requirements](#getting-started-requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Nodes](#nodes)
* [Configuration file](#configuration-file)
* [Service](#service)
* [Account](#account)
* [Node](#node)
* [Public key](#public-key)
* [Development](#development)
* [Requirements](#development-requirements)
* [Docker](#docker)
Expand All @@ -31,14 +34,22 @@

### Installation

Install the package from the [PypI](https://pypi.org/project/remme-core-cli) through [pip](https://github.com/pypa/pip):
Install the package from the [PyPi](https://pypi.org/project/remme-core-cli) through [pip](https://github.com/pypa/pip):

```bash
$ 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`,
- `node-1-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:
Expand All @@ -61,7 +72,7 @@ node-url: node-genesis-testnet.remme.io
Try it out by downloading the example of the configuration file to the home directory.

```bash
$ curl -L https://git.io/fjYZS > ~/.remme-core-cli.yml
$ curl -L https://git.io/fj3Mi > ~/.remme-core-cli.yml
```

### Service
Expand Down Expand Up @@ -92,16 +103,85 @@ Options:

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. |
| node-url | String | No | Apply the command to the specified node by its URL. |
| Arguments | Type | Required | Description |
| :-------: | :----: | :-------: | ------------------------------------ |
| address | String | Yes | Account address to get a balance by. |
| node-url | String | No | Node URL to apply a command to. |

```bash
$ remme account get-balance \
--address=1120076ecf036e857f42129b58303bcf1e03723764a1702cbe98529802aad8514ee3cf \
--node-url=node-genesis-testnet.remme.io
368440.0
{
"result": {
"balance": 368440.0
}
}
```

Transfer tokens to address — ``remme account transfer-tokens``:

| Arguments | Type | Required | Description |
| :---------: | :-----: | :-------: | ---------------------------------------------- |
| private-key | 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=1067b42e24b4c533706f7c6e62278773c8ec7bf9e78bf570e9feb58ba8274acc \
--address-to=112007d71fa7e120c60fb392a64fd69de891a60c667d9ea9e5d9d9d617263be6c20202 \
--amount=1000 \
--node-url=node-genesis-testnet.remme.io
{
"result": {
"batch_identifier": "aac64d7b10be4b93b8c345b5eca1dc870c6b3905485e48a0ca5f58928a88a42b7a404abb4f1027e973314cca95379b1ef375358ad1661d0964c1ded4c212810f"
}
}
```

### Node

Get node configurations — ``remme node get-configs``:

| Arguments | Type | Required | Description |
| :-------: | :----: | :-------: | ------------------------------- |
| node-url | String | No | Node URL to apply a command to. |

```bash
$ remme node get-configs --node-url=node-genesis-testnet.remme.io
{
"result": {
"configurations": {
"node_address": "1168296ecf036e857f42129b58303bcf1e03723764a1702cbe98529802aad8514ee3cf",
"node_public_key": "03738df3f4ac3621ba8e89413d3ff4ad036c3a0a4dbb164b695885aab6aab614ad"
}
}
}
```

### Public key

Get a list of the addresses of the public keys by account address — ``remme public-key get-list``:

| Arguments | Type | Required | Description |
| :-------: | :----: | :------: | --------------------------------------------------------------------- |
| address | String | Yes | Account address to get a list of the addresses of the public keys by. |
| node-url | String | No | Node URL to apply a command to. |

```bash
$ remme public-key get-list \
--address=1120076ecf036e857f42129b58303bcf1e03723764a1702cbe98529802aad8514ee3cf \
--node-url=node-genesis-testnet.remme.io
{
"result": {
"public_key_addresses": [
"a23be10b3aad1b4a98f338c71d6dcdb2aa2f296c7e31fb400615e335dc10dd1d4f62bf",
"a23be14b362514d624c1985277005327f6fc40413fb090eee6fccb673a32c9809060ff"
]
}
}
```

### Atomic Swap
Expand Down Expand Up @@ -141,7 +221,7 @@ Run the ``Docker container`` with the project source code in the background mode

```bash
$ docker build -t remme-core-cli . -f Dockerfile.development
$ docker run -d -v $PWD:/remme-core-cli --name remme-core-cli remme-core-cli
$ docker run -d --network host -v $PWD:/remme-core-cli --name remme-core-cli remme-core-cli
```

Enter the container bash:
Expand Down Expand Up @@ -200,7 +280,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:

Expand All @@ -211,10 +295,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 written the description of the pull request and have added at least 2 reviewers](https://github.com/camo/55c309334a8b61a4848a6ef25f9b0fb3751ae5e9/68747470733a2f2f686162726173746f726167652e6f72672f776562742f74312f70792f63752f7431707963753162786a736c796f6a6c707935306d7862357969652e706e67).
3. [Continuous integration has been passed](https://habrastorage.org/webt/oz/fl/-n/ozfl-nl-jynrh7ofz8yuz9_gapy.png).
92 changes: 74 additions & 18 deletions cli/account/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@
Provide implementation of the command line interface's account commands.
"""
import sys
import re

import asyncio
import click
from remme import Remme

from cli.account.help import GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE
from cli.account.forms import (
GetAccountBalanceForm,
TransferTokensForm,
)
from cli.account.help import (
ADDRESS_ARGUMENT_HELP_MESSAGE,
ADDRESS_TO_ARGUMENT_HELP_MESSAGE,
AMOUNT_ARGUMENT_HELP_MESSAGE,
PRIVATE_KEY_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,
)

loop = asyncio.get_event_loop()
from cli.utils import (
default_node_url,
print_errors,
print_result,
)


@click.group('account', chain=True)
Expand All @@ -27,25 +36,72 @@ def account_commands():
pass


@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('--address', type=str, required=True, help=ADDRESS_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 node_url is None:
node_url = 'localhost'
if errors:
print_errors(errors=errors)
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

remme = Remme(private_key_hex=None, network_config={
address = arguments.get('address')
node_url = arguments.get('node_url')

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

account = Account(service=remme)
balance = loop.run_until_complete(account.get_balance(address=address))
result, errors = Account(service=remme).get_balance(address=address)

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

print_result(result=result)


@click.option('--private-key', type=str, required=True, help=PRIVATE_KEY_ARGUMENT_HELP_MESSAGE)
@click.option('--address-to', type=str, required=True, help=ADDRESS_TO_ARGUMENT_HELP_MESSAGE)
@click.option('--amount', type=int, required=True, help=AMOUNT_ARGUMENT_HELP_MESSAGE)
@click.option('--node-url', type=str, required=False, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url())
@account_commands.command('transfer-tokens')
def transfer_tokens(private_key, address_to, amount, node_url):
"""
Transfer tokens to address.
"""
arguments, errors = TransferTokensForm().load({
'private_key': private_key,
'address_to': address_to,
'amount': amount,
'node_url': node_url,
})

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

private_key = arguments.get('private_key')
address_to = arguments.get('address_to')
amount = arguments.get('amount')
node_url = arguments.get('node_url')

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

result, errors = Account(service=remme).transfer_tokens(address_to=address_to, amount=amount)

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

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

from cli.generic.forms.fields import (
AccountAddressField,
NodeURLField,
PrivateKeyField,
)


class GetAccountBalanceForm(Schema):
"""
Get balance of the account form.
"""

address = AccountAddressField(required=True)
node_url = NodeURLField(allow_none=True, required=False)


class TransferTokensForm(Schema):
"""
Transfer tokens to address form.
"""

private_key = PrivateKeyField(required=True)
address_to = AccountAddressField(required=True)
amount = fields.Integer(
strict=True,
required=True,
validate=[
validate.Range(min=1, error='Amount must be greater than 0.'),
],
)
node_url = NodeURLField(allow_none=True, required=False)
6 changes: 5 additions & 1 deletion cli/account/help.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
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.'
ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a balance by.'
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_ARGUMENT_HELP_MESSAGE = 'Account\'s private key to transfer tokens from.'
8 changes: 7 additions & 1 deletion cli/account/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ class AccountInterface:
Implements account interface.
"""

async def get_balance(self, address):
def get_balance(self, address):
"""
Get balance of the account by its address.
"""
pass

def transfer_tokens(self, address_to, amount):
"""
Transfer tokens to address.
"""
pass
Loading

0 comments on commit 04d1ede

Please sign in to comment.