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: add log in rpc resp validation #210

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all 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
15 changes: 14 additions & 1 deletion pages/api/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import clone from 'just-clone'
import getConfig from 'next/config'
import { CHAINS } from '@lido-sdk/constants'
import { commonPatterns, satanizer } from '@lidofinance/satanizer'
import { parseChainId } from 'modules/blockChain/chains'
import { fetchWithFallback } from 'modules/network/utils/fetchWithFallback'
import type { NextApiRequest, NextApiResponse } from 'next'
Expand Down Expand Up @@ -30,6 +31,17 @@ interface IStat {
voteId: number
}

const patterns = [
...commonPatterns,
process.env.INFURA_API_KEY,
process.env.ALCHEMY_API_KEY,
process.env.ETHERSCAN_API_KEY,
process.env.WALLETCONNECT_PROJECT_ID,
...(process.env.EL_RPC_URLS_1 || 'NO_EL_RPC_URLS_1').split(','),
...(process.env.EL_RPC_URLS_17000 || 'NO_EL_RPC_URLS_17000').split(','),
]
const mask = satanizer(patterns)

const isStartFromTopic = (topic: string) => (req: IRpcRequest) =>
req.method === 'eth_getLogs' && req.params[0]?.topics?.[0] === topic

Expand Down Expand Up @@ -75,7 +87,7 @@ export default async function rpc(req: NextApiRequest, res: NextApiResponse) {
AragonVoting[chainId] ?? '',
AragonVotingAbi__factory.abi,
)
const filter = contractVoting.filters.StartVote(Number(0))
const filter = contractVoting.filters.StartVote()
const startVoteTopic = String(filter.topics?.[0])
const voteEvents: IStat[] = req.body
.filter(isStartFromTopic(startVoteTopic))
Expand All @@ -98,6 +110,7 @@ export default async function rpc(req: NextApiRequest, res: NextApiResponse) {
})
} catch (err) {
console.error(`Failed on empty log response verification`)
console.error(mask(err))
}

res.status(requested.status).json(responded)
Expand Down
Loading