From 8c2e16bed4e757e622e2b9ec892ef480d68574e2 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Wed, 11 Dec 2024 10:59:05 +0100 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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") `)