Skip to content

Commit

Permalink
Improve to select whether feature is supported or not
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Sep 20, 2024
1 parent 22bb0d3 commit ea11a3d
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 16 deletions.
4 changes: 3 additions & 1 deletion packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ relay:
relayEndpoint: "${RELAY_ENDPOINT}"
encryptKey: "${RELAY_ENCRYPT_KEY}"
testMode: ${RELAY_TEST_MODE}
bridgeActiveStatus: true
allowedShopIdPrefix: "0x0001"
initialBalanceOfProvider: 50000
paymentSigners:
- "0xBd8a48B11a576150E8772D6E9B658c60317CAdbc"
supportChainBridge: true
supportLoyaltyBridge: true;
supportExchange: true;

contracts:
sideChain:
Expand Down
4 changes: 3 additions & 1 deletion packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ relay:
relayEndpoint: "${RELAY_ENDPOINT}"
encryptKey: "${RELAY_ENCRYPT_KEY}"
testMode: ${RELAY_TEST_MODE}
bridgeActiveStatus: true
allowedShopIdPrefix: "0x0001"
initialBalanceOfProvider: 50000
paymentSigners:
- "0xBd8a48B11a576150E8772D6E9B658c60317CAdbc"
supportChainBridge: true
supportLoyaltyBridge: true;
supportExchange: true;

