Skip to content

Commit

Permalink
manifest api enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
hazelnutcloud committed Apr 5, 2023
1 parent db7fed6 commit 446da0d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ command
)
.option("-r, --rpc-url <rpcUrl:string>", "RPC URL", {
collect: true,
required: true,
})
.option("--no-gql", "Disable GraphQL server")
.action(start.action);
Expand Down
4 changes: 2 additions & 2 deletions cli/start/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -56,7 +56,7 @@ export const action = async (
const [name, url] = rpc.split("=");
acc[name] = url;
return acc;
}, {} as Record<string, string>);
}, {} as Record<string, string>) ?? {};

const arkiver = new Arkiver({
manifest,
Expand Down
4 changes: 2 additions & 2 deletions src/arkiver/arkiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 14 additions & 3 deletions src/arkiver/manifest-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { supportedChains } from "../chains.ts";
import {
ArkiveManifest,
BlockHandler,
ChainOptions,
Contract,
DataSource,
EventHandler,
Expand All @@ -14,6 +15,7 @@ import {
ExtractAbiEventNames,
mongoose,
} from "../deps.ts";
import { getChainObjFromChainName } from "../utils.ts";

export class Manifest {
public manifest: ArkiveManifest;
Expand Down Expand Up @@ -41,8 +43,9 @@ export class Manifest {

public addChain(
chain: keyof typeof supportedChains,
options?: Partial<ChainOptions>,
) {
return new DataSourceBuilder(this, chain);
return new DataSourceBuilder(this, chain, options);
}

public addEntity(entity: mongoose.Model<any>) {
Expand All @@ -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<ChainOptions> = {},
) {
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<const TAbi extends Abi>(
Expand Down
11 changes: 7 additions & 4 deletions src/arkiver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export interface IBlockHandler {
blockInterval: bigint;
}

export interface ChainOptions {
blockRange: bigint;
rpcUrl: string;
}

export interface ArkiveManifest {
dataSources: Partial<
Record<keyof typeof supportedChains, {
contracts?: Contract[];
blockHandlers?: IBlockHandler[];
}>
Record<keyof typeof supportedChains, DataSource>
>;
// deno-lint-ignore no-explicit-any
entities: { model: mongoose.Model<any>; list: boolean }[];
Expand All @@ -54,6 +56,7 @@ export interface ArkiveManifest {
export type DataSource = {
contracts?: Contract[];
blockHandlers?: IBlockHandler[];
options: ChainOptions;
};

export interface Contract {
Expand Down

1 comment on commit 446da0d

@vercel
Copy link

@vercel vercel bot commented on 446da0d Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.