Skip to content

Commit

Permalink
Merge pull request #305 from Junyong-Suh/fee_transfer_tx_could_be_null
Browse files Browse the repository at this point in the history
feat: wrapping event to handle null fee transfer tx
  • Loading branch information
shkangr authored Jun 27, 2024
2 parents 906f93e + 6519637 commit aa77353
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
18 changes: 12 additions & 6 deletions bridge/src/messages/wrapped-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class WrappedEvent extends WrappingEvent {
private readonly _refundTxId: string | null;
private readonly _isWhitelistEvent: boolean;
private readonly _description: string | undefined;
private readonly _feeTransferTxId: TxId;
private readonly _feeTransferTxId: TxId | null;

constructor(
explorerUrl: string,
Expand All @@ -33,7 +33,7 @@ export class WrappedEvent extends WrappingEvent {
refundTxId: TxId | null,
isWhitelistEvent: boolean,
description: string | undefined,
feeTransferTxId: TxId
feeTransferTxId: TxId | null
) {
super(explorerUrl, ncscanUrl, useNcscan, etherscanUrl);

Expand Down Expand Up @@ -64,6 +64,15 @@ export class WrappedEvent extends WrappingEvent {
},
]
: [];
const feeTransferTxIdField =
this._feeTransferTxId !== null
? [
{
title: "9c network transaction (fee transfer)",
value: this.toExplorerUrl(this._feeTransferTxId),
},
]
: [];

let text = "NCG → wNCG event occurred.";
if (this._isWhitelistEvent) text += " (Whitelist Transfer) <!here>";
Expand Down Expand Up @@ -101,10 +110,7 @@ export class WrappedEvent extends WrappingEvent {
title: "fee",
value: this._fee.toString(),
},
{
title: "9c network transaction (fee transfer)",
value: this.toExplorerUrl(this._feeTransferTxId),
},
...feeTransferTxIdField,
...refundFields,
],
fallback: `NCG ${this._sender} → wNCG ${this._recipient}`,
Expand Down
2 changes: 0 additions & 2 deletions bridge/src/messages/wrapping-event.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ChatPostMessageArguments } from "@slack/web-api";
import { Message } from ".";
import { TxId } from "../types/txid";
import { URL } from "url";
import { join, resolve } from "path";
import { ForceOmit } from "../types/force-omit";
import { combineNcExplorerUrl, combineUrl } from "./utils";

Expand Down
4 changes: 3 additions & 1 deletion bridge/src/observers/nine-chronicles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,16 @@ export class NCGTransferredEventObserver
console.log("WNCG mint tx", transactionHash);

// Transfer fee to the fee collector address if any
let feeTransferTxId: string = "No Fee Incurred";
let feeTransferTxId: string | null = null;
if (fee.greaterThan(0)) {
feeTransferTxId = await this._ncgTransfer.transfer(
this._feeCollectorAddress,
fee.toString(),
"I'm bridge and the fee is sent to fee collector."
);
console.log("Fee transfer tx", feeTransferTxId);
} else {
console.log("No fee transfer");
}

const isWhitelistEvent: boolean = accountType !== ACCOUNT_TYPE.GENERAL;
Expand Down
10 changes: 3 additions & 7 deletions bridge/test/messages/__snapshots__/wrapped-event.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Object {
Object {
"author_name": "Bridge Event",
"color": "#b547f5",
"fallback": "NCG 0xCbfC996ad185c61a031f40CeeE80a055e6D83005 → wNCG 0xDac65eCE9CB3E7a538773e08DE31F973233F064f",
"fallback": "NCG 0x27303a4c77c466fc5c631066d64516f1c9a28426 → wNCG 0x50a2aC5E97050bCC3A34dc27858B5DfDF77c4C83",
"fields": Array [
Object {
"title": "9c network transaction",
Expand All @@ -112,11 +112,11 @@ Object {
},
Object {
"title": "sender (NineChronicles)",
"value": "0xCbfC996ad185c61a031f40CeeE80a055e6D83005",
"value": "0x27303a4c77c466fc5c631066d64516f1c9a28426",
},
Object {
"title": "recipient (Ethereum)",
"value": "0xDac65eCE9CB3E7a538773e08DE31F973233F064f",
"value": "0x50a2aC5E97050bCC3A34dc27858B5DfDF77c4C83",
},
Object {
"title": "amount",
Expand All @@ -126,10 +126,6 @@ Object {
"title": "fee",
"value": "1",
},
Object {
"title": "9c network transaction (fee transfer)",
"value": "https://explorer.libplanet.io/9c-internal/transaction?0x9360cd40682a91a71f0afbfac3dd381866cdb319dc01c13531dfe648f8a28bc8",
},
Object {
"title": "description",
"value": "test description",
Expand Down
7 changes: 3 additions & 4 deletions bridge/test/messages/wrapped-event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,16 @@ describe("WrappedEvent", () => {
const NCSCAN_URL = "https://9cscan.com";
const USE_NCSCAN_URL = false;
const ETHERSCAN_URL = "https://ropsten.etherscan.io";
const SENDER = "0xCbfC996ad185c61a031f40CeeE80a055e6D83005";
const RECIPIENT = "0xDac65eCE9CB3E7a538773e08DE31F973233F064f";
const SENDER = "0x27303a4c77c466fc5c631066d64516f1c9a28426";
const RECIPIENT = "0x50a2aC5E97050bCC3A34dc27858B5DfDF77c4C83";
const AMOUNT = "200";
const ETHEREUM_TRANSACTION_HASH =
"0x9360cd40682a91a71f0afbfac3dd381866cdb319dc01c13531dfe648f8a28bc8";
const NINE_CHRONICLES_TX_ID =
"3409cdbaa24ec6f7c8d2c0f636325a2b2e9611e5e6df5c593cfcd299860d8044";
const FEE = new Decimal(1);
const IS_WHITELIST_EVENT = true;
const FEE_TRANSFER_TX_ID =
"0x9360cd40682a91a71f0afbfac3dd381866cdb319dc01c13531dfe648f8a28bc8";
const FEE_TRANSFER_TX_ID = null;
expect(
new WrappedEvent(
EXPLORER_URL,
Expand Down

0 comments on commit aa77353

Please sign in to comment.