From 8db287768c8692beb3e0b930a7ec20638ea45fd5 Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Wed, 8 Nov 2023 10:27:35 +0900 Subject: [PATCH] [Relay] Separates timeout time by settings --- packages/relay/config/config.yaml | 1 + packages/relay/config/config_test.yaml | 1 + packages/relay/src/common/Config.ts | 5 +++++ packages/relay/src/routers/PaymentRouter.ts | 12 ++++-------- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/relay/config/config.yaml b/packages/relay/config/config.yaml index c5dba9ac..b5a17bf6 100644 --- a/packages/relay/config/config.yaml +++ b/packages/relay/config/config.yaml @@ -40,6 +40,7 @@ relay: accessKey: "${ACCESS_KEY}" certifier: "${CERTIFIER_KEY}" callbackEndpoint: "${CALLBACK_ENDPOINT}" + paymentTimeoutSecond: 45 contracts: tokenAddress : "${TOKEN_CONTRACT_ADDRESS}" diff --git a/packages/relay/config/config_test.yaml b/packages/relay/config/config_test.yaml index c5dba9ac..b5a17bf6 100644 --- a/packages/relay/config/config_test.yaml +++ b/packages/relay/config/config_test.yaml @@ -40,6 +40,7 @@ relay: accessKey: "${ACCESS_KEY}" certifier: "${CERTIFIER_KEY}" callbackEndpoint: "${CALLBACK_ENDPOINT}" + paymentTimeoutSecond: 45 contracts: tokenAddress : "${TOKEN_CONTRACT_ADDRESS}" diff --git a/packages/relay/src/common/Config.ts b/packages/relay/src/common/Config.ts index c1ef2440..cc7fb1db 100644 --- a/packages/relay/src/common/Config.ts +++ b/packages/relay/src/common/Config.ts @@ -282,6 +282,7 @@ export class RelayConfig implements IRelayConfig { public accessKey: string; public certifierKey: string; public callbackEndpoint: string; + public paymentTimeoutSecond: number; /** * Constructor @@ -293,6 +294,7 @@ export class RelayConfig implements IRelayConfig { this.accessKey = defaults.accessKey; this.certifierKey = defaults.certifierKey; this.callbackEndpoint = defaults.callbackEndpoint; + this.paymentTimeoutSecond = defaults.paymentTimeoutSecond; } /** @@ -310,6 +312,7 @@ export class RelayConfig implements IRelayConfig { accessKey: process.env.ACCESS_SECRET || "", certifierKey: process.env.CERTIFIER_KEY || "", callbackEndpoint: process.env.CALLBACK_ENDPOINT || "", + paymentTimeoutSecond: 45, }; } @@ -322,6 +325,7 @@ export class RelayConfig implements IRelayConfig { if (config.accessKey !== undefined) this.accessKey = config.accessKey; if (config.certifierKey !== undefined) this.certifierKey = config.certifierKey; if (config.callbackEndpoint !== undefined) this.callbackEndpoint = config.callbackEndpoint; + if (config.paymentTimeoutSecond !== undefined) this.paymentTimeoutSecond = config.paymentTimeoutSecond; } } @@ -506,6 +510,7 @@ export interface IRelayConfig { accessKey: string; certifierKey: string; callbackEndpoint: string; + paymentTimeoutSecond: number; } export interface IContractsConfig { diff --git a/packages/relay/src/routers/PaymentRouter.ts b/packages/relay/src/routers/PaymentRouter.ts index 76dffec2..880abbe1 100644 --- a/packages/relay/src/routers/PaymentRouter.ts +++ b/packages/relay/src/routers/PaymentRouter.ts @@ -825,8 +825,7 @@ export class PaymentRouter { totalValue: item.totalValue.toString(), }; - const now = ContractUtils.getTimeStamp(); - if (now - item.createTimestamp > 60) { + if (ContractUtils.getTimeStamp() - item.cancelTimestamp > this._config.relay.paymentTimeoutSecond) { const message = "Timeout period expired"; res.status(200).json( this.makeResponseData(404, undefined, { @@ -1060,8 +1059,7 @@ export class PaymentRouter { totalValue: item.totalValue.toString(), }; - const now = ContractUtils.getTimeStamp(); - if (now - item.createTimestamp > 60) { + if (ContractUtils.getTimeStamp() - item.createTimestamp > this._config.relay.paymentTimeoutSecond) { const message = "Timeout period expired"; res.status(200).json( this.makeResponseData(404, undefined, { @@ -1288,8 +1286,7 @@ export class PaymentRouter { totalValue: item.totalValue.toString(), }; - const now = ContractUtils.getTimeStamp(); - if (now - item.cancelTimestamp > 60) { + if (ContractUtils.getTimeStamp() - item.cancelTimestamp > this._config.relay.paymentTimeoutSecond) { const message = "Timeout period expired"; res.status(200).json( this.makeResponseData(404, undefined, { @@ -1502,8 +1499,7 @@ export class PaymentRouter { totalValue: item.totalValue.toString(), }; - const now = ContractUtils.getTimeStamp(); - if (now - item.cancelTimestamp > 60) { + if (ContractUtils.getTimeStamp() - item.cancelTimestamp > this._config.relay.paymentTimeoutSecond) { const message = "Timeout period expired"; res.status(200).json( this.makeResponseData(404, undefined, {