Skip to content

Commit

Permalink
Merge pull request #2 from planetarium/feature/opensearch-migration
Browse files Browse the repository at this point in the history
Feature/opensearch migration
  • Loading branch information
carolk-dev authored Oct 31, 2024
2 parents 54b063e + 7b98353 commit b9fe206
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
12 changes: 11 additions & 1 deletion bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +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_AUTH: string = Configuration.get("OPENSEARCH_AUTH");
const OPENSEARCH_INDEX: string =
Configuration.get("OPENSEARCH_INDEX", false) || "9c-eth-bridge";
Expand Down Expand Up @@ -244,6 +247,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(
Expand Down Expand Up @@ -340,7 +349,8 @@ process.on("uncaughtException", console.error);
BSCSCAN_ROOT_URL,
integration,
multiPlanetary,
FAILURE_SUBSCRIBERS
FAILURE_SUBSCRIBERS,
opensearchMigrationClient
);
const ethereumBurnEventMonitor = new BscBurnEventMonitor(
provider,
Expand Down
34 changes: 33 additions & 1 deletion bridge/src/observers/burn-event-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -65,6 +67,7 @@ export class BscBurnEventObserver
this._integration = integration;
this._multiPlanetary = multiPlanetary;
this._failureSubscribers = failureSubscribers;
this._opensearchMigrationClient = opensearchMigrationClient;
}

async notify(data: {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
{
Expand Down
11 changes: 10 additions & 1 deletion bridge/test/observers/burn-event-observer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ describe(BscBurnEventObserver.name, () => {
to_opensearch: ReturnType<typeof jest.fn>;
};

const mockOpenSearchMigrationClient = new OpenSearchClient(
"https://www.random-url.com",
"auth",
"9c-eth-bridge"
) as OpenSearchClient & {
to_opensearch: ReturnType<typeof jest.fn>;
};

const mockMonitorStateStore: jest.Mocked<IMonitorStateStore> = {
load: jest.fn(),
store: jest.fn(),
Expand Down Expand Up @@ -148,7 +156,8 @@ describe(BscBurnEventObserver.name, () => {
"https://ropsten.etherscan.io",
mockIntegration,
multiPlanetary,
failureSubscribers
failureSubscribers,
mockOpenSearchMigrationClient
);

describe(BscBurnEventObserver.prototype.notify.name, () => {
Expand Down

0 comments on commit b9fe206

Please sign in to comment.