Skip to content

Commit b258f6f

Browse files
Merge pull request #1 from rsksmart/feat/add-rootstock
Add Rootstock
2 parents 6797b01 + f9aaa96 commit b258f6f

File tree

6 files changed

+108
-17
lines changed

6 files changed

+108
-17
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ INFURA_IPFS_PASS=
55
ALCHEMY_ARBITRUM_API_KEY=
66
ALCHEMY_SEPOLIA_API_KEY=
77
ALCHEMY_OPTIMISM_GOERLI_API_KEY=
8+
ROOTSTOCK_TESTNET_API_KEY=
9+
ROOTSTOCK_API_KEY=
810
#POLLING_INTERVAL=60000
911
#DISABLE_LISTENER=true
1012
#REQUEST_DELAY=500 # How many ms to wait before making a request to RPC (useful for free plans)

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ENV INFURA_API_KEY=${INFURA_API_KEY}
77
ENV ALCHEMY_ARBITRUM_API_KEY=${ALCHEMY_ARBITRUM_API_KEY}
88
ENV ALCHEMY_SEPOLIA_API_KEY=${ALCHEMY_SEPOLIA_API_KEY}
99
ENV ALCHEMY_OPTIMISM_GOERLI_API_KEY=${ALCHEMY_OPTIMISM_GOERLI_API_KEY}
10+
ENV ROOTSTOCK_TESTNET_API_KEY=${ROOTSTOCK_TESTNET_API_KEY}
11+
ENV ROOTSTOCK_API_KEY=${ROOTSTOCK_API_KEY}
1012
ENV CHAIN_ID=${CHAIN_ID}
1113

1214
COPY . .

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ INFURA_IPFS_PASS=
2121
ALCHEMY_ARBITRUM_API_KEY=
2222
ALCHEMY_SEPOLIA_API_KEY=
2323
ALCHEMY_OPTIMISM_GOERLI_API_KEY=
24+
ROOTSTOCK_TESTNET_API_KEY=
25+
ROOTSTOCK_API_KEY=
2426
#POLLING_INTERVAL=60000
2527
#DISABLE_LISTENER=true
2628
#REQUEST_DELAY=500 # How many ms to wait before making a request to RPC (useful for free plans)

graph.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import {
44
applyResolversEnhanceMap,
55
ResolversEnhanceMap,
66
} from "@generated/type-graphql";
7-
import { AuthChecker, Authorized, buildSchema } from "type-graphql";
7+
import {
8+
AuthChecker,
9+
Authorized,
10+
buildSchema,
11+
UseMiddleware,
12+
} from "type-graphql";
813
import { ApolloServer } from "apollo-server";
914
import { prisma } from "./db.server";
1015

