-
Notifications
You must be signed in to change notification settings - Fork 258
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 344bf1d The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
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 |
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.
b4rtaz
approved these changes
Oct 28, 2022
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
name: 'Pull request'
about: A new pull request
New Pull Request
Checklist
Issue Description
Related issue: #
FILL_THIS_OUT
Solution Description