Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge beta updates #106

Merged
merged 10 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class Ainize {
async loginWithSigner() {
const signer = new AinWalletSigner;
this.ain.setSigner(signer);
await this.handler.connect();
console.log('login success! address: ', await this.ain.getAddress());
}

Expand Down
31 changes: 20 additions & 11 deletions src/middlewares/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,28 @@ 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");
try {
const { triggerPath, triggerValue, txHash } = extractTriggerDataFromRequest(req);
if(!triggerPath || !triggerValue || !txHash) {
throw new Error("Not from blockchain");
}
// NOTE(yoojin): Validation will changed. Temp comment out.
// 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");
return;
}
this.cache.set(txHash, "in_progress", 500);
// NOTE(yoojin): Validation will changed. Temp comment out.
// _.isEqual(result, triggerValue) ? next(): res.send("Not from blockchain");
next();
} catch (e) {
console.log("Filtering Error ", e)
res.send(e);
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");
return;
}
this.cache.set(txHash, "in_progress", 500);
_.isEqual(result, triggerValue) ? next(): res.send("Not from blockchain");
}
/**
* DEPRECATED
Expand Down
Loading