@@ -14,7 +19,20 @@ export async function startGraph() {
1419
const resolversEnhanceMap: ResolversEnhanceMap = {
1520
Attestation: {
1621
attestation: [Authorized()],
17-
attestations: [Authorized()],
22+
attestations: [
23+
Authorized(),
24+
UseMiddleware(async (action, next) => {
25+
// Get the current args
26+
const args = action.args as any;
27+
28+
if (!args.take) {
29+
args.take = 100;
30+
}
31+
32+
// Call the next middleware or resolver
33+
return next();
34+
}),
35+
],
1836
findFirstAttestation: [Authorized()],
1937
aggregateAttestation: [Authorized()],
2038
createOneAttestation: [Authorized(["ADMIN"])],

scripts/updateForTxId.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,33 @@ import { updateDbFromEthTransaction } from "../utils";
66
const input = process.argv[2];
77

88
if (!input) {
9-
console.error("Please provide a transaction id or a comma-separated list of transaction ids");
9+
console.error(
10+
"Please provide a transaction id or a comma-separated list of transaction ids"
11+
);
1012
process.exit(1);
1113
}
1214

13-
const txids = input.split(',').map(txid => txid.trim());
15+
const txids = input.split(",").map((txid) => txid.trim());
1416

15-
Promise.all(txids.map(updateDbFromEthTransaction))
17+
async function processSequentially() {
18+
for (const txid of txids) {
19+
try {
20+
await updateDbFromEthTransaction(txid);
21+
console.log(`Successfully processed transaction: ${txid}`);
22+
} catch (error) {
23+
console.error(`Error processing transaction ${txid}:`, error);
24+
25+
process.exit(1);
26+
}
27+
}
28+
}
29+
30+
processSequentially()
1631
.then(() => {
17-
console.log("Success");
32+
console.log("All transactions processed");
1833
process.exit(0);
1934
})
2035
.catch((e) => {
21-
console.error("Error", e);
36+
console.error("Unexpected error:", e);
2237
process.exit(1);
23-
});
38+
});

utils.ts

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const requestDelay = process.env.REQUEST_DELAY
1717

1818
const limit = pLimit(5);
1919

20+
// Add a constant for maximum retries
21+
const MAX_RETRIES = 5;
22+
2023
export type EASChainConfig = {
2124
chainId: number;
2225
chainName: string;
@@ -158,16 +161,27 @@ export const EAS_CHAIN_CONFIGS: EASChainConfig[] = [
158161
etherscanURL: "https://lineascan.build/",
159162
rpcProvider: `https://linea-mainnet.infura.io/v3/${process.env.INFURA_LINEA_API_KEY}`,
160163
},
164+
// {
165+
// chainId: 80001,
166+
// chainName: "polygon-mumbai",
167+
// subdomain: "polygon-mumbai.",
168+
// version: "1.2.0",
169+
// contractAddress: "0xaEF4103A04090071165F78D45D83A0C0782c2B2a",
170+
// schemaRegistryAddress: "0x55D26f9ae0203EF95494AE4C170eD35f4Cf77797",
171+
// contractStartBlock: 41442300,
172+
// etherscanURL: "https://mumbai.polygonscan.com/",
173+
// rpcProvider: `https://polygon-mumbai.infura.io/v3/${process.env.INFURA_API_KEY}`,
174+
// },
161175
{
162-
chainId: 80001,
163-
chainName: "polygon-mumbai",
164-
subdomain: "polygon-mumbai.",
165-
version: "1.2.0",
166-
contractAddress: "0xaEF4103A04090071165F78D45D83A0C0782c2B2a",
167-
schemaRegistryAddress: "0x55D26f9ae0203EF95494AE4C170eD35f4Cf77797",
168-
contractStartBlock: 41442300,
169-
etherscanURL: "https://mumbai.polygonscan.com/",
170-
rpcProvider: `https://polygon-mumbai.infura.io/v3/${process.env.INFURA_API_KEY}`,
176+
chainId: 80002,
177+
chainName: "polygon-amoy",
178+
subdomain: "polygon-amoy.",
179+
version: "1.3.0",
180+
contractAddress: "0xb101275a60d8bfb14529C421899aD7CA1Ae5B5Fc",
181+
schemaRegistryAddress: "0x23c5701A1BDa89C61d181BD79E5203c730708AE7",
182+
contractStartBlock: 7372405,
183+
etherscanURL: "https://amoy.polygonscan.com/",
184+
rpcProvider: `https://restless-palpable-mountain.matic-amoy.quiknode.pro/${process.env.QUICKNODE_POLYGON_AMOY_API_KEY}/`,
171185
},
172186
{
173187
chainId: 137,
@@ -224,6 +238,28 @@ export const EAS_CHAIN_CONFIGS: EASChainConfig[] = [
224238
etherscanURL: "https://explorer.zksync.io",
225239
rpcProvider: `https://mainnet.era.zksync.io`,
226240
},
241+
{
242+
chainId: 31,
243+
chainName: "rootstock-testnet",
244+
subdomain: "rootstock-testnet.",
245+
version: "1.3.0",
246+
contractAddress: "0xc300aeEaDd60999933468738c9F5D7e9C0671e1c",
247+
schemaRegistryAddress: "0x679c62956cD2801AbAbF80e9D430f18859Eea2d5",
248+
contractStartBlock: 5457123,
249+
etherscanURL: "https://rootstock-testnet.blockscout.com/",
250+
rpcProvider: `https://rpc.testnet.rootstock.io/${process.env.ROOTSTOCK_TESTNET_API_KEY}`,
251+
},
252+
{
253+
chainId: 30,
254+
chainName: "rootstock",
255+
subdomain: "rootstock.",
256+
version: "1.3.0",
257+
contractAddress: "0x54C0726E9d2D57Bc37AD52c7E219A3229e0eE963",
258+
schemaRegistryAddress: "0xeF29675d82CC5967069d6d9C17F2719f67728F5B",
259+
contractStartBlock: 6635587,
260+
etherscanURL: "https://rootstock.blockscout.com/",
261+
rpcProvider: `https://rpc.mainnet.rootstock.io/${process.env.ROOTSTOCK_API_KEY}`,
262+
},
227263
];
228264

229265
const activeChainConfig = EAS_CHAIN_CONFIGS.find(
@@ -300,6 +336,13 @@ export async function getFormattedAttestationFromLog(
300336
let tries = 1;
301337

302338
do {
339+
if (tries > MAX_RETRIES) {
340+
console.log(
341+
`Max retries reached for log ${log.transactionHash}. Skipping...`
342+
);
343+
return null; // Exit the loop and return null after max retries
344+
}
345+
303346
[
304347
UID,
305348
schemaUID,
@@ -369,6 +412,13 @@ export async function getFormattedSchemaFromLog(
369412
let tries = 1;
370413

371414
do {
415+
if (tries > MAX_RETRIES) {
416+
console.log(
417+
`Max retries reached for schema log ${log.transactionHash}. Skipping...`
418+
);
419+
throw new Error("Max retries reached while fetching schema.");
420+
}
421+
372422
[UID, resolver, revocable, schema] = await schemaContract.getSchema(
373423
log.topics[1]
374424
);
@@ -471,6 +521,8 @@ export async function createAttestationsForLogs(logs: ethers.providers.Log[]) {
471521
await prisma.attestation.create({ data: attestation });
472522
await processCreatedAttestation(attestation);
473523
}
524+
} else {
525+
console.log("Skipped creating attestation due to max retries.");
474526
}
475527
}
476528
}

0 commit comments

Comments
 (0)