Skip to content

Commit

Permalink
Release v0.5.0: open the node and the masternode, start filter in lis…
Browse files Browse the repository at this point in the history
…t of states (#63)
  • Loading branch information
dmytrostriletskyi authored May 21, 2019
1 parent 6eaa1fc commit a9b1c07
Show file tree
Hide file tree
Showing 23 changed files with 398 additions and 24 deletions.
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [Atomic Swap](#atomic-swap)
* [Batch](#batch)
* [Node](#node)
* [Masternode](#masternode)
* [Public key](#public-key)
* [State](#state)
* [Transaction](#transaction)
Expand Down Expand Up @@ -664,6 +665,17 @@ $ remme node get-info --node-url=node-27-testnet.remme.io
}
```

Open the node to participate in the network (executable only on the machine which runs the node) — ``remme node open``:

```bash
$ remme node open
{
"result": {
"batch_id": "b877a10ddc0ef7f28b0b4a075cbab580b5f7be4dc4063e282a87ce812105316569ccba6c554176c36174bb62025181dc7bb9d83cba57d90dd27c04c043261c9c"
}
}
```

Get the initial stake of the node — ``remme node get-initial-stake``:

| Arguments | Type | Required | Description |
Expand All @@ -677,6 +689,23 @@ $ remme node get-initial-stake --node-url=node-27-testnet.remme.io
}
```

### Masternode

Open the masternode (executable only on the machine which runs the node) — ``remme masternode open``:

| Arguments | Type | Required | Description |
| :-------: | :-------: | :--------: | ----------------------------------------------------------- |
| amount | Integer | Yes | Starting amount of tokens to put to the masternode account. |

```bash
$ remme masternode open --amount=300000
{
"result": {
"batch_id": "b877a10ddc0ef7f28b0b4a075cbab580b5f7be4dc4063e282a87ce812105316569ccba6c554176c36174bb62025181dc7bb9d83cba57d90dd27c04c043261c9c"
}
}
```

### Public key

Get a list of the addresses of the public keys by account address — ``remme public-key get-list``:
Expand Down Expand Up @@ -754,17 +783,19 @@ $ remme state get \

Get a list of states — ``remme state get-list``:

| Arguments | Type | Required | Description |
| :-------: | :-----: | :------: | -------------------------------------------- |
| address | String | No | Account address to get a list of states by. |
| limit | Integer | No | Maximum amount of transactions to return. |
| head | String | No | Block identifier to get a list of states to. |
| reverse | Bool | No | Parameter to reverse result. |
| node-url | String | No | Node URL to apply a command to. |
| Arguments | Type | Required | Description |
| :-------: | :-----: | :------: | ----------------------------------------------------- |
| address | String | No | Account address to get a list of states by. |
| start | String | No | Account address to get a list of states starting from.|
| limit | Integer | No | Maximum amount of transactions to return. |
| head | String | No | Block identifier to get a list of states to. |
| reverse | Bool | No | Parameter to reverse result. |
| node-url | String | No | Node URL to apply a command to. |

```bash
$ remme state get-list \
--address=00001d0024b20fbe284cdaca250b30f40c30c3999e2cafbace268f2f26d9d493a4d09b \
--start=00001d0024b20fbe284cdaca250b30f40c30c3999e2cafbace268f2f26d9d493a4d09b \
--limit=1 \
--head=d3b9c12f76bf33ed0fb70df9f0ab9af9b3e29a6c9cf3e446fb2d799bdae07a92721cc52a0f3c683a972d562abae6a041d09a90c4157fce9bd305036e1cb15149 \
--reverse \
Expand Down
2 changes: 2 additions & 0 deletions cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cli.atomic_swap.cli import atomic_swap_commands
from cli.batch.cli import batch_commands
from cli.block.cli import block_commands
from cli.masternode.cli import masternode_commands
from cli.node.cli import node_commands
from cli.node_account.cli import node_account_commands
from cli.public_key.cli import public_key_commands
Expand All @@ -29,6 +30,7 @@ def cli():
cli.add_command(atomic_swap_commands)
cli.add_command(batch_commands)
cli.add_command(block_commands)
cli.add_command(masternode_commands)
cli.add_command(node_commands)
cli.add_command(node_account_commands)
cli.add_command(public_key_commands)
Expand Down
Empty file added cli/masternode/__init__.py
Empty file.
64 changes: 64 additions & 0 deletions cli/masternode/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Provide implementation of the command line interface's masternode commands.
"""
import sys

import click
from remme import Remme
from remme.models.account.account_type import AccountType

from cli.config import NodePrivateKey
from cli.constants import FAILED_EXIT_FROM_COMMAND_CODE
from cli.errors import NotSupportedOsToGetNodePrivateKeyError
from cli.masternode.forms import OpenMasternodeForm
from cli.masternode.help import STARTING_AMOUNT_ARGUMENT_HELP_MESSAGE
from cli.masternode.service import Masternode
from cli.utils import (
print_errors,
print_result,
)


@click.group('masternode', chain=True)
def masternode_commands():
"""
Provide commands for working with masternode.
"""
pass


@click.option('--amount', type=int, required=True, help=STARTING_AMOUNT_ARGUMENT_HELP_MESSAGE)
@masternode_commands.command('open')
def open(amount):
"""
Open the masternode with starting amount.
"""
arguments, errors = OpenMasternodeForm().load({
'amount': amount,
})

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

amount = arguments.get('amount')

try:
node_private_key = NodePrivateKey().get()

except (NotSupportedOsToGetNodePrivateKeyError, FileNotFoundError) as error:
print_errors(errors=str(error))
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

remme = Remme(
account_config={'private_key_hex': node_private_key, 'account_type': AccountType.NODE},
network_config={'node_address': 'localhost' + ':8080'},
)

result, errors = Masternode(service=remme).open(amount=amount)

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

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


class OpenMasternodeForm(Schema):
"""
Open the masternode with starting amount form.
"""

amount = fields.Integer(
strict=True,
required=True,
validate=[
validate.Range(min=1, error='Amount must be greater than 0.'),
],
)
4 changes: 4 additions & 0 deletions cli/masternode/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Provide help messages for command line interface's masternode commands.
"""
STARTING_AMOUNT_ARGUMENT_HELP_MESSAGE = 'Starting amount of tokens to put to the masternode account.'
15 changes: 15 additions & 0 deletions cli/masternode/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Provide implementation of the masternode interfaces.
"""


class MasternodeInterface:
"""
Implements masternode interface.
"""

def open(self, amount):
"""
Open the masternode with starting amount.
"""
pass
42 changes: 42 additions & 0 deletions cli/masternode/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Provide implementation of the masternode.
"""
import asyncio

from accessify import implements

from cli.masternode.interfaces import MasternodeInterface

loop = asyncio.get_event_loop()


@implements(MasternodeInterface)
class Masternode:
"""
Implements masternode.
"""

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

def open(self, amount):
"""
Open the masternode with starting amount.
"""
try:
open_masternode = loop.run_until_complete(
self.service.node_management.open_master_node(amount=amount),
)

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

return {
'batch_id': open_masternode.batch_id,
}, None
29 changes: 29 additions & 0 deletions cli/node/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

import click
from remme import Remme
from remme.models.account.account_type import AccountType

from cli.config import NodePrivateKey
from cli.constants import (
FAILED_EXIT_FROM_COMMAND_CODE,
NODE_URL_ARGUMENT_HELP_MESSAGE,
)
from cli.errors import NotSupportedOsToGetNodePrivateKeyError
from cli.node.forms import (
GetNodeConfigurationsForm,
GetNodeInformationForm,
Expand Down Expand Up @@ -146,3 +149,29 @@ def get_initial_stake(node_url):
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

print_result(result=result)


@node_commands.command('open')
def open():
"""
Open the node to participate in the network.
"""
try:
node_private_key = NodePrivateKey().get()

except (NotSupportedOsToGetNodePrivateKeyError, FileNotFoundError) as error:
print_errors(errors=str(error))
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

remme = Remme(
account_config={'private_key_hex': node_private_key, 'account_type': AccountType.NODE},
network_config={'node_address': 'localhost' + ':8080'},
)

result, errors = Node(service=remme).open()

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

print_result(result=result)
6 changes: 6 additions & 0 deletions cli/node/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ def get_initial_stake(self):
Get the initial stake of the node.
"""
pass

def open(self):
"""
Open the node to participate in the network.
"""
pass
14 changes: 14 additions & 0 deletions cli/node/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ def get_initial_stake(self):
return None, str(error)

return node_initial_stake, None

def open(self):
"""
Open the node to participate in the network.
"""
try:
open_node = loop.run_until_complete(self.service.node_management.open_node())

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

return {
'batch_id': open_node.batch_id,
}, None
8 changes: 6 additions & 2 deletions cli/state/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
STATES_HEAD_ARGUMENT_HELP_MESSAGE,
STATES_LIMIT_ARGUMENT_HELP_MESSAGE,
STATES_REVERSE_ARGUMENT_HELP_MESSAGE,
STATES_START_ADDRESS_ARGUMENT_HELP_MESSAGE,
)
from cli.state.service import State
from cli.utils import (
Expand Down Expand Up @@ -69,17 +70,19 @@ def get_state(address, node_url):


@click.option('--address', required=False, type=str, help=STATE_ACCOUNT_ADDRESS_ARGUMENT_HELP_MESSAGE)
@click.option('--start', required=False, type=str, help=STATES_START_ADDRESS_ARGUMENT_HELP_MESSAGE)
@click.option('--limit', required=False, type=int, help=STATES_LIMIT_ARGUMENT_HELP_MESSAGE)
@click.option('--head', required=False, type=str, help=STATES_HEAD_ARGUMENT_HELP_MESSAGE)
@click.option('--reverse', required=False, is_flag=True, help=STATES_REVERSE_ARGUMENT_HELP_MESSAGE)
@click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url())
@state_command.command('get-list')
def get_states(address, limit, head, reverse, node_url):
def get_states(address, start, limit, head, reverse, node_url):
"""
Get a list of states.
"""
arguments, errors = GetStateListForm().load({
'address': address,
'start': start,
'limit': limit,
'head': head,
'reverse': reverse,
Expand All @@ -91,6 +94,7 @@ def get_states(address, limit, head, reverse, node_url):
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

address = arguments.get('address')
start = arguments.get('start')
limit = arguments.get('limit')
head = arguments.get('head')
reverse = arguments.get('reverse')
Expand All @@ -101,7 +105,7 @@ def get_states(address, limit, head, reverse, node_url):
})

result, errors = State(service=remme).get_list(
address=address, limit=limit, head=head, reverse=reverse,
address=address, start=start, limit=limit, head=head, reverse=reverse,
)

if errors is not None:
Expand Down
1 change: 1 addition & 0 deletions cli/state/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GetStateListForm(Schema):
"""

address = AccountAddressField(allow_none=True, required=False)
start = AccountAddressField(allow_none=True, required=False)
head = BlockIdentifierField(allow_none=True, required=False)
limit = fields.Integer(
allow_none=True,
Expand Down
1 change: 1 addition & 0 deletions cli/state/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Provide help messages for command line interface's state commands.
"""
STATE_ACCOUNT_ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a state by.'
STATES_START_ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a list of states starting from.'
STATES_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of states to return.'
STATES_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of states to.'
STATES_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.'
3 changes: 2 additions & 1 deletion cli/state/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ def get(self, address):
"""
pass

def get_list(self, address, limit, head, reverse):
def get_list(self, address, start, limit, head, reverse):
"""
Get a list of states.
A list of states could be filtered by account address, start address, limit, head identifier, reverse.
Arguments:
address (string, optional): account address to get a state by.
start (string, optional): account address to get a list of states starting from.
limit (int, optional): maximum amount of states to return.
head (string, optional): block identifier to get a list of states to.
reverse (bool, optional): parameter to reverse result.
Expand Down
Loading

0 comments on commit a9b1c07

Please sign in to comment.