Skip to content

Commit

Permalink
Add SEARCH_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed May 20, 2024
1 parent 05a2788 commit 21709e4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion scroll-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ npm install -g bun
cd scroll-gateway
bun install
touch .dev.vars
## set L2_PROVIDER_URL
## set L2_PROVIDER_URL and SEARCH_URL(the default for sepolia is https://sepolia-rpc.scroll.io)
yarn dev
```

Expand Down
6 changes: 4 additions & 2 deletions scroll-gateway/src/ScrollProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ export interface ScrollProvableBlock {
export class ScrollProofService implements IProofService<ScrollProvableBlock> {
private readonly l2Provider: ethers.JsonRpcProvider;
private readonly helper: EVMProofHelper;
private readonly searchUrl: string;

constructor(
searchUrl: string,
l2Provider: ethers.JsonRpcProvider,
) {
this.l2Provider = l2Provider;
this.helper = new EVMProofHelper(l2Provider);
this.searchUrl = searchUrl;
}

async getStorageAt(block: ScrollProvableBlock, address: AddressLike, slot: bigint): Promise<string> {
Expand All @@ -40,9 +43,8 @@ export class ScrollProofService implements IProofService<ScrollProvableBlock> {
address: AddressLike,
slots: bigint[]
): Promise<string> {
const searchUrl = 'https://sepolia-api-re.scroll.io/api/search';
const { batch_index: batchIndex } = await (
await fetch(`${searchUrl}?keyword=${Number(block.number)}`)
await fetch(`${this.searchUrl}?keyword=${Number(block.number)}`)
).json();
const proof = await this.helper.getProofs(Number(block.number), address, slots);
const compressedProofs: string[] = [];
Expand Down
3 changes: 2 additions & 1 deletion scroll-gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
export type ScrollGateway = EVMGateway<ScrollProvableBlock>;

export async function makeScrollGateway(
searchUrl: string,
l2providerUrl: string
): Promise<ScrollGateway> {
const l2Provider = new JsonRpcProvider(l2providerUrl);
return new EVMGateway(new ScrollProofService(l2Provider));
return new EVMGateway(new ScrollProofService(searchUrl, l2Provider));
}

export { ScrollProofService, type ScrollProvableBlock };
9 changes: 8 additions & 1 deletion scroll-gateway/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const program = new Command()
'-v, --l2-provider-url <url>',
'l2 provider url',
'http://localhost:9545/'
)
.option(
'-s --search-url <search>',
'search url to fetch batch index',
process.env.SEARCH_URL
);

program.parse();
Expand All @@ -19,7 +24,9 @@ program.parse();

const l2Provider = new JsonRpcProvider(options.l2ProviderUrl);

const gateway = new EVMGateway(new ScrollProofService(l2Provider));
const gateway = new EVMGateway(
new ScrollProofService(options.searchUrl, l2Provider)
);
const server = new Server();
gateway.add(server);
const app = server.makeApp('/');
Expand Down
7 changes: 5 additions & 2 deletions scroll-gateway/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ interface Env {
L2_ROLLUP: string;
GATEWAY_DOMAIN: string;
ENDPOINT_URL: string;
SEARCH_URL: string;
}

let app: Router;

async function fetch(request: CFWRequest, env: Env) {
const { L2_PROVIDER_URL, GATEWAY_DOMAIN, ENDPOINT_URL } = env;
const { L2_PROVIDER_URL, GATEWAY_DOMAIN, ENDPOINT_URL, SEARCH_URL } = env;

// Loading libraries dynamically as a temp work around.
// Otherwise, deployment thorws "Error: Script startup exceeded CPU time limit." error
Expand All @@ -31,7 +32,9 @@ async function fetch(request: CFWRequest, env: Env) {
.ScrollProofService;
const l2Provider = new ethers.JsonRpcProvider(L2_PROVIDER_URL);

const gateway = new EVMGateway(new ScrollProofService(l2Provider));
const gateway = new EVMGateway(
new ScrollProofService(SEARCH_URL, l2Provider)
);

const server = new Server();
gateway.add(server);
Expand Down

0 comments on commit 21709e4

Please sign in to comment.