-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b98353
commit acc51e4
Showing
11 changed files
with
273 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
module.exports = { | ||
name: "bridge", | ||
displayName: "bridge", | ||
name: "bridge", | ||
displayName: "bridge", | ||
|
||
// NOTE: if you don't set this correctly then when you reference | ||
// it later in a path string you'll get a confusing error message. | ||
// It says something like' Module <rootDir>/config/polyfills.js in | ||
// the setupFiles option was not found.' | ||
rootDir: "./../", | ||
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/test/aws-dependent"], | ||
testMatch: ["**/*/*.spec.{ts,tsx}"], | ||
coverageDirectory: "coverage", | ||
coverageReporters: ["lcov"], | ||
// NOTE: if you don't set this correctly then when you reference | ||
// it later in a path string you'll get a confusing error message. | ||
// It says something like' Module <rootDir>/config/polyfills.js in | ||
// the setupFiles option was not found.' | ||
rootDir: "./../", | ||
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/test/aws-dependent"], | ||
testMatch: ["**/*/*.spec.{ts,tsx}"], | ||
coverageDirectory: "./bridge/coverage", | ||
coverageReporters: ["lcov"], | ||
|
||
// etc... | ||
// etc... | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import { TransactionStatus } from "../types/transaction-status"; | ||
|
||
export interface ExchangeHistory { | ||
network: string; | ||
tx_id: string; | ||
sender: string; | ||
recipient: string; | ||
timestamp: string; | ||
amount: number; | ||
status: TransactionStatus; | ||
} | ||
|
||
export interface IExchangeHistoryStore { | ||
put(history: ExchangeHistory): Promise<void>; | ||
exist(tx_id: string): Promise<boolean>; | ||
updateStatus( | ||
tx_id: string, | ||
status: TransactionStatus.COMPLETED | TransactionStatus.FAILED | ||
): Promise<void>; | ||
|
||
transferredAmountInLast24Hours( | ||
network: string, | ||
sender: string | ||
): Promise<number>; | ||
|
||
getPendingTransactions(): Promise<ExchangeHistory[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { ChatPostMessageArguments } from "@slack/web-api"; | ||
import { Message } from "."; | ||
import { ForceOmit } from "../types/force-omit"; | ||
import { ExchangeHistory } from "../interfaces/exchange-history-store"; | ||
import { combineUrl } from "../messages/utils"; | ||
import { MultiPlanetary } from "../multi-planetary"; | ||
|
||
export class PendingTransactionRetryMessage implements Message { | ||
private readonly _bscScanUrl: string; | ||
private readonly _multiPlanetary: MultiPlanetary; | ||
|
||
constructor( | ||
private readonly transactions: ExchangeHistory[], | ||
private readonly multiPlanetary: MultiPlanetary, | ||
bscScanUrl: string = process.env.BSCSCAN_URL || "https://bscscan.com" | ||
) { | ||
this._bscScanUrl = bscScanUrl; | ||
this._multiPlanetary = multiPlanetary; | ||
} | ||
|
||
render(): ForceOmit<Partial<ChatPostMessageArguments>, "channel"> { | ||
console.log(this.transactions); | ||
if (this.transactions) { | ||
return { | ||
text: `${this.transactions.length} Pending Transactions Found`, | ||
attachments: this.transactions.map((tx) => ({ | ||
author_name: "[BSC] wNCG → NCG pending event", | ||
color: "#ff0033", | ||
fields: [ | ||
{ | ||
title: "BSC transaction", | ||
value: combineUrl(this._bscScanUrl, `/tx/${tx.tx_id}`), | ||
}, | ||
{ | ||
title: "Planet Name", | ||
value: this._multiPlanetary.getRequestPlanetName(tx.recipient), | ||
}, | ||
{ | ||
title: "Sender(BSC)", | ||
value: tx.sender, | ||
}, | ||
{ | ||
title: "Recipient(9c)", | ||
value: tx.recipient, | ||
}, | ||
{ | ||
title: "Amount", | ||
value: tx.amount.toString(), | ||
}, | ||
{ | ||
title: "Timestamp", | ||
value: tx.timestamp, | ||
}, | ||
], | ||
})), | ||
}; | ||
} | ||
|
||
return { | ||
text: "No pending transactions", | ||
attachments: [ | ||
{ | ||
author_name: "BSC Bridge Restarted", | ||
color: "#ffcc00", | ||
}, | ||
], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { IExchangeHistoryStore } from "./interfaces/exchange-history-store"; | ||
import { INCGTransfer } from "./interfaces/ncg-transfer"; | ||
import { MultiPlanetary } from "./multi-planetary"; | ||
import { ISlackMessageSender } from "./interfaces/slack-message-sender"; | ||
import { PendingTransactionRetryMessage } from "./messages/pending-transaction-retry-message"; | ||
import { TransactionStatus } from "./types/transaction-status"; | ||
|
||
export class PendingTransactionRetryHandler { | ||
constructor( | ||
private readonly _exchangeHistoryStore: IExchangeHistoryStore, | ||
private readonly _ncgTransfer: INCGTransfer, | ||
private readonly _multiPlanetary: MultiPlanetary, | ||
private readonly _slackMessageSender: ISlackMessageSender | ||
) {} | ||
|
||
async retryPendingTransactions(): Promise<void> { | ||
const pendingTransactions = | ||
await this._exchangeHistoryStore.getPendingTransactions(); | ||
|
||
if (pendingTransactions.length > 0) { | ||
await this._slackMessageSender.sendMessage( | ||
new PendingTransactionRetryMessage( | ||
pendingTransactions, | ||
this._multiPlanetary | ||
) | ||
); | ||
|
||
for (const tx of pendingTransactions) { | ||
await this._exchangeHistoryStore.updateStatus( | ||
tx.tx_id, | ||
TransactionStatus.FAILED | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum TransactionStatus { | ||
PENDING = "pending", | ||
COMPLETED = "completed", | ||
FAILED = "failed", | ||
} |
Oops, something went wrong.