From 8c2e16bed4e757e622e2b9ec892ef480d68574e2 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Wed, 11 Dec 2024 10:59:05 +0100 Subject: [PATCH 01/14] chore: Add domain metadata --- envs/.env.init.example | 1 + schema.graphql | 2 + src/indexer/config/index.ts | 4 +- src/indexer/config/validator.ts | 101 +++++++++++++++++++++------- src/main.ts | 4 +- src/main_init.ts | 14 +++- src/model/generated/domain.model.ts | 6 ++ 7 files changed, 101 insertions(+), 31 deletions(-) diff --git a/envs/.env.init.example b/envs/.env.init.example index b74b4fc..431b0bb 100644 --- a/envs/.env.init.example +++ b/envs/.env.init.example @@ -8,3 +8,4 @@ DB_HOST=db START_SCRIPT_ENV=init SHARED_CONFIG_URL= +SYG_CHAINS='{"1": {"iconUrl": "https://example.com/icon1.png", "explorerUrl": "https://explorer.com/1"}, "2": {"iconUrl": "https://example.com/icon2.png", "explorerUrl": "https://explorer.com/2"}}' diff --git a/schema.graphql b/schema.graphql index 4540233..c2cb544 100644 --- a/schema.graphql +++ b/schema.graphql @@ -71,6 +71,8 @@ type Token @entity @index(fields: ["tokenAddress", "domainID"], unique: true) { type Domain @entity { id: ID! name: String! + iconUrl: String + explorerUrl: String transfersFrom: [Transfer!] @derivedFrom(field: "fromDomain") transfersTo: [Transfer!] @derivedFrom(field: "toDomain") token: [Token!] @derivedFrom(field: "domain") diff --git a/src/indexer/config/index.ts b/src/indexer/config/index.ts index 36d9a4a..77ceaaf 100644 --- a/src/indexer/config/index.ts +++ b/src/indexer/config/index.ts @@ -16,7 +16,7 @@ import type { IParser, IProcessor } from "../indexer"; import { SubstrateParser } from "../substrateIndexer/substrateParser"; import { createSubstrateProvider } from "../substrateIndexer/utils"; -import type { EnvVariables } from "./validator"; +import type { EnvIndexerVariables } from "./validator"; export type DomainConfig = { domainData: Domain; @@ -64,7 +64,7 @@ type Config = { rpcMap: Map; }; -export async function getConfig(envVars: EnvVariables): Promise { +export async function getConfig(envVars: EnvIndexerVariables): Promise { const sharedConfig = await fetchSharedConfig(envVars.sharedConfigURL); const rpcMap = createRpcMap(envVars.rpcUrls); const parserMap = await initializeParserMap(sharedConfig, rpcMap); diff --git a/src/indexer/config/validator.ts b/src/indexer/config/validator.ts index bf03307..deb6ff3 100644 --- a/src/indexer/config/validator.ts +++ b/src/indexer/config/validator.ts @@ -11,33 +11,39 @@ export type DbConfig = { password: string; }; -export type EnvVariables = { +export type DomainMetadata = { + [domainID: number]: { + iconUrl: string; + explorerUrl: string; + }; +}; + +type EnvVariables = { sharedConfigURL: string; - rpcUrls: string; - domainId: number; - domainGateway: string; dbConfig: DbConfig; +}; + +export type EnvInitVariables = { + sharedConfigURL: string; + dbConfig: DbConfig; + domainMetadata: DomainMetadata; logLevel: string; version: string; }; -export function getEnv(): EnvVariables { + +export type EnvIndexerVariables = { + sharedConfigURL: string; + rpcUrls: string; + domainId: number; + domainGateway: string; +}; + +function getEnv(): EnvVariables { const sharedConfigURL = process.env.SHARED_CONFIG_URL; if (!sharedConfigURL) { throw new Error(`SHARED_CONFIG_URL is not defined in the environment.`); } - const rpcUrls = process.env.RPC_URL; - if (!rpcUrls) { - throw new Error(`RPC_URL environment variable is not defined.`); - } - - const domainId = Number(process.env.DOMAIN_ID); - if (isNaN(domainId)) { - throw new Error(`DOMAIN_ID environment variable is invalid or not set.`); - } - - const domainGateway = process.env.DOMAIN_GATEWAY || ""; - const dbHost = process.env.DB_HOST; if (!dbHost) { throw new Error(`DB_HOST is not defined in the environment.`); @@ -63,14 +69,8 @@ export function getEnv(): EnvVariables { throw new Error(`DB_PASS is not defined in the environment.`); } - const logLevel = process.env.LOG_LEVEL || "debug"; - const version = process.env.VERSION || "unknown"; - return { - sharedConfigURL, - rpcUrls, - domainId, - domainGateway, + sharedConfigURL: sharedConfigURL, dbConfig: { host: dbHost, name: dbName, @@ -78,7 +78,60 @@ export function getEnv(): EnvVariables { username: dbUsername, password: dbPassword, }, + }; +} + +export function getInitEnv(): EnvInitVariables { + const coreEnvs = getEnv(); + + let domainMetadata: DomainMetadata; + if (process.env.SYG_CHAINS) { + try { + domainMetadata = JSON.parse(process.env.SYG_CHAINS) as DomainMetadata; + } catch (error) { + if (error instanceof Error) { + throw new Error(`SYG_CHAINS is not a valid JSON: ${error.message}`); + } else { + throw new Error( + `SYG_CHAINS is not a valid JSON: Unknown error occurred`, + ); + } + } + } else { + throw new Error(`SYG_CHAINS is not defined in the environment.`); + } + + const logLevel = process.env.LOG_LEVEL || "debug"; + const version = process.env.VERSION || "unknown"; + + return { + sharedConfigURL: coreEnvs.sharedConfigURL, + dbConfig: coreEnvs.dbConfig, + domainMetadata: domainMetadata, logLevel, version, }; } + +export function getIndexerEnv(): EnvIndexerVariables { + const coreEnvs = getEnv(); + + const rpcUrls = process.env.RPC_URL; + if (!rpcUrls) { + throw new Error(`RPC_URL environment variable is not defined.`); + } + + const domainId = Number(process.env.DOMAIN_ID); + if (isNaN(domainId)) { + throw new Error(`DOMAIN_ID environment variable is invalid or not set.`); + } + + const domainGateway = process.env.DOMAIN_GATEWAY || ""; + + return { + sharedConfigURL: coreEnvs.sharedConfigURL, + domainGateway: domainGateway, + domainId: domainId, + rpcUrls: rpcUrls, + }; +} diff --git a/src/main.ts b/src/main.ts index 395c354..d85bc02 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,7 +6,7 @@ SPDX-License-Identifier: LGPL-3.0-only import { Network } from "@buildwithsygma/core"; import { getConfig } from "./indexer/config"; -import { getEnv } from "./indexer/config/validator"; +import { getIndexerEnv } from "./indexer/config/validator"; import { EVMProcessor } from "./indexer/evmIndexer/evmProcessor"; import { Indexer } from "./indexer/indexer"; import type { ISubstrateParser } from "./indexer/substrateIndexer/substrateParser"; @@ -14,7 +14,7 @@ import { SubstrateProcessor } from "./indexer/substrateIndexer/substrateProcesso import { logger } from "./utils/logger"; async function startProcessing(): Promise { - const envVars = getEnv(); + const envVars = getIndexerEnv(); const config = await getConfig(envVars); let processor; switch (config.domain.type) { diff --git a/src/main_init.ts b/src/main_init.ts index 735e924..34565d0 100644 --- a/src/main_init.ts +++ b/src/main_init.ts @@ -7,7 +7,8 @@ import type { EntityManager } from "typeorm"; import type { Domain as DomainConfig } from "./indexer/config"; import { fetchSharedConfig } from "./indexer/config"; -import { getEnv } from "./indexer/config/validator"; +import type { DomainMetadata } from "./indexer/config/validator"; +import { getInitEnv } from "./indexer/config/validator"; import { Domain, Resource, Token } from "./model"; import { initDatabase } from "./utils"; import { logger } from "./utils/logger"; @@ -15,17 +16,22 @@ import { logger } from "./utils/logger"; const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000"; async function main(): Promise { - const envVars = getEnv(); + const envVars = getInitEnv(); 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, manager: EntityManager, + domainMetadata: DomainMetadata, ): Promise { for (const domain of domains) { await manager.upsert( @@ -33,6 +39,8 @@ async function insertDomains( { id: domain.id.toString(), name: domain.name, + iconUrl: domainMetadata[domain.id]?.iconUrl ?? "", + explorerUrl: domainMetadata[domain.id]?.explorerUrl ?? "", }, ["id"], ); diff --git a/src/model/generated/domain.model.ts b/src/model/generated/domain.model.ts index 75ac2bc..41ca2c4 100644 --- a/src/model/generated/domain.model.ts +++ b/src/model/generated/domain.model.ts @@ -18,6 +18,12 @@ export class Domain { @Column_("text", {nullable: false}) name!: string + @Column_("text", {nullable: true}) + iconUrl!: string | undefined | null + + @Column_("text", {nullable: true}) + explorerUrl!: string | undefined | null + @OneToMany_(() => Transfer, e => e.fromDomain) transfersFrom!: Transfer[] From 20279fde54af363f3fd93a5cc8e0cb963daf51a6 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Wed, 11 Dec 2024 11:02:07 +0100 Subject: [PATCH 02/14] Add migration --- .../{1733840019584-Data.js => 1733911296071-Data.js} | 6 +++--- schema.graphql | 4 ++-- src/main_init.ts | 4 ++-- src/model/generated/domain.model.ts | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename db/migrations/{1733840019584-Data.js => 1733911296071-Data.js} (97%) diff --git a/db/migrations/1733840019584-Data.js b/db/migrations/1733911296071-Data.js similarity index 97% rename from db/migrations/1733840019584-Data.js rename to db/migrations/1733911296071-Data.js index 96a8967..fa333d2 100644 --- a/db/migrations/1733840019584-Data.js +++ b/db/migrations/1733911296071-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1733840019584 { - name = 'Data1733840019584' +module.exports = class Data1733911296071 { + name = 'Data1733911296071' async up(db) { await db.query(`CREATE TABLE "resource" ("id" character varying NOT NULL, "type" text NOT NULL, CONSTRAINT "PK_e2894a5867e06ae2e8889f1173f" PRIMARY KEY ("id"))`) @@ -10,7 +10,7 @@ module.exports = class Data1733840019584 { await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) await db.query(`CREATE UNIQUE INDEX "IDX_ada3dfc11e70168668345b2951" ON "token" ("token_address", "domain_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "name" text NOT NULL, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "deposit" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "block_number" text NOT NULL, "deposit_data" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "handler_response" text NOT NULL, "destination" text, "account_id" character varying, CONSTRAINT "PK_6654b4be449dadfd9d03a324b61" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_9ced91570695137ec1d60c1a61" ON "deposit" ("account_id") `) diff --git a/schema.graphql b/schema.graphql index c2cb544..ae1c626 100644 --- a/schema.graphql +++ b/schema.graphql @@ -71,8 +71,8 @@ type Token @entity @index(fields: ["tokenAddress", "domainID"], unique: true) { type Domain @entity { id: ID! name: String! - iconUrl: String - explorerUrl: String + iconURL: String + explorerURL: String transfersFrom: [Transfer!] @derivedFrom(field: "fromDomain") transfersTo: [Transfer!] @derivedFrom(field: "toDomain") token: [Token!] @derivedFrom(field: "domain") diff --git a/src/main_init.ts b/src/main_init.ts index 34565d0..71313da 100644 --- a/src/main_init.ts +++ b/src/main_init.ts @@ -39,8 +39,8 @@ async function insertDomains( { id: domain.id.toString(), name: domain.name, - iconUrl: domainMetadata[domain.id]?.iconUrl ?? "", - explorerUrl: domainMetadata[domain.id]?.explorerUrl ?? "", + iconURL: domainMetadata[domain.id]?.iconUrl ?? "", + explorerURL: domainMetadata[domain.id]?.explorerUrl ?? "", }, ["id"], ); diff --git a/src/model/generated/domain.model.ts b/src/model/generated/domain.model.ts index 41ca2c4..fcda5a7 100644 --- a/src/model/generated/domain.model.ts +++ b/src/model/generated/domain.model.ts @@ -19,10 +19,10 @@ export class Domain { name!: string @Column_("text", {nullable: true}) - iconUrl!: string | undefined | null + iconURL!: string | undefined | null @Column_("text", {nullable: true}) - explorerUrl!: string | undefined | null + explorerURL!: string | undefined | null @OneToMany_(() => Transfer, e => e.fromDomain) transfersFrom!: Transfer[] From 0ee959fc447bd3303149e7481984e6cb4ea38eed Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 13 Dec 2024 11:34:26 +0100 Subject: [PATCH 03/14] Align with env refactor --- db/migrations/1734012304772-Data.js | 71 ------------------- ...11296071-Data.js => 1734085803528-Data.js} | 6 +- src/indexer/config/envLoader.ts | 4 ++ src/indexer/config/index.ts | 2 +- src/main.ts | 2 +- src/main_init.ts | 7 +- src/model/generated/domain.model.ts | 4 +- 7 files changed, 15 insertions(+), 81 deletions(-) delete mode 100644 db/migrations/1734012304772-Data.js rename db/migrations/{1733911296071-Data.js => 1734085803528-Data.js} (97%) diff --git a/db/migrations/1734012304772-Data.js b/db/migrations/1734012304772-Data.js deleted file mode 100644 index 222ea76..0000000 --- a/db/migrations/1734012304772-Data.js +++ /dev/null @@ -1,71 +0,0 @@ -module.exports = class Data1734012304772 { - name = 'Data1734012304772' - - async up(db) { - await db.query(`CREATE TABLE "resource" ("id" character varying NOT NULL, "type" text NOT NULL, CONSTRAINT "PK_e2894a5867e06ae2e8889f1173f" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "fee" ("id" character varying NOT NULL, "amount" text NOT NULL, "transfer_id" character varying, "token_id" uuid, CONSTRAINT "PK_ee7e51cc563615bc60c2b234635" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_119250e5caf62c90134b8e2f2d" ON "fee" ("transfer_id") `) - await db.query(`CREATE INDEX "IDX_bde4aa972635af552acf115242" ON "fee" ("token_id") `) - await db.query(`CREATE TABLE "token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "decimals" integer NOT NULL, "token_address" text NOT NULL, "token_symbol" text NOT NULL, "resource_id" character varying, "domain_id" character varying, CONSTRAINT "PK_82fae97f905930df5d62a702fc9" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) - await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_ada3dfc11e70168668345b2951" ON "token" ("token_address", "domain_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "deposit" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "block_number" text NOT NULL, "deposit_data" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "handler_response" text NOT NULL, "destination" text, "account_id" character varying, CONSTRAINT "PK_6654b4be449dadfd9d03a324b61" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_9ced91570695137ec1d60c1a61" ON "deposit" ("account_id") `) - await db.query(`CREATE TABLE "execution" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "block_number" text NOT NULL, "message" text, CONSTRAINT "PK_cc6684fedf29ec4c86db8448a2b" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "transfer" ("id" character varying NOT NULL, "status" character varying(8) NOT NULL, "deposit_nonce" text NOT NULL, "from_domain_id" character varying, "to_domain_id" character varying, "fee_id" character varying, "resource_id" character varying, "amount" text, "deposit_id" character varying, "execution_id" character varying, CONSTRAINT "REL_0832a6ad200eac838da26a9961" UNIQUE ("deposit_id"), CONSTRAINT "REL_4b62ae14edfb27605cd911db59" UNIQUE ("execution_id"), CONSTRAINT "REL_f6b9e9b86a1ce51c26cd08f596" UNIQUE ("fee_id"), CONSTRAINT "PK_fd9ddbdd49a17afcbe014401295" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_de485b5ed6e047f65e219eb9e9" ON "transfer" ("from_domain_id") `) - await db.query(`CREATE INDEX "IDX_2803ca6ca9e4443766093ff49b" ON "transfer" ("to_domain_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_0832a6ad200eac838da26a9961" ON "transfer" ("deposit_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_4b62ae14edfb27605cd911db59" ON "transfer" ("execution_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_f6b9e9b86a1ce51c26cd08f596" ON "transfer" ("fee_id") `) - await db.query(`CREATE INDEX "IDX_d508a1e7a2e0da07bd955f76d8" ON "transfer" ("resource_id") `) - await db.query(`ALTER TABLE "fee" ADD CONSTRAINT "FK_119250e5caf62c90134b8e2f2d3" FOREIGN KEY ("transfer_id") REFERENCES "transfer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "fee" ADD CONSTRAINT "FK_bde4aa972635af552acf1152420" FOREIGN KEY ("token_id") REFERENCES "token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "token" ADD CONSTRAINT "FK_435ef0917a04e91698042dff2bc" FOREIGN KEY ("resource_id") REFERENCES "resource"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "token" ADD CONSTRAINT "FK_3d565341b16e9c03d63e05eac83" FOREIGN KEY ("domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "deposit" ADD CONSTRAINT "FK_9ced91570695137ec1d60c1a61b" FOREIGN KEY ("account_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_de485b5ed6e047f65e219eb9e90" FOREIGN KEY ("from_domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_2803ca6ca9e4443766093ff49bf" FOREIGN KEY ("to_domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_0832a6ad200eac838da26a99615" FOREIGN KEY ("deposit_id") REFERENCES "deposit"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_4b62ae14edfb27605cd911db591" FOREIGN KEY ("execution_id") REFERENCES "execution"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a" FOREIGN KEY ("fee_id") REFERENCES "fee"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_d508a1e7a2e0da07bd955f76d81" FOREIGN KEY ("resource_id") REFERENCES "resource"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - } - - async down(db) { - await db.query(`DROP TABLE "resource"`) - await db.query(`DROP TABLE "fee"`) - await db.query(`DROP INDEX "public"."IDX_119250e5caf62c90134b8e2f2d"`) - await db.query(`DROP INDEX "public"."IDX_bde4aa972635af552acf115242"`) - await db.query(`DROP TABLE "token"`) - await db.query(`DROP INDEX "public"."IDX_435ef0917a04e91698042dff2b"`) - await db.query(`DROP INDEX "public"."IDX_3d565341b16e9c03d63e05eac8"`) - await db.query(`DROP INDEX "public"."IDX_ada3dfc11e70168668345b2951"`) - await db.query(`DROP TABLE "domain"`) - await db.query(`DROP TABLE "account"`) - await db.query(`DROP TABLE "deposit"`) - await db.query(`DROP INDEX "public"."IDX_9ced91570695137ec1d60c1a61"`) - await db.query(`DROP TABLE "execution"`) - await db.query(`DROP TABLE "transfer"`) - await db.query(`DROP INDEX "public"."IDX_de485b5ed6e047f65e219eb9e9"`) - await db.query(`DROP INDEX "public"."IDX_2803ca6ca9e4443766093ff49b"`) - await db.query(`DROP INDEX "public"."IDX_0832a6ad200eac838da26a9961"`) - await db.query(`DROP INDEX "public"."IDX_4b62ae14edfb27605cd911db59"`) - await db.query(`DROP INDEX "public"."IDX_f6b9e9b86a1ce51c26cd08f596"`) - await db.query(`DROP INDEX "public"."IDX_d508a1e7a2e0da07bd955f76d8"`) - await db.query(`ALTER TABLE "fee" DROP CONSTRAINT "FK_119250e5caf62c90134b8e2f2d3"`) - await db.query(`ALTER TABLE "fee" DROP CONSTRAINT "FK_bde4aa972635af552acf1152420"`) - await db.query(`ALTER TABLE "token" DROP CONSTRAINT "FK_435ef0917a04e91698042dff2bc"`) - await db.query(`ALTER TABLE "token" DROP CONSTRAINT "FK_3d565341b16e9c03d63e05eac83"`) - await db.query(`ALTER TABLE "deposit" DROP CONSTRAINT "FK_9ced91570695137ec1d60c1a61b"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_de485b5ed6e047f65e219eb9e90"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_2803ca6ca9e4443766093ff49bf"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_0832a6ad200eac838da26a99615"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_4b62ae14edfb27605cd911db591"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_d508a1e7a2e0da07bd955f76d81"`) - } -} diff --git a/db/migrations/1733911296071-Data.js b/db/migrations/1734085803528-Data.js similarity index 97% rename from db/migrations/1733911296071-Data.js rename to db/migrations/1734085803528-Data.js index fa333d2..a4c9560 100644 --- a/db/migrations/1733911296071-Data.js +++ b/db/migrations/1734085803528-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1733911296071 { - name = 'Data1733911296071' +module.exports = class Data1734085803528 { + name = 'Data1734085803528' async up(db) { await db.query(`CREATE TABLE "resource" ("id" character varying NOT NULL, "type" text NOT NULL, CONSTRAINT "PK_e2894a5867e06ae2e8889f1173f" PRIMARY KEY ("id"))`) @@ -10,7 +10,7 @@ module.exports = class Data1733911296071 { await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) await db.query(`CREATE UNIQUE INDEX "IDX_ada3dfc11e70168668345b2951" ON "token" ("token_address", "domain_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "deposit" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "block_number" text NOT NULL, "deposit_data" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "handler_response" text NOT NULL, "destination" text, "account_id" character varying, CONSTRAINT "PK_6654b4be449dadfd9d03a324b61" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_9ced91570695137ec1d60c1a61" ON "deposit" ("account_id") `) diff --git a/src/indexer/config/envLoader.ts b/src/indexer/config/envLoader.ts index 8d121a6..e2d6451 100644 --- a/src/indexer/config/envLoader.ts +++ b/src/indexer/config/envLoader.ts @@ -15,6 +15,8 @@ export type DomainMetadata = { domainId?: number; rpcUrl: string; domainGateway?: string; + iconUrl?: string; + explorerUrl?: string; }; export type EnvVariables = { @@ -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, diff --git a/src/indexer/config/index.ts b/src/indexer/config/index.ts index 93bf532..0750acb 100644 --- a/src/indexer/config/index.ts +++ b/src/indexer/config/index.ts @@ -58,7 +58,7 @@ type Config = { parser: IParser; }; -export async function getConfig(envVars: EnvIndexerVariables): Promise { +export async function getConfig(envVars: EnvVariables): Promise { const sharedConfig = await fetchSharedConfig(envVars.sharedConfigURL); const domainConfig = getDomainConfig( diff --git a/src/main.ts b/src/main.ts index 900db19..2bb2ecd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,7 +14,7 @@ import { SubstrateProcessor } from "./indexer/substrateIndexer/substrateProcesso import { logger } from "./utils/logger"; async function startProcessing(): Promise { - const envVars = getIndexerEnv(); + const envVars = getEnv(); const config = await getConfig(envVars); let processor; switch (config.domain.type) { diff --git a/src/main_init.ts b/src/main_init.ts index 9882a42..5dbce24 100644 --- a/src/main_init.ts +++ b/src/main_init.ts @@ -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"; @@ -15,7 +16,7 @@ import { logger } from "./utils/logger"; const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000"; async function main(): Promise { - const envVars = getInitEnv(); + const envVars = getEnv(); const dataSource = await initDatabase(envVars.dbConfig); const sharedConfig = await fetchSharedConfig(envVars.sharedConfigURL); @@ -39,8 +40,8 @@ async function insertDomains( id: domain.id.toString(), type: domain.type, name: domain.name, - iconURL: domainMetadata[domain.id]?.iconUrl ?? "", - explorerURL: domainMetadata[domain.id]?.explorerUrl ?? "", + iconURL: domainMetadata.iconUrl ?? "", + explorerURL: domainMetadata.explorerUrl ?? "", }, ["id"], ); diff --git a/src/model/generated/domain.model.ts b/src/model/generated/domain.model.ts index 1690db4..12a8de3 100644 --- a/src/model/generated/domain.model.ts +++ b/src/model/generated/domain.model.ts @@ -21,10 +21,10 @@ export class Domain { @StringColumn_({nullable: false}) name!: string - @Column_("text", {nullable: true}) + @StringColumn_({nullable: true}) iconURL!: string | undefined | null - @Column_("text", {nullable: true}) + @StringColumn_({nullable: true}) explorerURL!: string | undefined | null @OneToMany_(() => Transfer, e => e.fromDomain) From 8fc982bd344b86a2e93c091b175ffda3573c4ef6 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Tue, 17 Dec 2024 14:12:03 +0100 Subject: [PATCH 04/14] Migration generating --- db/migrations/1734085803528-Data.js | 71 ------------------- ...54978596-Data.js => 1734440931514-Data.js} | 6 +- 2 files changed, 3 insertions(+), 74 deletions(-) delete mode 100644 db/migrations/1734085803528-Data.js rename db/migrations/{1734354978596-Data.js => 1734440931514-Data.js} (97%) diff --git a/db/migrations/1734085803528-Data.js b/db/migrations/1734085803528-Data.js deleted file mode 100644 index a4c9560..0000000 --- a/db/migrations/1734085803528-Data.js +++ /dev/null @@ -1,71 +0,0 @@ -module.exports = class Data1734085803528 { - name = 'Data1734085803528' - - async up(db) { - await db.query(`CREATE TABLE "resource" ("id" character varying NOT NULL, "type" text NOT NULL, CONSTRAINT "PK_e2894a5867e06ae2e8889f1173f" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "fee" ("id" character varying NOT NULL, "amount" text NOT NULL, "transfer_id" character varying, "token_id" uuid, CONSTRAINT "PK_ee7e51cc563615bc60c2b234635" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_119250e5caf62c90134b8e2f2d" ON "fee" ("transfer_id") `) - await db.query(`CREATE INDEX "IDX_bde4aa972635af552acf115242" ON "fee" ("token_id") `) - await db.query(`CREATE TABLE "token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "decimals" integer NOT NULL, "token_address" text NOT NULL, "token_symbol" text NOT NULL, "resource_id" character varying, "domain_id" character varying, CONSTRAINT "PK_82fae97f905930df5d62a702fc9" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) - await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_ada3dfc11e70168668345b2951" ON "token" ("token_address", "domain_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "deposit" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "block_number" text NOT NULL, "deposit_data" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "handler_response" text NOT NULL, "destination" text, "account_id" character varying, CONSTRAINT "PK_6654b4be449dadfd9d03a324b61" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_9ced91570695137ec1d60c1a61" ON "deposit" ("account_id") `) - await db.query(`CREATE TABLE "execution" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "block_number" text NOT NULL, "message" text, CONSTRAINT "PK_cc6684fedf29ec4c86db8448a2b" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "transfer" ("id" character varying NOT NULL, "status" character varying(8) NOT NULL, "deposit_nonce" text NOT NULL, "from_domain_id" character varying, "to_domain_id" character varying, "fee_id" character varying, "resource_id" character varying, "amount" text, "deposit_id" character varying, "execution_id" character varying, CONSTRAINT "REL_0832a6ad200eac838da26a9961" UNIQUE ("deposit_id"), CONSTRAINT "REL_4b62ae14edfb27605cd911db59" UNIQUE ("execution_id"), CONSTRAINT "REL_f6b9e9b86a1ce51c26cd08f596" UNIQUE ("fee_id"), CONSTRAINT "PK_fd9ddbdd49a17afcbe014401295" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_de485b5ed6e047f65e219eb9e9" ON "transfer" ("from_domain_id") `) - await db.query(`CREATE INDEX "IDX_2803ca6ca9e4443766093ff49b" ON "transfer" ("to_domain_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_0832a6ad200eac838da26a9961" ON "transfer" ("deposit_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_4b62ae14edfb27605cd911db59" ON "transfer" ("execution_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_f6b9e9b86a1ce51c26cd08f596" ON "transfer" ("fee_id") `) - await db.query(`CREATE INDEX "IDX_d508a1e7a2e0da07bd955f76d8" ON "transfer" ("resource_id") `) - await db.query(`ALTER TABLE "fee" ADD CONSTRAINT "FK_119250e5caf62c90134b8e2f2d3" FOREIGN KEY ("transfer_id") REFERENCES "transfer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "fee" ADD CONSTRAINT "FK_bde4aa972635af552acf1152420" FOREIGN KEY ("token_id") REFERENCES "token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "token" ADD CONSTRAINT "FK_435ef0917a04e91698042dff2bc" FOREIGN KEY ("resource_id") REFERENCES "resource"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "token" ADD CONSTRAINT "FK_3d565341b16e9c03d63e05eac83" FOREIGN KEY ("domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "deposit" ADD CONSTRAINT "FK_9ced91570695137ec1d60c1a61b" FOREIGN KEY ("account_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_de485b5ed6e047f65e219eb9e90" FOREIGN KEY ("from_domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_2803ca6ca9e4443766093ff49bf" FOREIGN KEY ("to_domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_0832a6ad200eac838da26a99615" FOREIGN KEY ("deposit_id") REFERENCES "deposit"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_4b62ae14edfb27605cd911db591" FOREIGN KEY ("execution_id") REFERENCES "execution"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a" FOREIGN KEY ("fee_id") REFERENCES "fee"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_d508a1e7a2e0da07bd955f76d81" FOREIGN KEY ("resource_id") REFERENCES "resource"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - } - - async down(db) { - await db.query(`DROP TABLE "resource"`) - await db.query(`DROP TABLE "fee"`) - await db.query(`DROP INDEX "public"."IDX_119250e5caf62c90134b8e2f2d"`) - await db.query(`DROP INDEX "public"."IDX_bde4aa972635af552acf115242"`) - await db.query(`DROP TABLE "token"`) - await db.query(`DROP INDEX "public"."IDX_435ef0917a04e91698042dff2b"`) - await db.query(`DROP INDEX "public"."IDX_3d565341b16e9c03d63e05eac8"`) - await db.query(`DROP INDEX "public"."IDX_ada3dfc11e70168668345b2951"`) - await db.query(`DROP TABLE "domain"`) - await db.query(`DROP TABLE "account"`) - await db.query(`DROP TABLE "deposit"`) - await db.query(`DROP INDEX "public"."IDX_9ced91570695137ec1d60c1a61"`) - await db.query(`DROP TABLE "execution"`) - await db.query(`DROP TABLE "transfer"`) - await db.query(`DROP INDEX "public"."IDX_de485b5ed6e047f65e219eb9e9"`) - await db.query(`DROP INDEX "public"."IDX_2803ca6ca9e4443766093ff49b"`) - await db.query(`DROP INDEX "public"."IDX_0832a6ad200eac838da26a9961"`) - await db.query(`DROP INDEX "public"."IDX_4b62ae14edfb27605cd911db59"`) - await db.query(`DROP INDEX "public"."IDX_f6b9e9b86a1ce51c26cd08f596"`) - await db.query(`DROP INDEX "public"."IDX_d508a1e7a2e0da07bd955f76d8"`) - await db.query(`ALTER TABLE "fee" DROP CONSTRAINT "FK_119250e5caf62c90134b8e2f2d3"`) - await db.query(`ALTER TABLE "fee" DROP CONSTRAINT "FK_bde4aa972635af552acf1152420"`) - await db.query(`ALTER TABLE "token" DROP CONSTRAINT "FK_435ef0917a04e91698042dff2bc"`) - await db.query(`ALTER TABLE "token" DROP CONSTRAINT "FK_3d565341b16e9c03d63e05eac83"`) - await db.query(`ALTER TABLE "deposit" DROP CONSTRAINT "FK_9ced91570695137ec1d60c1a61b"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_de485b5ed6e047f65e219eb9e90"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_2803ca6ca9e4443766093ff49bf"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_0832a6ad200eac838da26a99615"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_4b62ae14edfb27605cd911db591"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_d508a1e7a2e0da07bd955f76d81"`) - } -} diff --git a/db/migrations/1734354978596-Data.js b/db/migrations/1734440931514-Data.js similarity index 97% rename from db/migrations/1734354978596-Data.js rename to db/migrations/1734440931514-Data.js index 987b337..c96ef45 100644 --- a/db/migrations/1734354978596-Data.js +++ b/db/migrations/1734440931514-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1734354978596 { - name = 'Data1734354978596' +module.exports = class Data1734440931514 { + name = 'Data1734440931514' async up(db) { await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) @@ -11,7 +11,7 @@ module.exports = class Data1734354978596 { await db.query(`CREATE INDEX "IDX_cd316229471fecd312159ee307" ON "route" ("from_domain_id") `) await db.query(`CREATE INDEX "IDX_863162a8edb416799e89f386f8" ON "route" ("to_domain_id") `) await db.query(`CREATE UNIQUE INDEX "IDX_7dc7af2a7a9c846759377d1450" ON "route" ("from_domain_id", "to_domain_id", "resource_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "decimals" integer NOT NULL, "token_address" text NOT NULL, "token_symbol" text NOT NULL, "resource_id" character varying, "domain_id" character varying, CONSTRAINT "PK_82fae97f905930df5d62a702fc9" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) From 52ed76a165e7726d9bde22f21dc27ce14b29069d Mon Sep 17 00:00:00 2001 From: mj52951 Date: Wed, 18 Dec 2024 16:48:11 +0100 Subject: [PATCH 05/14] Migration aligning --- db/migrations/1734440931514-Data.js | 77 ------------------- ...34955039-Data.js => 1734536868219-Data.js} | 6 +- 2 files changed, 3 insertions(+), 80 deletions(-) delete mode 100644 db/migrations/1734440931514-Data.js rename db/migrations/{1734434955039-Data.js => 1734536868219-Data.js} (97%) diff --git a/db/migrations/1734440931514-Data.js b/db/migrations/1734440931514-Data.js deleted file mode 100644 index c96ef45..0000000 --- a/db/migrations/1734440931514-Data.js +++ /dev/null @@ -1,77 +0,0 @@ -module.exports = class Data1734440931514 { - name = 'Data1734440931514' - - async up(db) { - await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "deposit" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "block_number" text NOT NULL, "deposit_data" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "handler_response" text NOT NULL, "destination" text, "account_id" character varying, CONSTRAINT "PK_6654b4be449dadfd9d03a324b61" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_9ced91570695137ec1d60c1a61" ON "deposit" ("account_id") `) - await db.query(`CREATE TABLE "execution" ("id" character varying NOT NULL, "tx_hash" text NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE, "block_number" text NOT NULL, "message" text, CONSTRAINT "PK_cc6684fedf29ec4c86db8448a2b" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "resource" ("id" character varying NOT NULL, "type" text NOT NULL, CONSTRAINT "PK_e2894a5867e06ae2e8889f1173f" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "route" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "from_domain_id" character varying, "to_domain_id" character varying, "resource_id" text, CONSTRAINT "PK_08affcd076e46415e5821acf52d" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_cd316229471fecd312159ee307" ON "route" ("from_domain_id") `) - await db.query(`CREATE INDEX "IDX_863162a8edb416799e89f386f8" ON "route" ("to_domain_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_7dc7af2a7a9c846759377d1450" ON "route" ("from_domain_id", "to_domain_id", "resource_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "decimals" integer NOT NULL, "token_address" text NOT NULL, "token_symbol" text NOT NULL, "resource_id" character varying, "domain_id" character varying, CONSTRAINT "PK_82fae97f905930df5d62a702fc9" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) - await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_ada3dfc11e70168668345b2951" ON "token" ("token_address", "domain_id") `) - await db.query(`CREATE TABLE "fee" ("id" character varying NOT NULL, "amount" text NOT NULL, "transfer_id" character varying, "token_id" uuid, CONSTRAINT "PK_ee7e51cc563615bc60c2b234635" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_119250e5caf62c90134b8e2f2d" ON "fee" ("transfer_id") `) - await db.query(`CREATE INDEX "IDX_bde4aa972635af552acf115242" ON "fee" ("token_id") `) - await db.query(`CREATE TABLE "transfer" ("id" character varying NOT NULL, "status" character varying(8) NOT NULL, "deposit_nonce" text NOT NULL, "fee_id" character varying, "route_id" uuid, "amount" text, "deposit_id" character varying, "execution_id" character varying, CONSTRAINT "REL_0832a6ad200eac838da26a9961" UNIQUE ("deposit_id"), CONSTRAINT "REL_4b62ae14edfb27605cd911db59" UNIQUE ("execution_id"), CONSTRAINT "REL_f6b9e9b86a1ce51c26cd08f596" UNIQUE ("fee_id"), CONSTRAINT "PK_fd9ddbdd49a17afcbe014401295" PRIMARY KEY ("id"))`) - await db.query(`CREATE UNIQUE INDEX "IDX_0832a6ad200eac838da26a9961" ON "transfer" ("deposit_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_4b62ae14edfb27605cd911db59" ON "transfer" ("execution_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_f6b9e9b86a1ce51c26cd08f596" ON "transfer" ("fee_id") `) - await db.query(`CREATE INDEX "IDX_da16210e30a21445643e6acbcd" ON "transfer" ("route_id") `) - await db.query(`CREATE UNIQUE INDEX "IDX_dd067380efca25d1e6764fa65f" ON "transfer" ("route_id", "deposit_nonce") `) - await db.query(`ALTER TABLE "deposit" ADD CONSTRAINT "FK_9ced91570695137ec1d60c1a61b" FOREIGN KEY ("account_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "route" ADD CONSTRAINT "FK_cd316229471fecd312159ee307e" FOREIGN KEY ("from_domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "route" ADD CONSTRAINT "FK_863162a8edb416799e89f386f82" FOREIGN KEY ("to_domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "token" ADD CONSTRAINT "FK_435ef0917a04e91698042dff2bc" FOREIGN KEY ("resource_id") REFERENCES "resource"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "token" ADD CONSTRAINT "FK_3d565341b16e9c03d63e05eac83" FOREIGN KEY ("domain_id") REFERENCES "domain"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "fee" ADD CONSTRAINT "FK_119250e5caf62c90134b8e2f2d3" FOREIGN KEY ("transfer_id") REFERENCES "transfer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "fee" ADD CONSTRAINT "FK_bde4aa972635af552acf1152420" FOREIGN KEY ("token_id") REFERENCES "token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_0832a6ad200eac838da26a99615" FOREIGN KEY ("deposit_id") REFERENCES "deposit"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_4b62ae14edfb27605cd911db591" FOREIGN KEY ("execution_id") REFERENCES "execution"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a" FOREIGN KEY ("fee_id") REFERENCES "fee"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "transfer" ADD CONSTRAINT "FK_da16210e30a21445643e6acbcd7" FOREIGN KEY ("route_id") REFERENCES "route"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - } - - async down(db) { - await db.query(`DROP TABLE "account"`) - await db.query(`DROP TABLE "deposit"`) - await db.query(`DROP INDEX "public"."IDX_9ced91570695137ec1d60c1a61"`) - await db.query(`DROP TABLE "execution"`) - await db.query(`DROP TABLE "resource"`) - await db.query(`DROP TABLE "route"`) - await db.query(`DROP INDEX "public"."IDX_cd316229471fecd312159ee307"`) - await db.query(`DROP INDEX "public"."IDX_863162a8edb416799e89f386f8"`) - await db.query(`DROP INDEX "public"."IDX_7dc7af2a7a9c846759377d1450"`) - await db.query(`DROP TABLE "domain"`) - await db.query(`DROP TABLE "token"`) - await db.query(`DROP INDEX "public"."IDX_435ef0917a04e91698042dff2b"`) - await db.query(`DROP INDEX "public"."IDX_3d565341b16e9c03d63e05eac8"`) - await db.query(`DROP INDEX "public"."IDX_ada3dfc11e70168668345b2951"`) - await db.query(`DROP TABLE "fee"`) - await db.query(`DROP INDEX "public"."IDX_119250e5caf62c90134b8e2f2d"`) - await db.query(`DROP INDEX "public"."IDX_bde4aa972635af552acf115242"`) - await db.query(`DROP TABLE "transfer"`) - await db.query(`DROP INDEX "public"."IDX_0832a6ad200eac838da26a9961"`) - await db.query(`DROP INDEX "public"."IDX_4b62ae14edfb27605cd911db59"`) - await db.query(`DROP INDEX "public"."IDX_f6b9e9b86a1ce51c26cd08f596"`) - await db.query(`DROP INDEX "public"."IDX_da16210e30a21445643e6acbcd"`) - await db.query(`DROP INDEX "public"."IDX_dd067380efca25d1e6764fa65f"`) - await db.query(`ALTER TABLE "deposit" DROP CONSTRAINT "FK_9ced91570695137ec1d60c1a61b"`) - await db.query(`ALTER TABLE "route" DROP CONSTRAINT "FK_cd316229471fecd312159ee307e"`) - await db.query(`ALTER TABLE "route" DROP CONSTRAINT "FK_863162a8edb416799e89f386f82"`) - await db.query(`ALTER TABLE "token" DROP CONSTRAINT "FK_435ef0917a04e91698042dff2bc"`) - await db.query(`ALTER TABLE "token" DROP CONSTRAINT "FK_3d565341b16e9c03d63e05eac83"`) - await db.query(`ALTER TABLE "fee" DROP CONSTRAINT "FK_119250e5caf62c90134b8e2f2d3"`) - await db.query(`ALTER TABLE "fee" DROP CONSTRAINT "FK_bde4aa972635af552acf1152420"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_0832a6ad200eac838da26a99615"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_4b62ae14edfb27605cd911db591"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a"`) - await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_da16210e30a21445643e6acbcd7"`) - } -} diff --git a/db/migrations/1734434955039-Data.js b/db/migrations/1734536868219-Data.js similarity index 97% rename from db/migrations/1734434955039-Data.js rename to db/migrations/1734536868219-Data.js index 5874e43..e5ce714 100644 --- a/db/migrations/1734434955039-Data.js +++ b/db/migrations/1734536868219-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1734434955039 { - name = 'Data1734434955039' +module.exports = class Data1734536868219 { + name = 'Data1734536868219' async up(db) { await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) @@ -12,7 +12,7 @@ module.exports = class Data1734434955039 { await db.query(`CREATE INDEX "IDX_863162a8edb416799e89f386f8" ON "route" ("to_domain_id") `) await db.query(`CREATE INDEX "IDX_4536bd7b96f363dedfe95dd26f" ON "route" ("resource_id") `) await db.query(`CREATE UNIQUE INDEX "IDX_7dc7af2a7a9c846759377d1450" ON "route" ("from_domain_id", "to_domain_id", "resource_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "decimals" integer NOT NULL, "token_address" text NOT NULL, "token_symbol" text NOT NULL, "resource_id" character varying, "domain_id" character varying, CONSTRAINT "PK_82fae97f905930df5d62a702fc9" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) From 619b1161f6eb84852958898bd6d22777fed968d1 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Thu, 19 Dec 2024 15:24:08 +0100 Subject: [PATCH 06/14] chore: Add domains endpoint --- src/api/controllers/DomainsController.ts | 30 +++++++++++++++++++ src/api/routes/domains.routes.ts | 18 +++++++++++ src/api/routes/index.ts | 2 ++ src/api/schemas/domains.schema.ts | 24 +++++++++++++++ .../services/dataAccess/domains.service.ts | 24 +++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 src/api/controllers/DomainsController.ts create mode 100644 src/api/routes/domains.routes.ts create mode 100644 src/api/schemas/domains.schema.ts create mode 100644 src/api/services/dataAccess/domains.service.ts diff --git a/src/api/controllers/DomainsController.ts b/src/api/controllers/DomainsController.ts new file mode 100644 index 0000000..6166aae --- /dev/null +++ b/src/api/controllers/DomainsController.ts @@ -0,0 +1,30 @@ +/* +The Licensed Work is (c) 2024 Sygma +SPDX-License-Identifier: LGPL-3.0-only +*/ +import type { FastifyReply, FastifyRequest } from "fastify"; +import type { DataSource } from "typeorm"; + +import { logger } from "../../utils/logger"; +import { DomainsService } from "../services/dataAccess/domains.service"; + +export class DomainsController { + private domainsService: DomainsService; + + constructor(dataSource: DataSource) { + this.domainsService = new DomainsService(dataSource); + } + + public async getDomains( + request: FastifyRequest, + reply: FastifyReply, + ): Promise { + try { + const domainsResult = await this.domainsService.findDomains({}); + await reply.status(200).send(domainsResult); + } catch (error) { + logger.error("Error occurred when fetching domains", error); + await reply.status(500).send({ error: "Internal server error" }); + } + } +} diff --git a/src/api/routes/domains.routes.ts b/src/api/routes/domains.routes.ts new file mode 100644 index 0000000..990160f --- /dev/null +++ b/src/api/routes/domains.routes.ts @@ -0,0 +1,18 @@ +/* +The Licensed Work is (c) 2024 Sygma +SPDX-License-Identifier: LGPL-3.0-only +*/ +import type { FastifyInstance } from "fastify"; + +import { DomainsController } from "../controllers/DomainsController"; +import { domainsSchema } from "../schemas/domains.schema"; + +export async function domainRoutes(server: FastifyInstance): Promise { + const domainsController = new DomainsController(server.db); + server.get( + "/domains", + { schema: domainsSchema }, + domainsController.getDomains.bind(domainsController), + ); + return Promise.resolve(); +} diff --git a/src/api/routes/index.ts b/src/api/routes/index.ts index f523559..e0bf4b7 100644 --- a/src/api/routes/index.ts +++ b/src/api/routes/index.ts @@ -4,8 +4,10 @@ SPDX-License-Identifier: LGPL-3.0-only */ import type { FastifyInstance } from "fastify"; +import { domainRoutes } from "./domains.routes"; import { transferRoutes } from "./transfers.routes"; export async function registerRoutes(server: FastifyInstance): Promise { await server.register(transferRoutes, { prefix: "/api" }); + await server.register(domainRoutes, { prefix: "/api" }); } diff --git a/src/api/schemas/domains.schema.ts b/src/api/schemas/domains.schema.ts new file mode 100644 index 0000000..5a2207e --- /dev/null +++ b/src/api/schemas/domains.schema.ts @@ -0,0 +1,24 @@ +/* +The Licensed Work is (c) 2024 Sygma +SPDX-License-Identifier: LGPL-3.0-only +*/ +import { domainSchema } from "."; + +export const domainsSchema = { + summary: "Get domains", + response: { + 200: { + description: "List of domains", + content: { + "application/json": { + schema: { + type: "array", + items: { + ...domainSchema, + }, + }, + }, + }, + }, + }, +}; diff --git a/src/api/services/dataAccess/domains.service.ts b/src/api/services/dataAccess/domains.service.ts new file mode 100644 index 0000000..08dfe4c --- /dev/null +++ b/src/api/services/dataAccess/domains.service.ts @@ -0,0 +1,24 @@ +/* +The Licensed Work is (c) 2024 Sygma +SPDX-License-Identifier: LGPL-3.0-only +*/ +import type { DataSource, FindOptionsWhere, Repository } from "typeorm"; + +import { Domain } from "../../../model"; + +export class DomainsService { + private domainRepository: Repository; + constructor(dataSource: DataSource) { + this.domainRepository = dataSource.getRepository(Domain); + } + + public async findDomains(where: FindOptionsWhere): Promise { + const routes = await this.domainRepository.find({ + where, + order: { + id: "ASC", + }, + }); + return routes; + } +} From 45d5bdc8e75dd9cd3b45bfa9dbeaa090c1b539de Mon Sep 17 00:00:00 2001 From: mj52951 Date: Thu, 19 Dec 2024 15:27:55 +0100 Subject: [PATCH 07/14] Naming fix --- src/api/services/dataAccess/domains.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/services/dataAccess/domains.service.ts b/src/api/services/dataAccess/domains.service.ts index 08dfe4c..c08f104 100644 --- a/src/api/services/dataAccess/domains.service.ts +++ b/src/api/services/dataAccess/domains.service.ts @@ -13,12 +13,12 @@ export class DomainsService { } public async findDomains(where: FindOptionsWhere): Promise { - const routes = await this.domainRepository.find({ + const domains = await this.domainRepository.find({ where, order: { id: "ASC", }, }); - return routes; + return domains; } } From 17c2ba3895702ef8443c7bb2d2a72dde3ee5443e Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 13:53:49 +0100 Subject: [PATCH 08/14] Align main init --- src/main_init.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main_init.ts b/src/main_init.ts index eb1d8f9..18d39f7 100644 --- a/src/main_init.ts +++ b/src/main_init.ts @@ -7,8 +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 { getDomainMetadata, getEnv } from "./indexer/config/envLoader"; import { Domain, Resource, Token } from "./model"; import { initDatabase } from "./utils"; @@ -19,20 +18,16 @@ export async function init(): Promise { const dataSource = await initDatabase(envVars.dbConfig); const sharedConfig = await fetchSharedConfig(envVars.sharedConfigURL); - await insertDomains( - sharedConfig.domains, - dataSource.manager, - envVars.domainMetadata, - ); + await insertDomains(sharedConfig.domains, dataSource.manager); await dataSource.destroy(); } async function insertDomains( domains: Array, manager: EntityManager, - domainMetadata: DomainMetadata, ): Promise { for (const domain of domains) { + const domainMetadata = getDomainMetadata(domain.id.toString()); await manager.upsert( Domain, { From 4652493808c16630c4e8b2170bf2ad6100052c2b Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 14:29:52 +0100 Subject: [PATCH 09/14] Insert only supported domains --- src/main_init.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main_init.ts b/src/main_init.ts index 18d39f7..c7684fb 100644 --- a/src/main_init.ts +++ b/src/main_init.ts @@ -10,6 +10,7 @@ import { fetchSharedConfig } from "./indexer/config"; import { getDomainMetadata, getEnv } from "./indexer/config/envLoader"; import { Domain, Resource, Token } from "./model"; import { initDatabase } from "./utils"; +import { logger } from "./utils/logger"; const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000"; @@ -18,15 +19,24 @@ export async function init(): Promise { 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, manager: EntityManager, + supportedDomains: number[], ): Promise { for (const domain of domains) { + if (!supportedDomains.includes(domain.id)) { + logger.warn(`Unsupported domain with id ${domain.id}, skipping...`); + continue; + } const domainMetadata = getDomainMetadata(domain.id.toString()); await manager.upsert( Domain, From d8f9f33dc04e729d56549b964e5455f2cef02647 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 14:46:50 +0100 Subject: [PATCH 10/14] Clean env files --- .env | 8 +------- envs/.env.api | 5 ----- envs/.env.evm-1 | 13 ------------- envs/.env.evm-2 | 13 ------------- envs/.env.substrate | 13 ------------- 5 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 envs/.env.api delete mode 100644 envs/.env.evm-1 delete mode 100644 envs/.env.evm-2 delete mode 100644 envs/.env.substrate diff --git a/.env b/.env index afa8ab9..ef52312 100644 --- a/.env +++ b/.env @@ -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]' \ No newline at end of file +DB_HOST=db \ No newline at end of file diff --git a/envs/.env.api b/envs/.env.api deleted file mode 100644 index a487c9b..0000000 --- a/envs/.env.api +++ /dev/null @@ -1,5 +0,0 @@ -DB_NAME=squid -DB_PASS=squid -DB_PORT=5432 -DB_USERNAME=postgres -DB_HOST=db \ No newline at end of file diff --git a/envs/.env.evm-1 b/envs/.env.evm-1 deleted file mode 100644 index 0692246..0000000 --- a/envs/.env.evm-1 +++ /dev/null @@ -1,13 +0,0 @@ -DB_NAME=squid -DB_PASS=squid -DB_PORT=5432 -DB_USERNAME=postgres -DB_HOST=db -START_SCRIPT_ENV=index - -PROCESSOR_PROMETHEUS_PORT=3000 - -SHARED_CONFIG_URL="https://ipfs.io/ipfs/bafkreiasnla2ya55of6nwm3swjstip4q2ixfa3t6tvixyibclfovxnerte" - -DOMAIN_ID=1 -1_METADATA='{"rpcUrl": "http://evm1:8545"}' diff --git a/envs/.env.evm-2 b/envs/.env.evm-2 deleted file mode 100644 index 1889c40..0000000 --- a/envs/.env.evm-2 +++ /dev/null @@ -1,13 +0,0 @@ -DB_NAME=squid -DB_PASS=squid -DB_PORT=5432 -DB_USERNAME=postgres -DB_HOST=db -START_SCRIPT_ENV=index - -PROCESSOR_PROMETHEUS_PORT=3002 - -SHARED_CONFIG_URL="https://ipfs.io/ipfs/bafkreiasnla2ya55of6nwm3swjstip4q2ixfa3t6tvixyibclfovxnerte" - -DOMAIN_ID=2 -2_METADATA='{"rpcUrl": "http://evm2:8545"}' diff --git a/envs/.env.substrate b/envs/.env.substrate deleted file mode 100644 index 0a2a60d..0000000 --- a/envs/.env.substrate +++ /dev/null @@ -1,13 +0,0 @@ -DB_NAME=squid -DB_PASS=squid -DB_PORT=5432 -DB_USERNAME=postgres -DB_HOST=db -START_SCRIPT_ENV=index - -PROCESSOR_PROMETHEUS_PORT=3004 - -SHARED_CONFIG_URL="https://ipfs.io/ipfs/bafkreiasnla2ya55of6nwm3swjstip4q2ixfa3t6tvixyibclfovxnerte" - -DOMAIN_ID=3 -3_METADATA='{"rpcUrl": "ws://substrate-pallet:9944"}' From dd484c43c55b466cf2ef7bbb7dbc5e16defa6806 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 14:55:18 +0100 Subject: [PATCH 11/14] Change loop iterating --- src/indexer/evmIndexer/evmProcessor.ts | 2 +- src/indexer/substrateIndexer/substrateParser.ts | 4 ++-- src/indexer/substrateIndexer/substrateProcessor.ts | 2 +- src/main_init.ts | 11 +++++------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/indexer/evmIndexer/evmProcessor.ts b/src/indexer/evmIndexer/evmProcessor.ts index 1e14a40..b5a32df 100644 --- a/src/indexer/evmIndexer/evmProcessor.ts +++ b/src/indexer/evmIndexer/evmProcessor.ts @@ -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 { diff --git a/src/indexer/substrateIndexer/substrateParser.ts b/src/indexer/substrateIndexer/substrateParser.ts index 4a09986..8af07b7 100644 --- a/src/indexer/substrateIndexer/substrateParser.ts +++ b/src/indexer/substrateIndexer/substrateParser.ts @@ -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}`, ); } @@ -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}`, ); } diff --git a/src/indexer/substrateIndexer/substrateProcessor.ts b/src/indexer/substrateIndexer/substrateProcessor.ts index 5e42901..8281725 100644 --- a/src/indexer/substrateIndexer/substrateProcessor.ts +++ b/src/indexer/substrateIndexer/substrateProcessor.ts @@ -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 { diff --git a/src/main_init.ts b/src/main_init.ts index c7684fb..44d991d 100644 --- a/src/main_init.ts +++ b/src/main_init.ts @@ -10,7 +10,6 @@ import { fetchSharedConfig } from "./indexer/config"; import { getDomainMetadata, getEnv } from "./indexer/config/envLoader"; import { Domain, Resource, Token } from "./model"; import { initDatabase } from "./utils"; -import { logger } from "./utils/logger"; const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000"; @@ -30,12 +29,12 @@ export async function init(): Promise { async function insertDomains( domains: Array, manager: EntityManager, - supportedDomains: number[], + supportedDomainsIDs: number[], ): Promise { - for (const domain of domains) { - if (!supportedDomains.includes(domain.id)) { - logger.warn(`Unsupported domain with id ${domain.id}, skipping...`); - continue; + 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( From c69547618b83310d1c88bbbdf43203e02216931d Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 15:50:03 +0100 Subject: [PATCH 12/14] Expand with domain metadata --- src/api/schemas/domains.schema.ts | 5 +++-- src/api/schemas/index.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api/schemas/domains.schema.ts b/src/api/schemas/domains.schema.ts index 5a2207e..485eb8a 100644 --- a/src/api/schemas/domains.schema.ts +++ b/src/api/schemas/domains.schema.ts @@ -2,7 +2,7 @@ The Licensed Work is (c) 2024 Sygma SPDX-License-Identifier: LGPL-3.0-only */ -import { domainSchema } from "."; +import { domainMetadataSchema, domainSchema } from "."; export const domainsSchema = { summary: "Get domains", @@ -14,7 +14,8 @@ export const domainsSchema = { schema: { type: "array", items: { - ...domainSchema, + ...domainSchema.properties, + ...domainMetadataSchema.properties, }, }, }, diff --git a/src/api/schemas/index.ts b/src/api/schemas/index.ts index 88d6049..32b1b2c 100644 --- a/src/api/schemas/index.ts +++ b/src/api/schemas/index.ts @@ -25,6 +25,14 @@ export const domainSchema = { }, }; +export const domainMetadataSchema = { + type: "object", + properties: { + iconURL: { type: "string", example: "https://example.com/icon1.png" }, + explorerURL: { type: "string", example: "https://explorer.com/1" }, + }, +}; + export const tokenSchema = { tpye: "object", properties: { From 7b60f92ff75ae4734b8953bc8e7b40d95e85756c Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 16:09:11 +0100 Subject: [PATCH 13/14] Set explorerUrl and iconUrl as mandatory --- .../{1734536868219-Data.js => 1734706828708-Data.js} | 8 ++++---- envs/.env.indexer.example | 6 +++--- schema.graphql | 4 ++-- src/indexer/config/envLoader.ts | 4 ++-- src/model/generated/domain.model.ts | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) rename db/migrations/{1734536868219-Data.js => 1734706828708-Data.js} (97%) diff --git a/db/migrations/1734536868219-Data.js b/db/migrations/1734706828708-Data.js similarity index 97% rename from db/migrations/1734536868219-Data.js rename to db/migrations/1734706828708-Data.js index 243bb80..526221d 100644 --- a/db/migrations/1734536868219-Data.js +++ b/db/migrations/1734706828708-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1734536868219 { - name = 'Data1734536868219' +module.exports = class Data1734706828708 { + name = 'Data1734706828708' async up(db) { await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "address_status" text, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) @@ -12,7 +12,7 @@ module.exports = class Data1734536868219 { await db.query(`CREATE INDEX "IDX_863162a8edb416799e89f386f8" ON "route" ("to_domain_id") `) await db.query(`CREATE INDEX "IDX_4536bd7b96f363dedfe95dd26f" ON "route" ("resource_id") `) await db.query(`CREATE UNIQUE INDEX "IDX_7dc7af2a7a9c846759377d1450" ON "route" ("from_domain_id", "to_domain_id", "resource_id") `) - await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text, "explorer_url" text, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "domain" ("id" character varying NOT NULL, "type" text NOT NULL, "name" text NOT NULL, "icon_url" text NOT NULL, "explorer_url" text NOT NULL, CONSTRAINT "PK_27e3ec3ea0ae02c8c5bceab3ba9" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "decimals" integer NOT NULL, "token_address" text NOT NULL, "token_symbol" text NOT NULL, "resource_id" character varying, "domain_id" character varying, CONSTRAINT "PK_82fae97f905930df5d62a702fc9" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_435ef0917a04e91698042dff2b" ON "token" ("resource_id") `) await db.query(`CREATE INDEX "IDX_3d565341b16e9c03d63e05eac8" ON "token" ("domain_id") `) @@ -78,4 +78,4 @@ module.exports = class Data1734536868219 { await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_f6b9e9b86a1ce51c26cd08f596a"`) await db.query(`ALTER TABLE "transfer" DROP CONSTRAINT "FK_da16210e30a21445643e6acbcd7"`) } -} \ No newline at end of file +} diff --git a/envs/.env.indexer.example b/envs/.env.indexer.example index afa8ab9..3eae8a5 100644 --- a/envs/.env.indexer.example +++ b/envs/.env.indexer.example @@ -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]' \ No newline at end of file diff --git a/schema.graphql b/schema.graphql index 418f7c4..bf55092 100644 --- a/schema.graphql +++ b/schema.graphql @@ -67,8 +67,8 @@ type Domain @entity { id: ID! type: String! name: String! - iconURL: String - explorerURL: String + iconURL: String! + explorerURL: String! routesFrom: [Route!] @derivedFrom(field: "fromDomain") routesTo: [Route!] @derivedFrom(field: "toDomain") token: [Token!] @derivedFrom(field: "domain") diff --git a/src/indexer/config/envLoader.ts b/src/indexer/config/envLoader.ts index 705806e..65ae8b6 100644 --- a/src/indexer/config/envLoader.ts +++ b/src/indexer/config/envLoader.ts @@ -15,8 +15,8 @@ export type DomainMetadata = { domainId: number; rpcUrl: string; domainGateway?: string; - iconUrl?: string; - explorerUrl?: string; + iconUrl: string; + explorerUrl: string; }; export type EnvVariables = { diff --git a/src/model/generated/domain.model.ts b/src/model/generated/domain.model.ts index 2cd798a..c5281c8 100644 --- a/src/model/generated/domain.model.ts +++ b/src/model/generated/domain.model.ts @@ -21,11 +21,11 @@ export class Domain { @StringColumn_({nullable: false}) name!: string - @StringColumn_({nullable: true}) - iconURL!: string | undefined | null + @StringColumn_({nullable: false}) + iconURL!: string - @StringColumn_({nullable: true}) - explorerURL!: string | undefined | null + @StringColumn_({nullable: false}) + explorerURL!: string @OneToMany_(() => Route, e => e.fromDomain) routesFrom!: Route[] From 1dad11d8284883cd0913963c7128af7aec70afc0 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 20 Dec 2024 16:27:17 +0100 Subject: [PATCH 14/14] Add e2e test --- tests/e2e/domains.spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/e2e/domains.spec.ts diff --git a/tests/e2e/domains.spec.ts b/tests/e2e/domains.spec.ts new file mode 100644 index 0000000..ddd30d7 --- /dev/null +++ b/tests/e2e/domains.spec.ts @@ -0,0 +1,24 @@ +/* +The Licensed Work is (c) 2024 Sygma +SPDX-License-Identifier: LGPL-3.0-only +*/ + +import { expect } from "chai"; +import { Domain } from "../../src/model"; + +const NUMBER_OF_DOMAINS = 3; + +describe("Domains tests", function () { + it("should succesfully fetch all domains", async () => { + const response = await fetch("http://localhost:8000/api/domains"); + const domains: Array = await response.json(); + expect(domains.length).to.be.deep.equal(NUMBER_OF_DOMAINS); + domains.map((domain) => { + expect(domain.id).to.be.not.null; + expect(domain.name).to.be.not.null; + expect(domain.type).to.be.not.null; + expect(domain.iconURL).to.be.not.null; + expect(domain.explorerURL).to.be.not.null; + }); + }); +});