Fix atomic swap
@@ -3,10 +3,12 @@ import logging
from aiohttp_json_rpc import (
RpcInvalidParamsError,
+ RpcGenericServerDefinedError,
)
from google.protobuf.json_format import MessageToJson
from remme.clients.atomic_swap import AtomicSwapClient
+from remme.shared.exceptions import KeyNotFound
__all__ = (
@@ -25,7 +27,13 @@ async def get_atomic_swap_info(request):
except KeyError as e:
raise RpcInvalidParamsError(message='Missed swap_id')
+ try:
swap_info = client.swap_get(swap_id)
+ except KeyNotFound:
+ raise RpcGenericServerDefinedError(
+ error_code=-32050,
+ message=f'Atomic swap with id "{swap_id}" not found'
+ )
LOGGER.info(f'Get swap info {swap_info}')
data = MessageToJson(
swap_info, preserving_proto_field_name=True,
@@ -36,4 +44,10 @@ async def get_atomic_swap_info(request):
async def get_atomic_swap_public_key(request):
client = AtomicSwapClient()
+ try:
return client.get_pub_key_encryption()
+ except KeyNotFound:
+ raise RpcGenericServerDefinedError(
+ error_code=-32050,
+ message='Public key for atomic swap not set'
+ )
