Skip to content

Commit

Permalink
Add the bridge's active status to the execution condition
Browse files Browse the repository at this point in the history
  • Loading branch information
danial303065 authored and MichaelKim20 committed Aug 7, 2024
1 parent 5a09052 commit f87530f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ relay:
relayEndpoint: "${RELAY_ENDPOINT}"
encryptKey: "${RELAY_ENCRYPT_KEY}"
testMode: ${RELAY_TEST_MODE}
bridgeActiveStatus: true

contracts:
sideChain:
Expand Down
1 change: 1 addition & 0 deletions packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ relay:
relayEndpoint: "${RELAY_ENDPOINT}"
encryptKey: "${RELAY_ENCRYPT_KEY}"
testMode: ${RELAY_TEST_MODE}
bridgeActiveStatus: true

contracts:
sideChain:
Expand Down
6 changes: 6 additions & 0 deletions packages/relay/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export class RelayConfig implements IRelayConfig {
public relayEndpoint: string;
public encryptKey: string;
public testMode: boolean;
public bridgeActiveStatus: boolean;

constructor() {
const defaults = RelayConfig.defaultValue();
Expand All @@ -224,6 +225,7 @@ export class RelayConfig implements IRelayConfig {
this.relayEndpoint = defaults.relayEndpoint;
this.encryptKey = defaults.encryptKey;
this.testMode = defaults.testMode;
this.bridgeActiveStatus = defaults.bridgeActiveStatus;
}

public static defaultValue(): IRelayConfig {
Expand All @@ -245,6 +247,7 @@ export class RelayConfig implements IRelayConfig {
relayEndpoint: "",
encryptKey: "",
testMode: false,
bridgeActiveStatus: true,
};
}

Expand All @@ -260,6 +263,8 @@ export class RelayConfig implements IRelayConfig {
if (config.relayEndpoint !== undefined) this.relayEndpoint = config.relayEndpoint;
if (config.encryptKey !== undefined) this.encryptKey = config.encryptKey;
if (config.testMode !== undefined) this.testMode = config.testMode.toString().toLowerCase() === "true";
if (config.bridgeActiveStatus !== undefined)
this.bridgeActiveStatus = config.bridgeActiveStatus.toString().toLowerCase() === "true";
}
}

Expand Down Expand Up @@ -482,6 +487,7 @@ export interface IRelayConfig {
relayEndpoint: string;
encryptKey: string;
testMode: boolean;
bridgeActiveStatus: boolean;
}

export interface IContractsConfig {
Expand Down
8 changes: 8 additions & 0 deletions packages/relay/src/routers/BridgeRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export class BridgeRouter {
private async bridge_withdraw(req: express.Request, res: express.Response) {
logger.http(`POST /v1/bridge/withdraw ${req.ip}:${JSON.stringify(req.body)}`);

if (!this.config.relay.bridgeActiveStatus) {
return res.status(200).json(ResponseMessage.getErrorMessage("3001"));
}

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
Expand Down Expand Up @@ -179,6 +183,10 @@ export class BridgeRouter {
private async bridge_deposit(req: express.Request, res: express.Response) {
logger.http(`POST /v1/bridge/deposit ${req.ip}:${JSON.stringify(req.body)}`);

if (!this.config.relay.bridgeActiveStatus) {
return res.status(200).json(ResponseMessage.getErrorMessage("3001"));
}

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
Expand Down
8 changes: 8 additions & 0 deletions packages/relay/src/routers/LedgerRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ export class LedgerRouter {
private async ledger_withdraw_via_bridge(req: express.Request, res: express.Response) {
logger.http(`POST /v1/ledger/withdraw_via_bridge ${req.ip}:${JSON.stringify(req.body)}`);

if (!this.config.relay.bridgeActiveStatus) {
return res.status(200).json(ResponseMessage.getErrorMessage("3001"));
}

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
Expand Down Expand Up @@ -670,6 +674,10 @@ export class LedgerRouter {
private async ledger_deposit_via_bridge(req: express.Request, res: express.Response) {
logger.http(`POST /v1/ledger/deposit_via_bridge ${req.ip}:${JSON.stringify(req.body)}`);

if (!this.config.relay.bridgeActiveStatus) {
return res.status(200).json(ResponseMessage.getErrorMessage("3001"));
}

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
Expand Down
1 change: 1 addition & 0 deletions packages/relay/src/utils/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class ResponseMessage {
["2030", "This payment cannot be closed before it is approved"],
["2033", "The task ID is not exist"],
["2040", "The status code for this task cannot be approved"],
["3001", "Bridge functionality is not yet available"],
["4000", "Denied by user"],
["5000", "Smart Contract Error"],
["6000", "Server Error"],
Expand Down

0 comments on commit f87530f

Please sign in to comment.