From 22d67f1042f643407ab3943eae5fafcd882cb2c0 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 7 Aug 2024 13:22:33 +0700 Subject: [PATCH] Create ibc_protocol.py --- .../interoperability/ibc/ibc_protocol.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 projects/DAPIO/interoperability/ibc/ibc_protocol.py diff --git a/projects/DAPIO/interoperability/ibc/ibc_protocol.py b/projects/DAPIO/interoperability/ibc/ibc_protocol.py new file mode 100644 index 000000000..9a0bb7e24 --- /dev/null +++ b/projects/DAPIO/interoperability/ibc/ibc_protocol.py @@ -0,0 +1,19 @@ +import json + +class IBCProtocol: + def __init__(self, connector: IBCConnector): + self.connector = connector + + def send_request(self, request: dict) -> dict: + message = json.dumps(request) + self.connector.send_message(message, self.connector.establish_connection()) + response = self.connector.receive_message(self.connector.establish_connection()) + return json.loads(response) + + def receive_request(self) -> dict: + message = self.connector.receive_message(self.connector.establish_connection()) + return json.loads(message) + + def send_response(self, response: dict) -> None: + message = json.dumps(response) + self.connector.send_message(message, self.connector.establish_connection())