Skip to content

Commit 84d3115

Browse files
authored
Merge pull request #13 from RoboVault/feat/custom-chain
Feat/custom chain
2 parents 894cb93 + cf4250e commit 84d3115

File tree

14 files changed

+480
-431
lines changed

14 files changed

+480
-431
lines changed

.github/workflows/format.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ jobs:
99
runs-on: ubuntu-22.04
1010
steps:
1111
- uses: actions/checkout@v3
12-
- uses: denoland/setup-deno@v1.1.1
12+
- uses: denoland/setup-deno@v1.1.2
1313
with:
1414
deno-version: v1.x
15+
- run: deno --version
1516
- run: deno fmt
16-
- name: Commit changes
17-
uses: stefanzweifel/git-auto-commit-action@v4
18-
with:
19-
commit_message: Apply formatting changes
20-
branch: ${{ github.head_ref }}

cli/start/mod.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {
22
ArkiveConsoleLogHandler,
3+
ArkiveManifest,
34
Arkiver,
45
buildSchemaFromEntities,
56
defaultArkiveData,
67
} from '../../mod.ts'
78
import { $, createYoga, delay, join, log, logLevel, serve } from '../deps.ts'
89
import { ArkiverMetadata } from '../../src/arkiver/arkive-metadata.ts'
910
import { createManifestHandlers } from './logger.ts'
10-
import { colors } from '../../src/deps.ts'
11+
import { colors, SchemaComposer } from '../../src/deps.ts'
1112

1213

1314
export const action = async (
@@ -67,7 +68,8 @@ export const action = async (
6768

6869
const manifestImport = await import(dir)
6970

70-
const manifest = manifestImport.default ?? manifestImport.manifest
71+
const manifest: ArkiveManifest | undefined = manifestImport.default ??
72+
manifestImport.manifest
7173

7274
if (!manifest) {
7375
throw new Error(
@@ -129,10 +131,19 @@ export const action = async (
129131
return
130132
}
131133

132-
const schema = buildSchemaFromEntities(
134+
const schemaComposer = new SchemaComposer()
135+
136+
buildSchemaFromEntities(
137+
schemaComposer,
133138
[...manifest.entities, { model: ArkiverMetadata, list: true }],
134139
)
135140

141+
if (manifest.schemaComposerCustomizer) {
142+
manifest.schemaComposerCustomizer(schemaComposer)
143+
}
144+
145+
const schema = schemaComposer.buildSchema()
146+
136147
const yoga = createYoga({
137148
schema,
138149
fetchAPI: {

mod.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
export type {
2-
ArkiveManifest,
3-
BlockHandler,
4-
EventHandlerFor,
2+
ArkiveManifest,
3+
BlockHandler,
4+
EventHandlerFor,
55
} from './src/arkiver/types.ts'
6-
export { Manifest } from './src/arkiver/manifest-builder.ts'
6+
export { Manifest } from './src/arkiver/manifest-builder/mod.ts'
77
export { ArkiveConsoleLogHandler } from './src/logger.ts'
88
export { Store } from './src/arkiver/store.ts'
99
export { Arkiver } from './src/arkiver/arkiver.ts'
1010
export { createEntity } from './src/graphql/entity.ts'
11-
export { Types } from './src/deps.ts'
11+
export { GraphQLError, Types } from './src/deps.ts'
1212
export { buildSchemaFromEntities } from './src/graphql/builder.ts'
1313
export { supportedChains } from './src/chains.ts'
1414
export {
15-
defaultArkiveData,
16-
JSONBigIntReplacer,
17-
JSONBigIntReviver,
15+
defaultArkiveData,
16+
JSONBigIntReplacer,
17+
JSONBigIntReviver,
1818
} from './src/utils.ts'
1919
export { parseArkiveManifest } from './src/arkiver/manifest-validator.ts'
2020
export { ArkiveLib, type SourceInfo } from './src/lib/ArkiveLib.ts'

src/arkiver/arkiver.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Arkive, ArkiveManifest } from './types.ts'
22
import { DataSource } from './data-source.ts'
33
import { mongoose } from '../deps.ts'
4-
import { assertChain, defaultArkiveData } from '../utils.ts'
4+
import { defaultArkiveData } from '../utils.ts'
55
import { logger } from '../logger.ts'
66

77
export class Arkiver extends EventTarget {
@@ -41,6 +41,10 @@ export class Arkiver extends EventTarget {
4141
logger('arkiver').debug(`Connected to database`)
4242
}
4343
await this.initSources()
44+
console.log(
45+
`Arkive manifest: `,
46+
this.manifest,
47+
)
4448
} catch (e) {
4549
logger('arkiver').error(`Error running arkiver: ${e}`)
4650
}
@@ -50,19 +54,21 @@ export class Arkiver extends EventTarget {
5054
logger('arkiver').debug(`Initializing data sources...`)
5155
const { dataSources } = this.manifest
5256
for (const [chain, source] of Object.entries(dataSources)) {
53-
try {
54-
assertChain(chain)
55-
} catch (_e) {
56-
logger('arkiver').error(
57-
`Invalid chain ${chain} in manifest, ignoring...`,
58-
)
57+
if (source === undefined) {
58+
// this should never happen but just in case
59+
logger('arkiver').error(`No data source found for chain ${chain}`)
5960
continue
6061
}
62+
// priority for rpcUrl is (highest to lowest):
63+
// 1. rpcUrl passed into Arkiver constructor (cli args in local mode)
64+
// 2. rpcUrl passed specified while building manifest
65+
// 3. default rpcUrl for chain from viem's chain configs
6166
const rpcUrl = this.rpcUrls[chain] ?? source.options.rpcUrl
6267
if (rpcUrl === undefined) {
6368
logger('arkiver').error(`No RPC URL found for chain ${chain}`)
6469
continue
6570
}
71+
source.options.rpcUrl = rpcUrl
6672
const dataSource = new DataSource({
6773
arkiveId: this.arkiveData.id,
6874
arkiveVersion: this.arkiveData.deployment.major_version,

src/arkiver/data-source.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from '../utils.ts'
3131
import { Store } from './store.ts'
3232
import { MongoStatusProvider } from './providers/mongodb.ts'
33-
import { supportedChains } from '../chains.ts'
33+
import { Chains } from './manifest-builder/manifest.ts'
3434

3535
interface NormalizedContracts {
3636
contracts: {
@@ -41,7 +41,7 @@ interface NormalizedContracts {
4141
}
4242

4343
export class DataSource extends EventTarget {
44-
private readonly chain: keyof typeof supportedChains
44+
private readonly chain: Chains
4545
private readonly rpcUrl: string
4646
private readonly client: PublicClient<HttpTransport>
4747
private readonly blockRange: bigint
@@ -115,7 +115,7 @@ export class DataSource extends EventTarget {
115115
constructor(
116116
params: {
117117
contracts: Contract[]
118-
chain: keyof typeof supportedChains
118+
chain: Chains
119119
rpcUrl: string
120120
blockRange: bigint
121121
arkiveId: number

0 commit comments

Comments
 (0)