diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6ba4f..dd60c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v0.3.4 - Signing up now requires a username - Fixed a bug where the `arkiver start` command would not start the GraphQL server if no `-c` flag was passed +- Add options parameter to `Manifest`'s `addChain` method. This allows you to specify the chain's querying blockrange and the chain's RPC URL. +- Add rpcUrl field to `ChainOptions`. You can now omit passing in `--rpc-url` to the `arkiver start` command and instead pass in the RPC URL in the `addChain` method. If no RPC URL is passed in, the default public RPC URL for the chain will be used. # v0.3.3 - Re-add automatic mongodb spin up on `arkiver start` command diff --git a/cli.ts b/cli.ts index 1ec7fe2..d6c802f 100644 --- a/cli.ts +++ b/cli.ts @@ -60,7 +60,6 @@ command ) .option("-r, --rpc-url ", "RPC URL", { collect: true, - required: true, }) .option("--no-gql", "Disable GraphQL server") .action(start.action); diff --git a/cli/start/mod.ts b/cli/start/mod.ts index 2a43608..98d5488 100644 --- a/cli/start/mod.ts +++ b/cli/start/mod.ts @@ -6,7 +6,7 @@ import { ArkiverMetadata } from "../../src/arkiver/arkive-metadata.ts"; export const action = async ( options: { manifest?: string; - rpcUrl: string[]; + rpcUrl?: string[]; mongoConnection?: string; gql: boolean; }, @@ -56,7 +56,7 @@ export const action = async ( const [name, url] = rpc.split("="); acc[name] = url; return acc; - }, {} as Record); + }, {} as Record) ?? {}; const arkiver = new Arkiver({ manifest, diff --git a/src/arkiver/arkiver.ts b/src/arkiver/arkiver.ts index 3ebea5f..4c4c317 100644 --- a/src/arkiver/arkiver.ts +++ b/src/arkiver/arkiver.ts @@ -78,10 +78,10 @@ export class Arkiver extends EventTarget { const dataSource = new DataSource({ arkiveId: this.arkiveData.id, arkiveVersion: this.arkiveData.deployment.major_version, - blockRange: 3000n, + blockRange: source.options.blockRange, chain, contracts: source.contracts ?? [], - rpcUrl: this.rpcUrls[chain], + rpcUrl: this.rpcUrls[chain] ?? source.options.rpcUrl, blockSources: source.blockHandlers ?? [], }); await dataSource.run(); diff --git a/src/arkiver/manifest-builder.ts b/src/arkiver/manifest-builder.ts index b6d60dd..892d4eb 100644 --- a/src/arkiver/manifest-builder.ts +++ b/src/arkiver/manifest-builder.ts @@ -3,6 +3,7 @@ import { supportedChains } from "../chains.ts"; import { ArkiveManifest, BlockHandler, + ChainOptions, Contract, DataSource, EventHandler, @@ -14,6 +15,7 @@ import { ExtractAbiEventNames, mongoose, } from "../deps.ts"; +import { getChainObjFromChainName } from "../utils.ts"; export class Manifest { public manifest: ArkiveManifest; @@ -41,8 +43,9 @@ export class Manifest { public addChain( chain: keyof typeof supportedChains, + options?: Partial, ) { - return new DataSourceBuilder(this, chain); + return new DataSourceBuilder(this, chain, options); } public addEntity(entity: mongoose.Model) { @@ -64,16 +67,24 @@ export class Manifest { } export class DataSourceBuilder { - public dataSource: DataSource = {}; + public dataSource: DataSource; constructor( private builder: Manifest, chain: keyof typeof supportedChains, + options: Partial = {}, ) { if (this.builder.manifest.dataSources[chain] != undefined) { throw new Error(`Cannot add data source for ${chain} more than once.`); } - this.builder.manifest.dataSources[chain] = this.dataSource; + const dataSource: DataSource = { + options: { + blockRange: 3000n, + rpcUrl: getChainObjFromChainName(chain).rpcUrls.public.http[0], + ...options, + }, + }; + this.builder.manifest.dataSources[chain] = this.dataSource = dataSource; } public addContract( diff --git a/src/arkiver/types.ts b/src/arkiver/types.ts index 33357fd..c6a77f5 100644 --- a/src/arkiver/types.ts +++ b/src/arkiver/types.ts @@ -39,12 +39,14 @@ export interface IBlockHandler { blockInterval: bigint; } +export interface ChainOptions { + blockRange: bigint; + rpcUrl: string; +} + export interface ArkiveManifest { dataSources: Partial< - Record + Record >; // deno-lint-ignore no-explicit-any entities: { model: mongoose.Model; list: boolean }[]; @@ -54,6 +56,7 @@ export interface ArkiveManifest { export type DataSource = { contracts?: Contract[]; blockHandlers?: IBlockHandler[]; + options: ChainOptions; }; export interface Contract {