-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v0.5.0: open the node and the masternode, start filter in lis…
…t of states (#63)
- Loading branch information
1 parent
6eaa1fc
commit a9b1c07
Showing
23 changed files
with
398 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.