-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trade: prevent create wallet when rpc getLogs req fails
- Loading branch information
Showing
5 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { chain } from "@/lib/viem" | ||
import { NextRequest } from "next/server" | ||
import { createPublicClient, http, parseAbiItem } from "viem" | ||
|
||
export const runtime = "edge" | ||
|
||
// Necessary because public RPC does not support getting logs | ||
const viemClient = createPublicClient({ | ||
chain, | ||
transport: http(process.env.RPC_URL), | ||
}) | ||
|
||
export async function GET(req: NextRequest) { | ||
try { | ||
const blinderShare = BigInt( | ||
req.nextUrl.searchParams.get("blinderShare") || "0" | ||
) | ||
if (!blinderShare) { | ||
throw new Error("Blinder share is required") | ||
} | ||
const logs = await viemClient.getLogs({ | ||
address: process.env.NEXT_PUBLIC_DARKPOOL_CONTRACT, | ||
event: parseAbiItem( | ||
"event WalletUpdated(uint256 indexed wallet_blinder_share)" | ||
), | ||
args: { | ||
wallet_blinder_share: blinderShare, | ||
}, | ||
fromBlock: BigInt(process.env.FROM_BLOCK || 0), | ||
}) | ||
return new Response(JSON.stringify({ logs: logs.length })) | ||
} catch (error) { | ||
console.error(error) | ||
return new Response(JSON.stringify({ error }), { status: 500 }) | ||
} | ||
} |
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.