From ba53f43c860b34a0ab1c7dce54f6c09a38b41449 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Tue, 30 Jan 2024 14:00:27 +0900 Subject: [PATCH 1/3] fix: path --- src/middlewares/middleware.ts | 4 ++++ src/utils/extractor.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/middlewares/middleware.ts b/src/middlewares/middleware.ts index f954533..02b5975 100644 --- a/src/middlewares/middleware.ts +++ b/src/middlewares/middleware.ts @@ -22,6 +22,10 @@ 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") { 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 } From 2aaa4dbd87a0ee9534ad265bc886134b85c56262 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Tue, 30 Jan 2024 14:03:52 +0900 Subject: [PATCH 2/3] letterCase --- src/middlewares/middleware.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/middlewares/middleware.ts b/src/middlewares/middleware.ts index 02b5975..49139d5 100644 --- a/src/middlewares/middleware.ts +++ b/src/middlewares/middleware.ts @@ -23,17 +23,17 @@ export default class Middleware { //check if request is from blockchain trigger const { triggerPath, triggerValue, txHash } = extractTriggerDataFromRequest(req); if(!triggerPath || !triggerValue || !txHash) { - res.send("not from blockChain"); + 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 From dc4d34a5b40a21722dbd11ad31430d7cd86cbba8 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Tue, 30 Jan 2024 14:04:29 +0900 Subject: [PATCH 3/3] fix --- src/middlewares/middleware.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middlewares/middleware.ts b/src/middlewares/middleware.ts index 49139d5..1b36249 100644 --- a/src/middlewares/middleware.ts +++ b/src/middlewares/middleware.ts @@ -23,7 +23,7 @@ export default class Middleware { //check if request is from blockchain trigger const { triggerPath, triggerValue, txHash } = extractTriggerDataFromRequest(req); if(!triggerPath || !triggerValue || !txHash) { - res.send("Not from blockChain"); + res.send("Not from blockchain"); return; } const result = await this.ain.getValue(triggerPath); @@ -33,7 +33,7 @@ export default class Middleware { 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