-
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 block transactions from database #54
Comments
@saimeunt can I work on this issue? |
Hi @ShantelPeters! |
I am applying for this use via https://app.onlydust.com/p/opscan-by-walnut @saimeunt .. please can I be assigned to this issue ? |
Hi @ShantelPeters! |
@saimeunt I'll to work on this |
Hi @raizo07! |
Hi @saimeunt i am applying to this issue via https://app.onlydust.com/p/opscan-by-walnut I’m a front end developer and I would love to be assigned to this issue |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedHello, I'm Renzo, a Software Engineer with over 5+ years of experience in the industry, I recently started in Web3 as a member of Dojo Coding and this would be one of my first contributions to the ecosystem! How I plan on tackling this issue
File Changes
|
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedI have experience working with databases, JSON manipulation and typescript and i would like to contribute to this project. How I plan on tackling this issue
|
Hello @saimeunt , Please can i be assigned this issue? This is my first time contributing to this ecosystem and I would love to be given the opportunity. I am a front-end Developer, and my experience includes html, css, react, JavaScript and a little of TypeScript. To solve this issue, I’ll follow the implementation guidelines strictly and make sure I follow it in details and I’ll create the function and test the function I was asked to create in the implementation guideline. Please assign me. I’ll begin work ASAP! |
Hi @od-hunter! |
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-block-transactions. Update or create lib/fetch-database.ts to include the function for querying block transactions from the database using Prisma. I will move the block transactions data fetching logic from lib/fetch-data.ts to components/pages/block-txs/fetch-block-transactions.ts. Then update Block Transactions Page Component |
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 block transactions 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 {
fromViemTransactionWithReceipt,
TransactionWithReceipt,
fromPrismaTransactionWithReceipt
} from "@/lib/types";
import { getSignatureBySelector } from "@/lib/4byte-directory";
type FetchBlockTransactionsReturnType = {
transactions: TransactionWithReceipt[];
blockNumber: bigint;
blockTimestamp: bigint;
};
const fetchBlockTransactionsFromJsonRpc = async (number: bigint): Promise<FetchBlockTransactionsReturnType> => {
const block = await l2PublicClient.getBlock({
blockNumber: number,
includeTransactions: true,
});
if (!block) {
throw new Error(`Block ${number} not found`);
}
const [receipts, signatures] = await Promise.all([
Promise.all(
block.transactions.map(({ hash }) =>
l2PublicClient.getTransactionReceipt({ hash }),
),
),
Promise.all(
block.transactions.map(({ input }) =>
getSignatureBySelector(input.slice(0, 10)),
),
),
]);
const transactions = block.transactions.map((transaction, i) =>
fromViemTransactionWithReceipt(
transaction,
receipts[i],
block.timestamp,
signatures[i],
),
);
return { transactions, blockNumber: block.number, blockTimestamp: block.timestamp };
};
const fetchBlockTransactionsFromDatabase = async (number: bigint): Promise<FetchBlockTransactionsReturnType> => {
const block = await prisma.block.findUnique({
where: { number: number.toString() },
include: {
transactions: {
include: { receipt: true }
}
},
});
if (!block) {
return fetchBlockTransactionsFromJsonRpc(number);
}
const transactions = await Promise.all(block.transactions.map(async (transaction) => {
const signature = await getSignatureBySelector(transaction.input.slice(0, 10));
return fromPrismaTransactionWithReceipt(transaction, transaction.receipt, signature);
}));
return {
transactions,
blockNumber: BigInt(block.number),
blockTimestamp: BigInt(block.timestamp),
};
};
const fetchBlockTransactions = process.env.DATABASE_URL
? fetchBlockTransactionsFromDatabase
: fetchBlockTransactionsFromJsonRpc;
export default fetchBlockTransactions;
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 block transactions page (components/pages/block-txs/index.tsx) should be updated to use this new function instead of directly querying the JSON-RPC endpoint. |
Hi @martinvibes! |
The maintainer saimeunt has assigned renzobanegass to this issue via OnlyDust Platform. |
@renzobanegass this one goes to you, good luck! @PoulavBhowmick03 really appreciate your comment as it was a very solid proof of your understanding of the issue, but I'm afraid we try to only assign one issue per person during the hack (in case we have alternative good enough applications) to give a chance to everyone. |
Thanks, I´ll start right away! |
PR created! Waiting for feedback! |
Fetch block transactions from database
Read contributors guidelines
User stories
As a rollup developer using op-scan, I want to fetch the block transactions 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/block-txs/fetch-block-transactions.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/components/pages/block-txs/index.tsx#L11-L37) or from the database (this is what has to be implemented).Move the block transactions data fetching logic from the block txs page to this helper function and just call this function in the block txs page top-level server component.
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: