Skip to content

Commit

Permalink
Release v0.6.0: set bet and close masternode, node account's simple t…
Browse files Browse the repository at this point in the history
…ransfer and from frozen to unfrozen (#69)
  • Loading branch information
dmytrostriletskyi authored May 24, 2019
1 parent a9b1c07 commit c028ccd
Show file tree
Hide file tree
Showing 23 changed files with 895 additions and 65 deletions.
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ $ remme account transfer-tokens \
}
```

### Node Account
### Node account

Get information about the node account by its address — ``remme node-account get``:

Expand Down Expand Up @@ -235,6 +235,39 @@ $ remme node-account get \
}
```

Transfer tokens to address — ``remme node-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 node-account transfer-tokens \
--private-key=7ae575740dcdae8e704ff461ab89ad42505e06abbbae8ea68e18387e537b7462 \
--address-to=1168292465adcaffeea284f89330dcc013533c8c285089b75466a958733f4f3fc9174d \
--amount=100 \
--node-url=node-genesis-testnet.remme.io
{
"result": {
"batch_identifier": "aac64d7b10be4b93b8c345b5eca1dc870c6b3905485e48a0ca5f58928a88a42b7a404abb4f1027e973314cca95379b1ef375358ad1661d0964c1ded4c212810f"
}
}
```

Transfer available tokens from frozen to unfrozen reputation's balances (executable only on the machine which runs the node) — `remme node-account transfer-tokens-from-frozen-to-unfrozen`.

```bash
$ remme node-account transfer-tokens-from-frozen-to-unfrozen
{
"result": {
"batch_id": "045c2b7c43a7ca7c3dc60e92714c03265572a726d1fae631c39a404eaf97770e3f6a7a8c35c86f6361afb2e4f12b4a17d71a66a19158b62f30531ab32b62f06f"
}
}
```

### Block

Get a list of blocks — ``remme block get-list``:
Expand Down Expand Up @@ -706,6 +739,33 @@ $ remme masternode open --amount=300000
}
```

Close the masternode (executable only on the machine which runs the node) — ``remme masternode close``:

```bash
$ remme masternode close
{
"result": {
"batch_id": "ae0ad8d5379beb28211cdc3f4d70a7ef66852eb815241cb201425897fc470e727c34e67ea77525ac696633afd27cca88227df52493889edcbb6fb840b4c93326"
}
}
```

Set the masternode betting behavior (executable only on the machine which runs the node) — ``remme masternode set-bet``:

| Arguments | Type | Required | Description |
| :-------: | :----: | :------: | ---------------------------------------------------------------- |
| bet | String | Yes | Bet to set to the masternode account. |
| | | | Possible values are `min`, `max`, or an integer value (e.g. 20). |

```bash
$ remme masternode set-bet --bet=max
{
"result": {
"batch_id": "a58c23ba6b346aeb3c7186754e436eb23162a5250384667a6c3ce70f7f02e19c42e8ca31f871e4aea333849b8ea752321882977499b1df098832a8296b0c6e9a"
}
}
```

### Public key

Get a list of the addresses of the public keys by account address — ``remme public-key get-list``:
Expand Down
6 changes: 2 additions & 4 deletions cli/account/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import click
from remme import Remme

from cli.account.forms import (
GetAccountBalanceForm,
TransferTokensForm,
)
from cli.account.forms import GetAccountBalanceForm
from cli.account.help import (
ACCOUNT_ADDRESS_ARGUMENT_HELP_MESSAGE,
ACCOUNT_ADDRESS_TO_ARGUMENT_HELP_MESSAGE,
Expand All @@ -21,6 +18,7 @@
FAILED_EXIT_FROM_COMMAND_CODE,
NODE_URL_ARGUMENT_HELP_MESSAGE,
)
from cli.generic.forms.forms import TransferTokensForm
from cli.utils import (
default_node_url,
print_errors,
Expand Down
24 changes: 1 addition & 23 deletions cli/account/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
"""
Provide forms for command line interface's account commands.
"""
from marshmallow import (
Schema,
fields,
validate,
)
from marshmallow import Schema

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


Expand All @@ -21,20 +16,3 @@ class GetAccountBalanceForm(Schema):

address = AccountAddressField(required=True)
node_url = NodeUrlField(required=True)


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(required=True)
2 changes: 2 additions & 0 deletions cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
RemmeFamilyName.SWAP.value,
]

BET_TYPES = ['max', 'min']

DEV_CONSENSUS_GENESIS_NODE_IP_ADDRESS_FOR_TESTING = '142.93.161.195'
DEV_CONSENSUS_GENESIS_NODE_ACCOUNT_ADDRESS = '1168292465adcaffeea284f89330dcc013533c8c285089b75466a958733f4f3fc9174d'
DEV_CONSENSUS_GENESIS_ACCOUNT_ADDRESS = '1120072465adcaffeea284f89330dcc013533c8c285089b75466a958733f4f3fc9174d'
Expand Down
9 changes: 9 additions & 0 deletions cli/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ class NotSupportedOsToGetNodePrivateKeyError(Exception):

def __init__(self, message):
self.message = message


class NotSupportedBetError(Exception):
"""
The following bet is not supported to be set as masternode betting behavior error.
"""

def __init__(self, message):
self.message = message
23 changes: 23 additions & 0 deletions cli/generic/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from cli.constants import (
ADDRESS_REGEXP,
BATCH_IDENTIFIER_REGEXP,
BET_TYPES,
BLOCK_IDENTIFIER_REGEXP,
DOMAIN_NAME_REGEXP,
FAMILY_NAMES,
Expand Down Expand Up @@ -250,3 +251,25 @@ def _deserialize(self, value, attr, obj, **kwargs):
block_validated_identifiers.append(identifier)

return block_validated_identifiers


class BetField(fields.Field):
"""
Implements validation of the bet.
"""

def _deserialize(self, value, attr, obj, **kwargs):
"""
Validate data (bet) that was passed to field.
Valid bet is `min` or `max` as strings, or an integer positive value.
"""
bet = value

if bet in BET_TYPES:
return bet

if bet.isdigit():
return int(bet)

raise ValidationError(f'The following bet `{bet}` is invalid.')
31 changes: 31 additions & 0 deletions cli/generic/forms/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Provide implementation of the generic forms.
"""
from marshmallow import (
Schema,
fields,
validate,
)

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


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(required=True)
83 changes: 80 additions & 3 deletions cli/masternode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@

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.errors import (
NotSupportedBetError,
NotSupportedOsToGetNodePrivateKeyError,
)
from cli.masternode.forms import (
OpenMasternodeForm,
SetBetMasternodeForm,
)
from cli.masternode.help import (
SET_BET_ARGUMENT_HELP_MESSAGE,
STARTING_AMOUNT_ARGUMENT_HELP_MESSAGE,
)
from cli.masternode.service import Masternode
from cli.utils import (
print_errors,
Expand Down Expand Up @@ -62,3 +71,71 @@ def open(amount):
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

print_result(result=result)


@masternode_commands.command('close')
def close():
"""
Close the masternode.
"""
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).close()

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

print_result(result=result)


@click.option('--bet', type=str, required=True, help=SET_BET_ARGUMENT_HELP_MESSAGE)
@masternode_commands.command('set-bet')
def set_bet(bet):
"""
Set the masternode betting behavior.
"""
arguments, errors = SetBetMasternodeForm().load({
'bet': bet,
})

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

bet = arguments.get('bet')

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'},
)

try:
result, errors = Masternode(service=remme).set_bet(bet=bet)

except NotSupportedBetError as error:
print_errors(errors=str(error))
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE)

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

print_result(result=result)
10 changes: 10 additions & 0 deletions cli/masternode/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
validate,
)

from cli.generic.forms.fields import BetField


class OpenMasternodeForm(Schema):
"""
Expand All @@ -20,3 +22,11 @@ class OpenMasternodeForm(Schema):
validate.Range(min=1, error='Amount must be greater than 0.'),
],
)


class SetBetMasternodeForm(Schema):
"""
Set the masternode betting behavior form.
"""

bet = BetField(required=True)
2 changes: 2 additions & 0 deletions cli/masternode/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
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.'
SET_BET_ARGUMENT_HELP_MESSAGE = \
'Bet to set to the masternode account. Possible values are `min`, `max`, or an integer value (e.g. 20).'
16 changes: 16 additions & 0 deletions cli/masternode/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ def open(self, amount):
Open the masternode with starting amount.
"""
pass

def close(self):
"""
Close the masternode.
"""
pass

def set_bet(self, bet):
"""
Set the masternode betting behavior.
Arguments:
bet (string or integer, required): type of bet to set to the masternode account. Valid bet is
`min` or `max` as strings, or an integer value (e.g. 20).
"""
pass
Loading

0 comments on commit c028ccd

Please sign in to comment.