From 06a6b7fa3ee108b0dbb33df07edfef278c09f289 Mon Sep 17 00:00:00 2001 From: carolk-dev Date: Tue, 22 Oct 2024 15:48:01 +0900 Subject: [PATCH 1/2] add one more opensearch call for migration --- bridge/src/index.ts | 10 +++++- bridge/src/observers/burn-event-observer.ts | 34 ++++++++++++++++++- .../observers/burn-event-observer.spec.ts | 11 +++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/bridge/src/index.ts b/bridge/src/index.ts index 51424a5..60a74ca 100644 --- a/bridge/src/index.ts +++ b/bridge/src/index.ts @@ -97,6 +97,7 @@ process.on("uncaughtException", console.error); const SLACK_WEB_TOKEN: string = Configuration.get("SLACK_WEB_TOKEN"); const FAILURE_SUBSCRIBERS: string = Configuration.get("FAILURE_SUBSCRIBERS"); const OPENSEARCH_ENDPOINT: string = Configuration.get("OPENSEARCH_ENDPOINT"); + const OPENSEARCH_ENDPOINT_MIGRATION: string = Configuration.get("OPENSEARCH_ENDPOINT_MIGRATION"); const OPENSEARCH_AUTH: string = Configuration.get("OPENSEARCH_AUTH"); const OPENSEARCH_INDEX: string = Configuration.get("OPENSEARCH_INDEX", false) || "9c-eth-bridge"; @@ -244,6 +245,12 @@ process.on("uncaughtException", console.error); OPENSEARCH_INDEX ); + const opensearchMigrationClient = new OpenSearchClient( + OPENSEARCH_ENDPOINT_MIGRATION, + OPENSEARCH_AUTH, + OPENSEARCH_INDEX + ); + const GRAPHQL_REQUEST_RETRY = 5; const JWT_SECRET_KEY = Configuration.get("JWT_SECRET_KEY"); const headlessGraphQLCLient = new HeadlessGraphQLClient( @@ -340,7 +347,8 @@ process.on("uncaughtException", console.error); BSCSCAN_ROOT_URL, integration, multiPlanetary, - FAILURE_SUBSCRIBERS + FAILURE_SUBSCRIBERS, + opensearchMigrationClient ); const ethereumBurnEventMonitor = new BscBurnEventMonitor( provider, diff --git a/bridge/src/observers/burn-event-observer.ts b/bridge/src/observers/burn-event-observer.ts index 7e4cda9..1a31179 100644 --- a/bridge/src/observers/burn-event-observer.ts +++ b/bridge/src/observers/burn-event-observer.ts @@ -36,6 +36,7 @@ export class BscBurnEventObserver private readonly _integration: Integration; private readonly _multiPlanetary: MultiPlanetary; private readonly _failureSubscribers: string; + private readonly _opensearchMigrationClient: OpenSearchClient; constructor( ncgTransfer: INCGTransfer, @@ -50,7 +51,8 @@ export class BscBurnEventObserver etherscanUrl: string, integration: Integration, multiPlanetary: MultiPlanetary, - failureSubscribers: string + failureSubscribers: string, + opensearchMigrationClient: OpenSearchClient ) { this._ncgTransfer = ncgTransfer; this._slackMessageSender = slackMessageSender; @@ -65,6 +67,7 @@ export class BscBurnEventObserver this._integration = integration; this._multiPlanetary = multiPlanetary; this._failureSubscribers = failureSubscribers; + this._opensearchMigrationClient = opensearchMigrationClient; } async notify(data: { @@ -116,6 +119,15 @@ export class BscBurnEventObserver amount: amountString, network: "BSC", }); + this._opensearchMigrationClient.to_opensearch("error", { + content: "wNCG -> NCG request failure", + cause: "Exchange history exist", + ethereumTxId: transactionHash, + sender: sender, + recipient: user9cAddress, + amount: amountString, + network: "BSC", + }); continue; } @@ -189,6 +201,16 @@ export class BscBurnEventObserver planetName: requestPlanetName, network: "BSC", }); + await this._opensearchMigrationClient.to_opensearch("info", { + content: "wNCG -> NCG request success", + libplanetTxId: nineChroniclesTxId, + ethereumTxId: transactionHash, + sender: sender, + recipient: user9cAddress, + amount: amount.toNumber(), + planetName: requestPlanetName, + network: "BSC", + }); console.log("Transferred", nineChroniclesTxId); } catch (e) { const slackMsgRes = await this._slackMessageSender.sendMessage( @@ -228,6 +250,16 @@ export class BscBurnEventObserver planetName: requestPlanetName, network: "BSC", }); + await this._opensearchMigrationClient.to_opensearch("error", { + content: "wNCG -> NCG request failure", + cause: String(e), + ethereumTxId: transactionHash, + sender: sender, + recipient: user9cAddress, + amount: amount.toNumber(), + planetName: requestPlanetName, + network: "BSC", + }); await this._integration.error( "Unexpected error during unwrapping NCG", { diff --git a/bridge/test/observers/burn-event-observer.spec.ts b/bridge/test/observers/burn-event-observer.spec.ts index a19f8bb..daebf17 100644 --- a/bridge/test/observers/burn-event-observer.spec.ts +++ b/bridge/test/observers/burn-event-observer.spec.ts @@ -73,6 +73,14 @@ describe(BscBurnEventObserver.name, () => { to_opensearch: ReturnType; }; + const mockOpenSearchMigrationClient = new OpenSearchClient( + "https://www.random-url.com", + "auth", + "9c-eth-bridge" + ) as OpenSearchClient & { + to_opensearch: ReturnType; + }; + const mockMonitorStateStore: jest.Mocked = { load: jest.fn(), store: jest.fn(), @@ -148,7 +156,8 @@ describe(BscBurnEventObserver.name, () => { "https://ropsten.etherscan.io", mockIntegration, multiPlanetary, - failureSubscribers + failureSubscribers, + mockOpenSearchMigrationClient ); describe(BscBurnEventObserver.prototype.notify.name, () => { From 7b98353796a3d674f9f120f112cd10d21bd4e4f7 Mon Sep 17 00:00:00 2001 From: carolk-dev Date: Thu, 24 Oct 2024 10:54:45 +0900 Subject: [PATCH 2/2] edit prettier --- bridge/package.json | 2 +- bridge/src/index.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bridge/package.json b/bridge/package.json index bddaa8b..e0fa0c2 100644 --- a/bridge/package.json +++ b/bridge/package.json @@ -9,7 +9,7 @@ "test:aws": "jest --config=./aws.jest.config.js", "test:bridge": "jest --config=./bridge.jest.config.js", "coverage": "jest --coverage --config=./bridge.jest.config.js", - "lint": "eslint src --ext .ts", + "lint": "prettier --check src test", "build": "tsc", "transfer": "node scripts/transfer-script.js transfer" }, diff --git a/bridge/src/index.ts b/bridge/src/index.ts index 60a74ca..eb7a329 100644 --- a/bridge/src/index.ts +++ b/bridge/src/index.ts @@ -97,7 +97,9 @@ process.on("uncaughtException", console.error); const SLACK_WEB_TOKEN: string = Configuration.get("SLACK_WEB_TOKEN"); const FAILURE_SUBSCRIBERS: string = Configuration.get("FAILURE_SUBSCRIBERS"); const OPENSEARCH_ENDPOINT: string = Configuration.get("OPENSEARCH_ENDPOINT"); - const OPENSEARCH_ENDPOINT_MIGRATION: string = Configuration.get("OPENSEARCH_ENDPOINT_MIGRATION"); + const OPENSEARCH_ENDPOINT_MIGRATION: string = Configuration.get( + "OPENSEARCH_ENDPOINT_MIGRATION" + ); const OPENSEARCH_AUTH: string = Configuration.get("OPENSEARCH_AUTH"); const OPENSEARCH_INDEX: string = Configuration.get("OPENSEARCH_INDEX", false) || "9c-eth-bridge";