-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REM-1312: Get particular Atomic Swap information by its identifier #24
Changes from 7 commits
02a8bca
e628ecd
a36b469
9c2b446
4704b21
cbf1be3
a92a23d
cef8365
881434c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
""" | ||
Provide help messages for command line interface's atomic swap commands. | ||
""" | ||
SWAP_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Swap identifier to get an information about swap by.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Alladin9393, done. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import asyncio | ||
|
||
from accessify import implements | ||
from aiohttp_json_rpc import RpcGenericServerDefinedError | ||
|
||
from cli.atomic_swap.interfaces import AtomicSwapInterface | ||
|
||
|
@@ -38,3 +39,20 @@ def get_public_key(self): | |
return { | ||
'public_key': public_key, | ||
}, None | ||
|
||
def get(self, swap_id): | ||
""" | ||
Get information about atomic swap by its identifier. | ||
""" | ||
try: | ||
swap_info = loop.run_until_complete(self.service.swap.get_info(swap_id=swap_id)) | ||
|
||
except RpcGenericServerDefinedError as error: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ticket is not related to |
||
return None, str(error.message) | ||
|
||
except Exception as error: | ||
return None, str(error) | ||
|
||
return { | ||
'information': swap_info.data, | ||
}, None |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
PUBLIC_KEY_REGEXP = r'^[0-9a-f]{66}$' | ||
PUBLIC_KEY_ADDRESS_REGEXP = r'^[0-9a-f]{70}$' | ||
HEADER_SIGNATURE_REGEXP = r'^[0-9a-f]{128}$' | ||
SWAP_IDENTIFIER_REGEXP = r'^[a-f0-9]{64}$' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change according to alphabetical order. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constants not in alphabetical order. It should be fixed in another ticket for technical dept. |
||
DOMAIN_NAME_REGEXP = r'(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]' | ||
|
||
PASSED_EXIT_FROM_COMMAND_CODE = 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
DOMAIN_NAME_REGEXP, | ||
PRIVATE_KEY_REGEXP, | ||
PUBLIC_KEY_ADDRESS_REGEXP, | ||
SWAP_IDENTIFIER_REGEXP, | ||
) | ||
|
||
|
||
|
@@ -102,3 +103,23 @@ def _deserialize(self, value, attr, data, **kwargs): | |
raise ValidationError(f'The following public key address `{public_key_address}` is invalid.') | ||
|
||
return value | ||
|
||
|
||
class SwapIdentifierField(fields.Field): | ||
""" | ||
Implements validation of the swap identifier. | ||
|
||
References: | ||
- https://marshmallow.readthedocs.io/en/3.0/custom_fields.html | ||
""" | ||
|
||
def _deserialize(self, value, attr, data, **kwargs): | ||
""" | ||
Validate data (swap identifier) that was passed to field. | ||
""" | ||
swap_identifier = value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is it for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For more detail, variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You create a class that named
and you have a method
Also, you validate one variable and return another, it not logical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These points are the core arguments why we should create the separated explicit (!) variable and return it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmytrostriletskyi, ok, but we don't return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Alladin9393, refresh page. |
||
|
||
if re.match(pattern=SWAP_IDENTIFIER_REGEXP, string=swap_identifier) is None: | ||
raise ValidationError(f'The following swap identifier `{swap_identifier}` is invalid.') | ||
|
||
return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get information about atomic swap by its identifier form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmytrostriletskyi, done.