contracts:
sideChain:
Expand Down
24 changes: 18 additions & 6 deletions packages/relay/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ export class RelayConfig implements IRelayConfig {
public relayEndpoint: string;
public encryptKey: string;
public testMode: boolean;
public bridgeActiveStatus: boolean;
public allowedShopIdPrefix: string;
public initialBalanceOfProvider: number;
public supportChainBridge: boolean;
public supportLoyaltyBridge: boolean;
public supportExchange: boolean;

constructor() {
const defaults = RelayConfig.defaultValue();
Expand All @@ -229,9 +231,11 @@ export class RelayConfig implements IRelayConfig {
this.relayEndpoint = defaults.relayEndpoint;
this.encryptKey = defaults.encryptKey;
this.testMode = defaults.testMode;
this.bridgeActiveStatus = defaults.bridgeActiveStatus;
this.allowedShopIdPrefix = defaults.allowedShopIdPrefix;
this.initialBalanceOfProvider = defaults.initialBalanceOfProvider;
this.supportChainBridge = defaults.supportChainBridge;
this.supportLoyaltyBridge = defaults.supportLoyaltyBridge;
this.supportExchange = defaults.supportExchange;
}

public static defaultValue(): IRelayConfig {
Expand All @@ -254,9 +258,11 @@ export class RelayConfig implements IRelayConfig {
relayEndpoint: "",
encryptKey: "",
testMode: false,
bridgeActiveStatus: true,
allowedShopIdPrefix: "0x0001",
initialBalanceOfProvider: 50000,
supportChainBridge: true,
supportLoyaltyBridge: true,
supportExchange: true,
};
}

Expand All @@ -273,11 +279,15 @@ 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";
if (config.allowedShopIdPrefix !== undefined) this.allowedShopIdPrefix = config.allowedShopIdPrefix;
if (config.initialBalanceOfProvider !== undefined)
this.initialBalanceOfProvider = config.initialBalanceOfProvider;
if (config.supportChainBridge !== undefined)
this.supportChainBridge = config.supportChainBridge.toString().toLowerCase() === "true";
if (config.supportLoyaltyBridge !== undefined)
this.supportLoyaltyBridge = config.supportLoyaltyBridge.toString().toLowerCase() === "true";
if (config.supportExchange !== undefined)
this.supportExchange = config.supportExchange.toString().toLowerCase() === "true";
}

public isPaymentSigner(account: string): boolean {
Expand Down Expand Up @@ -506,9 +516,11 @@ export interface IRelayConfig {
relayEndpoint: string;
encryptKey: string;
testMode: boolean;
bridgeActiveStatus: boolean;
allowedShopIdPrefix: string;
initialBalanceOfProvider: number;
supportChainBridge: boolean;
supportLoyaltyBridge: boolean;
supportExchange: boolean;
}

export interface IContractsConfig {
Expand Down
8 changes: 6 additions & 2 deletions packages/relay/src/routers/BridgeRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ 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) {
if (!this.config.relay.supportChainBridge) {
return res.status(200).json(ResponseMessage.getErrorMessage("3001"));
}

Expand Down Expand Up @@ -183,7 +183,7 @@ 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) {
if (!this.config.relay.supportChainBridge) {
return res.status(200).json(ResponseMessage.getErrorMessage("3001"));
}

Expand All @@ -192,6 +192,10 @@ export class BridgeRouter {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

if (!this.config.relay.supportLoyaltyBridge) {
return res.status(200).json(ResponseMessage.getErrorMessage("2010", { validation: errors.array() }));
}

const signerItem = await this.getRelaySigner(this.contractManager.mainChainProvider);
try {
const account: string = String(req.body.account).trim();
Expand Down
12 changes: 8 additions & 4 deletions packages/relay/src/routers/LedgerRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export class LedgerRouter {
private async exchangePointToToken(req: express.Request, res: express.Response) {
logger.http(`POST /v1/ledger/exchangePointToToken ${req.ip}:${JSON.stringify(req.body)}`);

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

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
Expand Down Expand Up @@ -619,8 +623,8 @@ 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"));
if (!this.config.relay.supportLoyaltyBridge) {
return res.status(200).json(ResponseMessage.getErrorMessage("3002"));
}

const errors = validationResult(req);
Expand Down Expand Up @@ -674,8 +678,8 @@ 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"));
if (!this.config.relay.supportLoyaltyBridge) {
return res.status(200).json(ResponseMessage.getErrorMessage("3002"));
}

const errors = validationResult(req);
Expand Down
6 changes: 5 additions & 1 deletion packages/relay/src/routers/TokenRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export class TokenRouter {
const tokenSymbol = await this.contractManager.sideTokenContract.symbol();
const precision = tokenSymbol === "ACC" ? 2 : 0;
const equivalentCurrency = tokenSymbol === "ACC" ? "PHP" : "KRW";
const language = tokenSymbol === "ACC" ? "en" : "kr";
const language = tokenSymbol === "ACC" ? "en" : "ko";
this.metrics.add("success", 1);
return res.status(200).json(
this.makeResponseData(0, {
Expand All @@ -475,6 +475,10 @@ export class TokenRouter {
equivalentCurrency,
},
language,
support: {
bridge: this.config.relay.supportLoyaltyBridge,
exchange: this.config.relay.supportExchange,
},
})
);
} catch (error: any) {
Expand Down
4 changes: 3 additions & 1 deletion packages/relay/src/utils/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ 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"],
["3001", "Chain Bridge functionality is not yet available"],
["3002", "Loyalty Bridge functionality is not yet available"],
["3003", "The ability to exchange points for tokens is not supported"],
["3072", "The shopId is invalid"],
["4000", "Denied by user"],
["5000", "Smart Contract Error"],
Expand Down
67 changes: 67 additions & 0 deletions packages/relay/tspec/09_System.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Tspec } from "tspec";
import { ResultCode } from "./types";

export type SystemInfoApiSpec = Tspec.DefineApiSpec<{
tags: ["System Info"];
paths: {
"/v1/chain/main/info": {
get: {
summary: "Provide information of System";
responses: {
200: {
/**
* Result Code
* @example 0
*/
code: ResultCode;
data: {
token: {
/**
* Token Symbol
* @example "ACC"
*/
symbol: string;
};
point: {
/**
* Decimals
* @example 2"
*/
precision: string;
/**
* Symbol of a currency of the same value
* @example "PHP"
*/
equivalentCurrency: string;
};
/**
* Default Language for the System
* @example "en"
*/
language: string;
support: {
/**
* Moving Assets Using Bridges
* @example true
*/
bridge: boolean;
/**
* Exchange Points for Tokens
* @example true
*/
exchange: boolean;
};
};
error?: {
/**
* Error Message
* @example "Failed to check the validity of parameters"
*/
message: string;
};
};
};
};
};
};
}>;

0 comments on commit ea11a3d

Please sign in to comment.