-
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.
Add form for getting account balance arguments
- Loading branch information
1 parent
21a83bb
commit 0f01dc7
Showing
6 changed files
with
206 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Provide forms for command line interface's account commands. | ||
""" | ||
import re | ||
|
||
from marshmallow import ( | ||
Schema, | ||
ValidationError, | ||
fields, | ||
validates, | ||
) | ||
|
||
from cli.constants import ( | ||
ADDRESS_REGEXP, | ||
DOMAIN_NAME_REGEXP, | ||
) | ||
|
||
|
||
class GetAccountBalanceForm(Schema): | ||
""" | ||
Get balance of the account form. | ||
""" | ||
|
||
address = fields.String(required=True) | ||
node_url = fields.String(allow_none=True, required=False) | ||
|
||
@validates('address') | ||
def validate_address(self, address): | ||
""" | ||
Validate account address. | ||
""" | ||
if re.match(pattern=ADDRESS_REGEXP, string=address) is None: | ||
raise ValidationError(f'The following address `{address}` is invalid.') | ||
|
||
@validates('node_url') | ||
def validate_node_url(self, node_url): | ||
""" | ||
Validate node URL. | ||
If node URL is localhost, it means client didn't passed any URL, so nothing to validate. | ||
""" | ||
if node_url is 'localhost': | ||
return | ||
|
||
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.') |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ accessify==0.3.1 | |
asyncio==3.4.3 | ||
click==7.0 | ||
remme==1.0.0 | ||
marshmallow==2.19.2 |
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