-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fetch latest blocks from database #55
Comments
Hi @saimeunt can I work on this? |
Hi @Iwueseiter! |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedhello @saimeunt I would love to work on this issue I'm a frontend developer and I have made contribution to other repositories, and this would be my first contribution on this repository I would love to contribute to this project!! How I plan on tackling this issueHere is what is required to be done: Transfer Fetch Logic: Top-Level Server Component: Database Integration: Data Consistency Verification: Op-Indexer Utilization: |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedI'm a blockchain developer and also a frontend developer. I've contributed to projects here on onlydust before. How I plan on tackling this issueHere is how I intend to work on this task: Define an environment variable to toggle between JSON-RPC and database data sources. |
hello @saimeunt I would love to be assigned this issue and be a contributor on this project hopefully My background and how it can be leveraged Here is my Onlydust profile link https://app.onlydust.com/u/martinvibes. How I plan on tackling this issueTo solve this issue I’ll: |
Hi @martinvibes! |
I am applying to this issue via https://app.onlydust.com/p/opscan-by-walnut @saimeunt hello ,I am a frontend developer and this would be my first time contributing to this ecosystem |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedPlease I will like to be assigned this issue. I am a front-end Developer, and my experience includes html, css, react, JavaScript and a little of TypeScript. How I plan on tackling this issueTo solve this issue I’ll: |
Hi @saimeunt please I would love to be assigned this issue and be a contributor to your repo |
Hi @blessingbytes! |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedI am a Full Stack blockchain Developer with expertise in Next.js, Nest.js, TypeScript, JavaScript, React, Node.js, Three.js, and Solidity. My journey with OnlyDust hackathons began at Edition 1, and I've since made 30 contributions across 9 projects. With my extensive experience on the OnlyDust platform (profile: https://app.onlydust.com/u/Ugo-X), I've honed my skills in delivering quality solutions under pressure. How I plan on tackling this issueI will...
|
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedMy name is Collins Ikechukwu. I am a fullstack developer with 4 years of experience. I'm thrilled about the chance to contribute to the Op Scan Project. With 4 years of solid experience in Next.js, TypeScript, Shadcn, and React, Nodejs and PHP I'm confident in my ability to deliver an efficient and user-friendly Contract page for transactions. How I plan on tackling this issueCreate fetch-blocks.ts
Implement fetchFromDatabase
Update lib/fetch-data.ts I will Move the fetchLatestBlocks function logic from lib/fetch-data.ts to components/pages/blocks/fetch-blocks.ts. Ensure it is used appropriately. Update Blocks Page Component I will In the top-level server component for the blocks page, use the new fetchBlocks function to retrieve data. |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedI'm Poulav Bhowmick, with a robust background in TypeScript, fullstack development and blockchain technology. My experience includes building robust applications, optimizing functionalities and blockchain integration. I have actively participated in events and open source contributions, enhancing my capability to tackle real-world tech challenges. My projects can be viewed on my GitHub Profile and OnlyDust Profile. Plus I´m active member of Starknet community🇷. This is my first contribution to Walnut’s Repositories. How I plan on tackling this issueTo implement fetching latest blocks from either JSON-RPC or a database, I propose the following steps:
Here's a skeleton of the import { l2PublicClient } from "@/lib/chains";
import { prisma } from "@/lib/prisma";
import { fromViemBlock, Block } from "@/lib/types";
import { range } from "@/lib/utils";
const fetchLatestBlocksFromJsonRpc = async (start: bigint): Promise<Block[]> => {
const blocksPerPage = BigInt(process.env.NEXT_PUBLIC_BLOCKS_PER_PAGE);
const blocks = await Promise.all(
range(Number(start), Math.max(Number(start - blocksPerPage), -1)).map((i) =>
l2PublicClient.getBlock({ blockNumber: BigInt(i) }),
),
);
return blocks.map(fromViemBlock);
};
const fetchLatestBlocksFromDatabase = async (start: bigint): Promise<Block[]> => {
const blocksPerPage = BigInt(process.env.NEXT_PUBLIC_BLOCKS_PER_PAGE);
const blocks = await prisma.block.findMany({
where: {
number: {
lte: start.toString(),
gt: (start - blocksPerPage).toString(),
},
},
orderBy: {
number: 'desc',
},
take: Number(blocksPerPage),
});
if (blocks.length === 0) {
return fetchLatestBlocksFromJsonRpc(start);
}
return blocks.map(block => ({
number: BigInt(block.number),
hash: block.hash,
parentHash: block.parentHash,
timestamp: BigInt(block.timestamp),
nonce: block.nonce,
difficulty: BigInt(block.difficulty),
gasLimit: BigInt(block.gasLimit),
gasUsed: BigInt(block.gasUsed),
miner: block.miner,
extraData: block.extraData,
baseFeePerGas: block.baseFeePerGas ? BigInt(block.baseFeePerGas) : null,
transactions: [], // Assuming we don't need transactions here, adjust if needed
}));
};
const fetchLatestBlocks = process.env.DATABASE_URL
? fetchLatestBlocksFromDatabase
: fetchLatestBlocksFromJsonRpc;
export default fetchLatestBlocks;
This implementation follows the pattern established in the transaction details fetching, using the DATABASE_URL environment variable to determine the data source. It also includes a fallback to JSON-RPC if the database query fails or returns no results.
The blocks page should be updated to use this new function instead of calling fetchLatestBlocks from lib/fetch-data.ts. |
I am applying to this issue via OnlyDust platform. hello @saimeunt i would love to be assigned on this issue and be a ccontributor My background and how it can be leveragedi'm a How I plan on tackling this issueSteps: Clone the op-scan repository and set up your .env file with the DATA_SOURCE variable set to either jsonrpc or database. Create fetch-blocks.ts under components/pages/blocks/. Move the block fetching logic from lib/fetch-data.ts to fetch-blocks.ts. Modify the blocks page to call the new helper function. Set up and run op-indexer to keep the database synchronized. Test fetching blocks from both JSON-RPC and the database. i would love to participate on this repo and be amongs other contributors |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedHello! I worked in the last ODHack by adding the latest 10 transaction component in the home page, this issue seems to be pretty similar to it but now the data source is the DB. How I plan on tackling this issueI will follow what you suggested, basically querying the data from the DB and showing the results in the existing component, since I already worked on this project in the past I already have enough context :) |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedMy name is Nnawuihe Johnkennedy .I am a software developer using Mern stack, i havea wealth of experiences including working for Thorium Logic ,Ivan research institute e.t .c .This is my portfolio :johnkennedy.vercel.app How I plan on tackling this issueI can create a fetch-blocks.ts helper function to fetch latest blocks data from either JSON-RPC or a database using Prisma, configured via an environment variable, ensuring pagination logic is preserved, and update the blocks page to use this function while running op-indexer to keep the database updated. |
The maintainer saimeunt has assigned Ugo-X to this issue via OnlyDust Platform. |
Fetch latest blocks from database
Read contributors guidelines
User stories
As a rollup developer using op-scan, I want to fetch the latest blocks data either from JSON-RPC (current behavior) or from a database fed from op-indexer.
The data source should be abstracted away in a dedicated function and is configured using an environment variable.
Validation
It should fetch the exact same data whether calling the RPC directly or querying the database.
It MUST adhere to the existing design pattern already implemented in the tx details page.
Implementation
Create a new helper function under
components/pages/blocks/fetch-blocks.ts
, use the same logic found incomponents/pages/tx/fetch-transaction-details.ts
, a top level exported function which is data source agnostic and 2 separate functions fetching data from either JSON-RPC (this is already implemented here: https://github.com/walnuthq/op-scan/blob/main/src/lib/fetch-data.ts#L20-L28) or from the database (this is what has to be implemented).Move the fetchLatestBlocks data fetching logic from the
lib/fetch-data.ts
to this helper function and just call this function in the blocks page top-level server component.You will need to make sure the pagination logic is preserved when querying data via Prisma.
Run op-indexer as a background task in another terminal along the explorer to keep an up-to-date database mirroring what you'd fetch from the JSON-RPC endpoint.
Resources
The text was updated successfully, but these errors were encountered: