diff --git a/oocana/oocana/context.py b/oocana/oocana/context.py index e9f71699..697e98e5 100644 --- a/oocana/oocana/context.py +++ b/oocana/oocana/context.py @@ -682,6 +682,33 @@ def response_callback(payload: Dict[str, Any]): return await f + async def query_auth(self, id: str) -> Dict[str, Any]: + request_id = random_string(16) + loop = asyncio.get_running_loop() + f: asyncio.Future[Dict[str, Any]] = loop.create_future() + + def response_callback(payload: Dict[str, Any]): + if payload.get("request_id") != request_id: + return + self.__mainframe.remove_request_response_callback(self.session_id, request_id, response_callback) + if payload.get("result") is not None: + loop.call_soon_threadsafe(lambda: f.set_result(payload.get("result", {}))) + elif payload.get("error") is not None: + loop.call_soon_threadsafe(lambda: f.set_exception(ValueError(payload.get("error", "Unknown error occurred while querying the auth.")))) + + self.__mainframe.add_request_response_callback(self.session_id, request_id, response_callback) + + self.__mainframe.send(self.job_info, { + "type": "BlockRequest", + "action": "QueryAuth", + "id": id, + "session_id": self.session_id, + "job_id": self.job_id, + "request_id": request_id, + }) + + return await f + async def query_block(self, block: str) -> QueryBlockResponse: """ this is a experimental api, it is used to query the block information..