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

feat(streams): parse server plugin for moralis streams #782

Merged
merged 4 commits into from
Oct 28, 2022

Conversation

sogunshola
Copy link
Contributor


name: 'Pull request'
about: A new pull request

New Pull Request

Checklist

  • I am not disclosing a vulnerability.
  • My code is conform the code style
  • I have made corresponding changes to the documentation
  • I have updated Typescript definitions when needed

Issue Description

Related issue: #FILL_THIS_OUT

Solution Description

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2022

🦋 Changeset detected

Latest commit: 344bf1d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
demo-parse-server-migration Minor
@moralisweb3/streams Minor
@moralisweb3/parse-server Minor
moralis Minor
@moralisweb3/core Minor
@moralisweb3/auth Minor
@moralisweb3/api-utils Minor
@moralisweb3/evm-utils Minor
@moralisweb3/sol-utils Minor
@moralisweb3/evm-api Minor
@moralisweb3/sol-api Minor
@moralisweb3/client-firebase-auth-utils Minor
@moralisweb3/client-firebase-evm-auth Minor
@moralisweb3/client-firebase-sol-auth Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sogunshola sogunshola requested review from ErnoW and b4rtaz October 28, 2022 11:58
Comment on lines +33 to +82
return express.Router().post(webhookUrl, bodyParser.json({ limit: '50mb' }), async (req, res) => {
try {
verifySignature(req, streams);
} catch (e) {
return res.status(401).json({ message: e.message });
}
try {
const updates: Record<string, any> = {};
const batch = req.body as IWebhook;

const logUpdates = logsProcessor.process(batch);
const txUpdates = txsProcessor.process(batch);
const internalTxUpdates = internalTxProcessor.process(batch);

// Prepare updates
if (!updates['Logs']) {
updates['Logs'] = [];
}
updates['Logs'].push(prepareUpdate(logUpdates, ['logIndex', 'transactionHash']));

if (!updates['Txs']) {
updates['Txs'] = [];
}
updates['Txs'].push(prepareUpdate(txUpdates, ['transactionIndex']));

if (!updates['TxsInternal']) {
updates['TxsInternal'] = [];
}
updates['TxsInternal'].push(prepareUpdate(internalTxUpdates, ['hash']));

const results: unknown[] = [];
const upsert = new Upsert(parseObject);
// eslint-disable-next-line guard-for-in
for (const tableName in updates) {
for (let index = 0; index < updates[tableName].length; index++) {
const data = updates[tableName][index];
data.forEach(({ filter, update }: any) => {
results.push(upsert.execute(tableName, filter, update));
});
}
}
await Promise.all(results);
} catch (e) {
// eslint-disable-next-line no-console
console.log('error while inserting logs', e.message);
return res.status(500).json({ message: 'error while inserting logs' });
}

return res.status(200).json({ message: 'ok' });
});

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [authorization](1), but is not rate-limited.
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2022

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 66%
66.56% (221/332) 50% (41/82) 68.05% (49/72)
auth Coverage: 97%
97.94% (143/146) 90.9% (20/22) 100% (42/42)
core Coverage: 89%
90.15% (568/630) 75.79% (119/157) 83.72% (108/129)
evm-api Coverage: 82%
80.72% (469/581) 17.57% (58/330) 66.32% (197/297)
evm-utils Coverage: 36%
36.68% (343/935) 39.17% (105/268) 28.26% (91/322)
sol-api Coverage: 75%
76.1% (86/113) 47.36% (9/19) 53.19% (25/47)
sol-utils Coverage: 82%
81.18% (82/101) 66.66% (12/18) 85.71% (30/35)
streams Coverage: 83%
84.46% (549/650) 66.08% (76/115) 79.06% (136/172)

@sogunshola sogunshola merged commit bab7a1e into main Oct 28, 2022
@sogunshola sogunshola deleted the feat/parse-server branch October 28, 2022 12:18
@github-actions github-actions bot mentioned this pull request Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants