-
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.
Refactor account CLI commands and implementation (#26)
- Loading branch information
1 parent
a8cef2a
commit fcf353a
Showing
13 changed files
with
134 additions
and
79 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
Provide help messages for command line interface's account commands. | ||
""" | ||
GET_ACCOUNT_BALANCE_ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a balance by.' | ||
ADDRESS_ARGUMENT_HELP_MESSAGE = 'Account address to get a balance by.' |
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
Empty file.
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,62 @@ | ||
""" | ||
Provide implementation of the custom fields. | ||
""" | ||
import re | ||
|
||
from marshmallow import ( | ||
ValidationError, | ||
fields, | ||
) | ||
|
||
from cli.constants import ( | ||
ADDRESS_REGEXP, | ||
DOMAIN_NAME_REGEXP, | ||
) | ||
|
||
|
||
class AccountAddressField(fields.Field): | ||
""" | ||
Implements validation of the account address. | ||
References: | ||
- https://marshmallow.readthedocs.io/en/3.0/custom_fields.html | ||
""" | ||
|
||
def _deserialize(self, value, attr, obj, **kwargs): | ||
""" | ||
Validate data (account address) that was passed to field. | ||
""" | ||
address = value | ||
|
||
if re.match(pattern=ADDRESS_REGEXP, string=address) is None: | ||
raise ValidationError(f'The following address `{address}` is invalid.') | ||
|
||
return address | ||
|
||
|
||
class NodeURLField(fields.Field): | ||
""" | ||
Implements validation of the node URL. | ||
If node URL is localhost, it means client didn't passed any URL, so nothing to validate. | ||
References: | ||
- https://marshmallow.readthedocs.io/en/3.0/custom_fields.html | ||
""" | ||
|
||
def _deserialize(self, value, attr, obj, **kwargs): | ||
""" | ||
Validate data (node URL) that was passed to field. | ||
""" | ||
node_url = value | ||
|
||
if node_url == 'localhost': | ||
return node_url | ||
|
||
if 'http' in node_url or 'https' in node_url: | ||
raise ValidationError(f'Pass the following node URL `{node_url}` without protocol (http, https, etc.).') | ||
|
||
if re.match(pattern=DOMAIN_NAME_REGEXP, string=node_url) is None: | ||
raise ValidationError(f'The following node URL `{node_url}` is invalid.') | ||
|
||
return node_url |
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