def get_result(self, request: Request): identifier, req_id, operation = get_request_data(request) buy_key = BuyHandler.prepare_buy_key(identifier, req_id) result = self.state.get(buy_key) res = {f.IDENTIFIER.nm: identifier, f.REQ_ID.nm: req_id, "buy": result} return Reply(res)
def get_result(self, request: Request): ledger_id = request.operation.get(f.LEDGER_ID.nm, DOMAIN_LEDGER_ID) db = self.database_manager.get_database(ledger_id) if db is None: return RequestNack(request.identifier, request.reqId, 'Invalid ledger id {}'.format(ledger_id)) seq_no = request.operation.get(DATA) try: txn = self.node.getReplyFromLedger(db.ledger, seq_no) except KeyError: txn = None if txn is None: logger.debug("{} can not handle GET_TXN request: ledger doesn't " "have txn with seqNo={}".format(self, str(seq_no))) result = { f.IDENTIFIER.nm: request.identifier, f.REQ_ID.nm: request.reqId, TXN_TYPE: request.operation[TXN_TYPE], DATA: None } if txn: result[DATA] = txn.result result[f.SEQ_NO.nm] = get_seq_no(txn.result) return Reply(result)
def processRequest(self, request: Request, frm: str): if request.operation[TXN_TYPE] == GET_NYM: self.send_ack_to_client(request.key, frm) result = self.reqHandler.handleGetNymReq(request, frm) self.transmitToClient(Reply(result), frm) self.total_read_request_number += 1 elif request.operation[TXN_TYPE] == GET_SCHEMA: self.send_ack_to_client(request.key, frm) # TODO: `handleGetSchemaReq` should be changed to # `get_reply_for_schema_req`, the rationale being that the method # is not completely handling the request but fetching a response. # Similar reasoning follows for other methods below result = self.reqHandler.handleGetSchemaReq(request, frm) self.transmitToClient(Reply(result), frm) self.total_read_request_number += 1 elif request.operation[TXN_TYPE] == GET_ATTR: self.send_ack_to_client(request.key, frm) result = self.reqHandler.handleGetAttrsReq(request, frm) self.transmitToClient(Reply(result), frm) self.total_read_request_number += 1 elif request.operation[TXN_TYPE] == GET_CLAIM_DEF: self.send_ack_to_client(request.key, frm) result = self.reqHandler.handleGetClaimDefReq(request, frm) self.transmitToClient(Reply(result), frm) self.total_read_request_number += 1 elif request.operation[TXN_TYPE] == GET_TXNS: super().processRequest(request, frm) else: # forced request should be processed before consensus if (request.operation[TXN_TYPE] in [ POOL_UPGRADE, POOL_CONFIG]) and request.isForced(): self.configReqHandler.validate(request) self.configReqHandler.applyForced(request) # here we should have write transactions that should be processed # only on writable pool if self.poolCfg.isWritable() or (request.operation[TXN_TYPE] in [ POOL_UPGRADE, POOL_CONFIG]): super().processRequest(request, frm) else: raise InvalidClientRequest( request.identifier, request.reqId, 'Pool is in readonly mode, try again in 60 seconds')
def processRequest(self, request, frm): if request.operation[TXN_TYPE] == 'get_buy': self.send_ack_to_client(request.key, frm) identifier = request.identifier buy_key = self.reqHandler.prepare_buy_key(identifier) result = self.reqHandler.state.get(buy_key) res = { f.IDENTIFIER.nm: identifier, f.REQ_ID.nm: request.reqId, "buy": result } self.transmitToClient(Reply(res), frm) else: super().processRequest(request, frm)
def processRequest(self, request, frm): if request.operation[TXN_TYPE] == GET_BUY: self.send_ack_to_client(request.key, frm) identifier = request.identifier req_id = request.reqId result = self.read_manager.get_result(request) res = { f.IDENTIFIER.nm: identifier, f.REQ_ID.nm: req_id, "buy": result } self.transmitToClient(Reply(res), frm) else: super().processRequest(request, frm)