Skip to content

Commit

Permalink
Update Rooch chainId to handle multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
xlassix committed Oct 18, 2024
1 parent 91d04d0 commit 0677e68
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 146 deletions.
18 changes: 12 additions & 6 deletions orchestrator/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { addressValidator, isRequiredWhenChainsInclude, privateKeyValidator } fr
const baseConfig = {
chains: (process.env.CHAINS ? process.env.CHAINS.split(",") : ChainList) as SupportedChain[],
// Rooch
roochChainId: process.env.ROOCH_CHAIN_ID,
roochChainId: (process.env.ROOCH_CHAIN_ID
? process.env.ROOCH_CHAIN_ID.split(",")
: ["testnet", "pre-mainnet"]) as RoochNetwork[],
roochPrivateKey: process.env.ROOCH_PRIVATE_KEY ?? "",
roochOracleAddress: process.env.ROOCH_ORACLE_ADDRESS ?? "",
roochIndexerCron: process.env.ROOCH_INDEXER_CRON,
Expand All @@ -27,7 +29,7 @@ const baseConfig = {

interface IEnvVars {
chains: SupportedChain[];
roochChainId: RoochNetwork;
roochChainId: RoochNetwork[];
roochOracleAddress: string;
roochPrivateKey: string;
roochIndexerCron: string;
Expand All @@ -52,10 +54,14 @@ const envVarsSchema = Joi.object({
.insensitive(),
)
.default(ChainList),
roochChainId: Joi.string()
.valid(...RoochNetworkList)
.insensitive()
.default(RoochNetworkList[0]),
roochChainId: Joi.array()
.items(
Joi.string()
.valid(...RoochNetworkList)
.insensitive()
.default(RoochNetworkList[0]),
)
.default([RoochNetworkList[0]]),
roochOracleAddress: isRequiredWhenChainsInclude(
Joi.string().custom((value, helper) => addressValidator(value, helper)),
SupportedChain.ROOCH,
Expand Down
23 changes: 13 additions & 10 deletions orchestrator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ import { log } from "./logger";
await xInstance.requestAccessToken();
}

if (env.rooch.privateKey && env.rooch.chainId && env.rooch.oracleAddress && env.chains.includes("ROOCH")) {
if (env.rooch.privateKey && env.rooch.chainId.length > 0 && env.rooch.oracleAddress && env.chains.includes("ROOCH")) {
// https://www.npmjs.com/package/cron#cronjob-class
const rooch = new RoochIndexer(env.rooch.privateKey, env.rooch.chainId, env.rooch.oracleAddress);
new CronJob(
env.rooch.indexerCron,
() => {
rooch.run();
},
null,
true,
);

env.rooch.chainId.map((chain) => {
const rooch = new RoochIndexer(env.rooch.privateKey, chain, env.rooch.oracleAddress);
new CronJob(
env.rooch.indexerCron,
() => {
rooch.run();
},
null,
true,
);
});
} else {
log.info(`Skipping Rooch Indexer initialization...`);
}
Expand Down
8 changes: 6 additions & 2 deletions orchestrator/src/indexer/rooch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default class RoochIndexer extends Indexer {
return `ROOCH-${this.chainId}`;
}

getRoochNodeUrl() {
return this.chainId === "pre-mainnet" ? "https://main-seed.rooch.network" : getRoochNodeUrl(this.chainId);
}

/**
* Fetches a list of RequestAdded events based on the provided cursor.
*
Expand All @@ -40,7 +44,7 @@ export default class RoochIndexer extends Indexer {
async fetchRequestAddedEvents(cursor: null | number | string = null): Promise<ProcessedRequestAdded<any>[]> {
try {
const response = await axios.post(
getRoochNodeUrl(this.chainId),
this.getRoochNodeUrl(),
{
id: 101,
jsonrpc: "2.0",
Expand Down Expand Up @@ -100,7 +104,7 @@ export default class RoochIndexer extends Indexer {
*/
async sendFulfillment(data: ProcessedRequestAdded<any>, status: number, result: string) {
const client = new RoochClient({
url: getRoochNodeUrl(this.chainId),
url: this.getRoochNodeUrl(),
});
log.debug({ notify: data.notify });

Expand Down
2 changes: 1 addition & 1 deletion orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type RoochEnv = {
};
export const ALLOWED_HOST = ["x.com", "api.x.com", "twitter.com", "api.twitter.com"];

export const RoochNetworkList = ["testnet", "devnet", "localnet"] as const;
export const RoochNetworkList = ["testnet", "devnet", "localnet", "pre-mainnet"] as const;

export const AptosNetworkList = ["testnet", "mainnet"] as const;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"dependencies": {
"@aptos-labs/ts-sdk": "^1.29.1",
"@prisma/client": "5.19.1",
"@roochnetwork/rooch-sdk": "^0.2.3",
"@roochnetwork/rooch-sdk": "^0.2.7",
"@sentry/node": "^8.26.0",
"@sentry/profiling-node": "^8.26.0",
"axios": "^1.7.4",
Expand Down
Loading

0 comments on commit 0677e68

Please sign in to comment.