diff --git a/src/middlewares/middleware.ts b/src/middlewares/middleware.ts index f954533..1b36249 100644 --- a/src/middlewares/middleware.ts +++ b/src/middlewares/middleware.ts @@ -22,14 +22,18 @@ export default class Middleware { blockchainTriggerFilter = async (req: Request, res: Response, next: NextFunction) => { //check if request is from blockchain trigger const { triggerPath, triggerValue, txHash } = extractTriggerDataFromRequest(req); + if(!triggerPath || !triggerValue || !txHash) { + res.send("Not from blockchain"); + return; + } const result = await this.ain.getValue(triggerPath); // if request is first reque st, set cache if (this.cache.get(txHash) && this.cache.get(txHash) !== "error") { - res.send("duplicated"); + res.send("Duplicated"); return; } this.cache.set(txHash, "in_progress", 500); - _.isEqual(result, triggerValue) ? next(): res.send("not from blockChain"); + _.isEqual(result, triggerValue) ? next(): res.send("Not from blockchain"); } /** * DEPRECATED diff --git a/src/utils/extractor.ts b/src/utils/extractor.ts index 47be1f4..87c7686 100644 --- a/src/utils/extractor.ts +++ b/src/utils/extractor.ts @@ -26,7 +26,7 @@ export const extractTriggerDataFromRequest = (req:Request) => { const triggerData = { triggerPath: path, triggerValue: req.body.value, - txHash: req.body.txhash, + txHash: req.body.transaction.hash, } return triggerData }