Skip to content

Commit

Permalink
Get list of the public keys by account address on which these keys de…
Browse files Browse the repository at this point in the history
…pend (#16)
  • Loading branch information
anastasiia-bilova authored Apr 24, 2019
1 parent 850d3a3 commit ef7ecd5
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* [Configuration file](#configuration-file)
* [Service](#service)
* [Account](#account)
* [Public key](#public-key)
* [Development](#development)
* [Requirements](#development-requirements)
* [Docker](#docker)
Expand Down Expand Up @@ -139,6 +140,29 @@ $ remme account transfer-tokens \
}
```

### 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/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import click

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


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


cli.add_command(account_commands)
cli.add_command(public_key_commands)
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
Empty file added tests/public_key/__init__.py
Empty file.
Loading

0 comments on commit ef7ecd5

Please sign in to comment.