Exemplo n.º 1
0
    def doCustomAction(self, ppTime: float, req: Request) -> None:
        """
        Execute the REQUEST sent to this Node

        :param ppTime: the time at which PRE-PREPARE was sent
        :param req: the client REQUEST
        """
        if req.operation[TXN_TYPE] == NYM and not \
                self.canNymRequestBeProcessed(req.identifier, req.operation):
            reason = "nym {} is already added".format(
                req.operation[TARGET_NYM])
            if req.key in self.requestSender:
                self.transmitToClient(RequestNack(*req.key, reason),
                                      self.requestSender.pop(req.key))
        else:
            reply = self.generateReply(int(ppTime), req)
            self.storeTxnAndSendToClient(reply)
Exemplo n.º 2
0
    def doCustomAction(self, ppTime: float, req: Request) -> None:
        """
        Execute the REQUEST sent to this Node

        :param ppTime: the time at which PRE-PREPARE was sent
        :param req: the client REQUEST
        """
        if req.operation[TXN_TYPE] == NYM and not \
                self.canNymRequestBeProcessed(req.identifier, req.operation):
            reason = "nym {} is already added".format(req.operation[TARGET_NYM])
            if req.key in self.requestSender:
                self.transmitToClient(RequestNack(*req.key, reason),
                                      self.requestSender.pop(req.key))
        else:
            reply = self.generateReply(int(ppTime), req)
            self.storeTxnAndSendToClient(reply)
            if req.operation[TXN_TYPE] in CONFIG_TXN_TYPES:
                # Currently config ledger has only code update related changes
                # so transaction goes to Upgrader
                self.upgrader.handleUpgradeTxn(reply.result)
Exemplo n.º 3
0
 def processGetTxnReq(self, request: Request, frm: str):
     nym = request.operation[TARGET_NYM]
     origin = request.identifier
     if nym != origin:
         # TODO not sure this is correct; why does it matter?
         msg = "You can only receive transactions for yourself"
         self.transmitToClient(RequestNack(*request.key, msg), frm)
     else:
         self.transmitToClient(RequestAck(*request.key), frm)
         data = request.operation.get(DATA)
         addNymTxn = self.graphStore.getAddNymTxn(origin)
         txnIds = [addNymTxn[TXN_ID], ] + self.graphStore. \
             getAddAttributeTxnIds(origin)
         # If sending transactions to a user then should send user's
         # sponsor creation transaction also
         if addNymTxn.get(ROLE) == USER:
             sponsorNymTxn = self.graphStore.getAddNymTxn(
                 addNymTxn.get(f.IDENTIFIER.nm))
             txnIds = [
                 sponsorNymTxn[TXN_ID],
             ] + txnIds
         # TODO: Remove this log statement
         logger.debug("{} getting replies for {}".format(self, txnIds))
         result = self.secondaryStorage.getReplies(*txnIds, seqNo=data)
         txns = sorted(list(result.values()), key=itemgetter(F.seqNo.name))
         lastTxn = str(txns[-1][F.seqNo.name]) if len(txns) > 0 else data
         result = {TXN_ID: self.genTxnId(request.identifier, request.reqId)}
         result.update(request.operation)
         # TODO: We should have a single JSON encoder which does the
         # encoding for us, like sorting by keys, handling datetime objects.
         result[DATA] = json.dumps({
             LAST_TXN: lastTxn,
             TXNS: txns
         },
                                   default=dateTimeEncoding,
                                   sort_keys=True)
         result.update({
             f.IDENTIFIER.nm: request.identifier,
             f.REQ_ID.nm: request.reqId,
         })
         self.transmitToClient(Reply(result), frm)
Exemplo n.º 4
0
 def nackReq(self, req, frm):
     self.transmitToClient(RequestNack(*req.key, reason="testing"), frm)