diff --git a/packages/relay/config/config.yaml b/packages/relay/config/config.yaml index 682db3c..0c4ad5c 100644 --- a/packages/relay/config/config.yaml +++ b/packages/relay/config/config.yaml @@ -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: diff --git a/packages/relay/config/config_test.yaml b/packages/relay/config/config_test.yaml index 24e5b06..524c731 100644 --- a/packages/relay/config/config_test.yaml +++ b/packages/relay/config/config_test.yaml @@ -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: diff --git a/packages/relay/src/common/Config.ts b/packages/relay/src/common/Config.ts index e83f2cb..2da5a42 100644 --- a/packages/relay/src/common/Config.ts +++ b/packages/relay/src/common/Config.ts @@ -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(); @@ -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 { @@ -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, }; } @@ -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 { @@ -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 { diff --git a/packages/relay/src/routers/BridgeRouter.ts b/packages/relay/src/routers/BridgeRouter.ts index 01cc461..88beae8 100644 --- a/packages/relay/src/routers/BridgeRouter.ts +++ b/packages/relay/src/routers/BridgeRouter.ts @@ -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")); } @@ -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")); } @@ -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(); diff --git a/packages/relay/src/routers/LedgerRouter.ts b/packages/relay/src/routers/LedgerRouter.ts index 22ad6c2..f9679f2 100644 --- a/packages/relay/src/routers/LedgerRouter.ts +++ b/packages/relay/src/routers/LedgerRouter.ts @@ -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() })); @@ -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); @@ -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); diff --git a/packages/relay/src/routers/TokenRouter.ts b/packages/relay/src/routers/TokenRouter.ts index 8b179ca..fdab790 100644 --- a/packages/relay/src/routers/TokenRouter.ts +++ b/packages/relay/src/routers/TokenRouter.ts @@ -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, { @@ -475,6 +475,10 @@ export class TokenRouter { equivalentCurrency, }, language, + support: { + bridge: this.config.relay.supportLoyaltyBridge, + exchange: this.config.relay.supportExchange, + }, }) ); } catch (error: any) { diff --git a/packages/relay/src/utils/Errors.ts b/packages/relay/src/utils/Errors.ts index 5870873..c46dafa 100644 --- a/packages/relay/src/utils/Errors.ts +++ b/packages/relay/src/utils/Errors.ts @@ -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"], diff --git a/packages/relay/tspec/09_System.ts b/packages/relay/tspec/09_System.ts new file mode 100644 index 0000000..1b8637a --- /dev/null +++ b/packages/relay/tspec/09_System.ts @@ -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; + }; + }; + }; + }; + }; + }; +}>;