Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add domain metadata #32

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type Domain @entity {
id: ID!
type: String!
name: String!
iconURL: String
explorerURL: String
routesFrom: [Route!] @derivedFrom(field: "fromDomain")
routesTo: [Route!] @derivedFrom(field: "toDomain")
token: [Token!] @derivedFrom(field: "domain")
Expand Down
4 changes: 4 additions & 0 deletions src/indexer/config/envLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type DomainMetadata = {
domainId: number;
rpcUrl: string;
domainGateway?: string;
iconUrl?: string;
explorerUrl?: string;
};

export type EnvVariables = {
Expand Down Expand Up @@ -76,6 +78,8 @@ export function getEnv(): EnvVariables {
domainId: domainId,
domainGateway: parsedDomainMetadata.domainGateway,
rpcUrl: parsedDomainMetadata.rpcUrl,
iconUrl: parsedDomainMetadata.iconUrl,
explorerUrl: parsedDomainMetadata.explorerUrl,
},
dbConfig: {
host: dbHost,
Expand Down
10 changes: 9 additions & 1 deletion src/main_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { EntityManager } from "typeorm";

import type { Domain as DomainConfig } from "./indexer/config";
import { fetchSharedConfig } from "./indexer/config";
import type { DomainMetadata } from "./indexer/config/envLoader";
import { getEnv } from "./indexer/config/envLoader";
import { Domain, Resource, Token } from "./model";
import { initDatabase } from "./utils";
Expand All @@ -19,13 +20,18 @@ async function main(): Promise<void> {
const dataSource = await initDatabase(envVars.dbConfig);
const sharedConfig = await fetchSharedConfig(envVars.sharedConfigURL);

await insertDomains(sharedConfig.domains, dataSource.manager);
await insertDomains(
sharedConfig.domains,
dataSource.manager,
envVars.domainMetadata,
);
await dataSource.destroy();
}

async function insertDomains(
domains: Array<DomainConfig>,
manager: EntityManager,
domainMetadata: DomainMetadata,
): Promise<void> {
for (const domain of domains) {
await manager.upsert(
Expand All @@ -34,6 +40,8 @@ async function insertDomains(
id: domain.id.toString(),
type: domain.type,
name: domain.name,
iconURL: domainMetadata.iconUrl ?? "",
explorerURL: domainMetadata.explorerUrl ?? "",
},
["id"],
);
Expand Down
6 changes: 6 additions & 0 deletions src/model/generated/domain.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export class Domain {
@StringColumn_({nullable: false})
name!: string

@StringColumn_({nullable: true})
iconURL!: string | undefined | null

@StringColumn_({nullable: true})
explorerURL!: string | undefined | null

@OneToMany_(() => Route, e => e.fromDomain)
routesFrom!: Route[]

Expand Down
Loading