Skip to content

Commit

Permalink
Merge branch 'develop' into get-node-configs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrostriletskyi authored and anastasiia-bilova committed Apr 25, 2019
2 parents d13366b + ef7ecd5 commit 0ed94c7
Show file tree
Hide file tree
Showing 14 changed files with 400 additions and 9 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [Service](#service)
* [Account](#account)
* [Node](#node)
* [Public key](#public-key)
* [Development](#development)
* [Requirements](#development-requirements)
* [Docker](#docker)
Expand Down Expand Up @@ -160,6 +161,29 @@ $ remme node get-configs --node-url=node-genesis-testnet.remme.io
}
```

### 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"
]
}
}
```

## Development

<h3 id="development-requirements">Requirements</h4>
Expand Down
2 changes: 2 additions & 0 deletions cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@

NODE_IP_ADDRESS_FOR_TESTING = '159.89.104.9'
LATEST_RELEASE_NODE_IP_ADDRESS_FOR_TESTING = '165.22.75.163'
RELEASE_0_9_0_ALPHA_NODE_ADDRESS = '165.227.169.119'

PRIVATE_KEY_FOR_TESTING = 'b03e31d2f310305eab249133b53b5fb3270090fc1692c9b022b81c6b9bb6029b'
2 changes: 2 additions & 0 deletions cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cli.account.cli import account_commands
from cli.node.cli import node_commands
from cli.public_key.cli import public_key_commands


@click.group()
Expand All @@ -19,3 +20,4 @@ def cli():

cli.add_command(account_commands)
cli.add_command(node_commands)
cli.add_command(public_key_commands)
3 changes: 0 additions & 3 deletions cli/node/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Provide implementation of the command line interface's node commands.
"""
import asyncio
import sys

import click
Expand All @@ -19,8 +18,6 @@
print_result,
)

loop = asyncio.get_event_loop()


@click.group('node', chain=True)
def node_commands():
Expand Down
Empty file added cli/public_key/__init__.py
Empty file.
60 changes: 60 additions & 0 deletions cli/public_key/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Provide implementation of the command line interface's public key commands.
"""
import sys

import click
from remme import Remme

from cli.constants import (
FAILED_EXIT_FROM_COMMAND_CODE,
NODE_URL_ARGUMENT_HELP_MESSAGE,
)
from cli.public_key.forms import GetPublicKeysForm
from cli.public_key.help import ADDRESS_ARGUMENT_HELP_MESSAGE
from cli.public_key.service import PublicKey
from cli.utils import (
default_node_url,
print_errors,
print_result,
)


@click.group('public-key', chain=True)
def public_key_commands():
"""
Provide commands for working with public key.
"""
pass


@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())
@public_key_commands.command('get-list')
def get_public_keys(address, node_url):
"""
Get a list of the addresses of the public keys by account address.
"""
arguments, errors = GetPublicKeysForm().load({
'address': address,
'node_url': node_url,
})

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

address = arguments.get('address')
node_url = arguments.get('node_url')

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

result, errors = PublicKey(service=remme).get_list(address=address)

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

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

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


class GetPublicKeysForm(Schema):
"""
Get a list of the addresses of the public keys form.
"""

address = AccountAddressField(required=True)
node_url = NodeURLField(allow_none=True, required=False)
4 changes: 4 additions & 0 deletions cli/public_key/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Provide help messages for command line interface's public key commands.
"""
ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a list of the addresses of the public keys by.'
15 changes: 15 additions & 0 deletions cli/public_key/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Provide implementation of the public key interfaces.
"""


class PublicKeyInterface:
"""
Implements public key interface.
"""

def get_list(self, address):
"""
Get a list of the addresses of the public keys by account address.
"""
pass
42 changes: 42 additions & 0 deletions cli/public_key/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Provide implementation of the public key.
"""
import asyncio

from accessify import implements

from cli.public_key.interfaces import PublicKeyInterface

loop = asyncio.get_event_loop()


@implements(PublicKeyInterface)
class PublicKey:
"""
Implements public key.
"""

def __init__(self, service):
"""
Constructor.
Arguments:
service: object to interact with Remme core API.
"""
self.service = service

def get_list(self, address):
"""
Get a list of the addresses of the public keys by account address.
"""
try:
public_key_addresses = loop.run_until_complete(
self.service.public_key_storage.get_account_public_keys(address=address),
)

except Exception as error:
return None, str(error)

return {
'public_key_addresses': public_key_addresses,
}, None
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def data(self):
Get node configurations.
"""
return {
'node_address': '11682919ed54658edf965f955a5783e6a653ce3bb411b99c8afe9f6e5840af45171774',
'node_public_key': '03725231d64d1b379a1d855d0e7614684744ba915bd657e398f5a5cefc9ced896d',
'node_address': '116829f18683f6c30146559c9cb8d5d302545019ff00f2ab72500df99bceb7b81a1dad',
'node_public_key': '0350e9cf23966ad404dc56438fd01ec11a913446cfd7c4fb8d95586a58718431e7',
}


Expand Down
8 changes: 4 additions & 4 deletions tests/node/test_get_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from cli.constants import (
FAILED_EXIT_FROM_COMMAND_CODE,
LATEST_RELEASE_NODE_IP_ADDRESS_FOR_TESTING,
PASSED_EXIT_FROM_COMMAND_CODE,
RELEASE_0_9_0_ALPHA_NODE_ADDRESS,
)
from cli.entrypoint import cli
from cli.utils import dict_to_pretty_json
Expand All @@ -24,14 +24,14 @@ def test_get_node_configs():
'node',
'get-configs',
'--node-url',
LATEST_RELEASE_NODE_IP_ADDRESS_FOR_TESTING,
RELEASE_0_9_0_ALPHA_NODE_ADDRESS,
])

expected_node_configurations = {
'result': {
'configurations': {
'node_address': '11682919ed54658edf965f955a5783e6a653ce3bb411b99c8afe9f6e5840af45171774',
'node_public_key': '03725231d64d1b379a1d855d0e7614684744ba915bd657e398f5a5cefc9ced896d',
'node_address': '116829f18683f6c30146559c9cb8d5d302545019ff00f2ab72500df99bceb7b81a1dad',
'node_public_key': '0350e9cf23966ad404dc56438fd01ec11a913446cfd7c4fb8d95586a58718431e7',
},
},
}
Expand Down
Empty file added tests/public_key/__init__.py
Empty file.
Loading

0 comments on commit 0ed94c7

Please sign in to comment.