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

Merged
merged 15 commits into from
Jan 7, 2025
Merged
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
8 changes: 1 addition & 7 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@ DB_NAME=postgres
DB_PASS=postgres
DB_PORT=5432
DB_USERNAME=postgres
DB_HOST=db
SHARED_CONFIG_URL="https://ipfs.io/ipfs/bafkreiasnla2ya55of6nwm3swjstip4q2ixfa3t6tvixyibclfovxnerte"
1_METADATA='{"id": 1, "rpcUrl": "http://evm1:8545"}'
2_METADATA='{"id": 2, "rpcUrl": "http://evm2:8545"}'
3_METADATA='{"id": 3, "rpcUrl": "ws://substrate-pallet:9944"}'

ENV_DOMAINS='[1,2,3]'
DB_HOST=db

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

5 changes: 0 additions & 5 deletions envs/.env.api

This file was deleted.

13 changes: 0 additions & 13 deletions envs/.env.evm-1

This file was deleted.

13 changes: 0 additions & 13 deletions envs/.env.evm-2

This file was deleted.

6 changes: 3 additions & 3 deletions envs/.env.indexer.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ DB_PORT=5432
DB_USERNAME=postgres
DB_HOST=db
SHARED_CONFIG_URL="https://ipfs.io/ipfs/bafkreiasnla2ya55of6nwm3swjstip4q2ixfa3t6tvixyibclfovxnerte"
1_METADATA='{"id": 1, "rpcUrl": "http://evm1:8545"}'
2_METADATA='{"id": 2, "rpcUrl": "http://evm2:8545"}'
3_METADATA='{"id": 3, "rpcUrl": "ws://substrate-pallet:9944"}'
1_METADATA='{"id": 1, "rpcUrl": "http://evm1:8545", "iconUrl": "https://example.com/icon1.png", "explorerUrl": "https://explorer.com/1"}'
2_METADATA='{"id": 2, "rpcUrl": "http://evm2:8545", "iconUrl": "https://example.com/icon2.png", "explorerUrl": "https://explorer.com/2"}'
3_METADATA='{"id": 3, "rpcUrl": "ws://substrate-pallet:9944", "iconUrl": "https://example.com/icon3.png", "explorerUrl": "https://explorer.com/3"}'

ENV_DOMAINS='[1,2,3]'
13 changes: 0 additions & 13 deletions envs/.env.substrate

This file was deleted.

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
2 changes: 2 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
2 changes: 1 addition & 1 deletion src/indexer/evmIndexer/evmProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class EVMProcessor implements IProcessor {

for (const block of ctx.blocks) {
this.logger.info(
`Processing block ${block.header.height} on networ ${domain.name}(${domain.id})`,
`Processing block ${block.header.height} on network ${domain.name}(${domain.id})`,
);
for (const log of block.logs) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/indexer/substrateIndexer/substrateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class SubstrateParser implements ISubstrateParser {
});
if (!resource) {
throw new NotFoundError(
`Unssupported resource with ID ${event.resourceId}`,
`Unsupported resource with ID ${event.resourceId}`,
);
}

Expand Down Expand Up @@ -218,7 +218,7 @@ export class SubstrateParser implements ISubstrateParser {
});
if (!resource) {
throw new NotFoundError(
`Unssupported resource with ID ${event.resourceId}`,
`Unsupported resource with ID ${event.resourceId}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/indexer/substrateIndexer/substrateProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class SubstrateProcessor implements IProcessor {
const fees: FeeCollectedData[] = [];
for (const block of ctx.blocks) {
this.logger.info(
`processing bloc ${block.header.height} on networ ${domain.name}(${domain.id})`,
`Processing block ${block.header.height} on network ${domain.name}(${domain.id})`,
);
for (const event of block.events) {
try {
Expand Down
18 changes: 15 additions & 3 deletions src/main_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { EntityManager } from "typeorm";

import type { Domain as DomainConfig } from "./indexer/config";
import { fetchSharedConfig } from "./indexer/config";
import { getEnv } from "./indexer/config/envLoader";
import { getDomainMetadata, getEnv } from "./indexer/config/envLoader";
import { Domain, Resource, Token } from "./model";
import { initDatabase } from "./utils";

Expand All @@ -18,21 +18,33 @@ export async function init(): 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.envDomains,
);
await dataSource.destroy();
}

async function insertDomains(
domains: Array<DomainConfig>,
manager: EntityManager,
supportedDomainsIDs: number[],
): Promise<void> {
for (const domain of domains) {
for (const domainID of supportedDomainsIDs) {
const domain = domains.find((domain) => domain.id == domainID);
if (!domain) {
throw new Error(`domain with id ${domainID} not found in shared-config`);
}
const domainMetadata = getDomainMetadata(domain.id.toString());
await manager.upsert(
Domain,
{
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: false})
iconURL!: string

@StringColumn_({nullable: false})
explorerURL!: string

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

Expand Down
Loading