-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fetching block details from database #58
Conversation
Someone is attempting to deploy a commit to the Walnut Team on Vercel. A member of the Team first needs to authorize it. |
@saimeunt Do have a look at this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PoulavBhowmick03 nice work, please make the requested changes and we'll merge this ASAP.
src/components/lib/fetch-data.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is a leftover and is no longer needed, please delete it.
prisma/schema.prisma
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only commit the renaming of POSTGRES_URL to DATABASE_URL but keep the default option to use sqlite.
import { prisma } from "@/lib/prisma"; | ||
|
||
type FetchBlockDetailsReturnType = { | ||
block: Block | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these functions returns only a Block or null, there's no need for this helper type, just specify their return type as Block | null
directly.
const fetchBlockDetailsFromDatabase = async ( | ||
number: bigint, | ||
): Promise<FetchBlockDetailsReturnType> => { | ||
console.log(`Attempting to fetch block ${number} from database`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all the console.logs, we don't want them outside of testing purpose.
): Promise<FetchBlockDetailsReturnType> => { | ||
console.log(`Attempting to fetch block ${number} from database`); | ||
const block = await prisma.block.findUnique({ | ||
where: { number: BigInt(number) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number is already a bigint, there's no need to cast it to BigInt.
console.log(`Fetching block ${number} from JSON-RPC`); | ||
const block = await l2PublicClient.getBlock({ blockNumber: number }); | ||
|
||
if (!block) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next few lines can be simplified by return block ? fromViemBlock(block) : null;
@saimeunt , thank you! made the changes, do have a look |
@PoulavBhowmick03 there's a final change to be made here: Remove the curly braces because we're no longer returning an enclosing object. |
@saimeunt done |
Related Issues
Closes #53
Changes
fetchBlockDetails
incomponents/pages/block/fetch-block-details.ts
components/pages/block/index.tsx
to use the newfetchBlockDetails
functionImplementation Details
fetchBlockDetails
function is data source agnosticfetchBlockDetailsFromJsonRpc
: fetches data from JSON-RPC (existing behavior)fetchBlockDetailsFromDatabase
: fetches data from the database (new implementation)DATABASE_URL
environment variableValidation
Additional Notes