Skip to content

Commit

Permalink
[Relay] Separates timeout time by settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Nov 8, 2023
1 parent d685986 commit 02cc315
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ relay:
accessKey: "${ACCESS_KEY}"
certifier: "${CERTIFIER_KEY}"
callbackEndpoint: "${CALLBACK_ENDPOINT}"
paymentTimeoutSecond: 45

contracts:
tokenAddress : "${TOKEN_CONTRACT_ADDRESS}"
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 @@ -40,6 +40,7 @@ relay:
accessKey: "${ACCESS_KEY}"
certifier: "${CERTIFIER_KEY}"
callbackEndpoint: "${CALLBACK_ENDPOINT}"
paymentTimeoutSecond: 45

contracts:
tokenAddress : "${TOKEN_CONTRACT_ADDRESS}"
Expand Down
5 changes: 5 additions & 0 deletions packages/relay/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export class RelayConfig implements IRelayConfig {
public accessKey: string;
public certifierKey: string;
public callbackEndpoint: string;
public paymentTimeoutSecond: number;

/**
* Constructor
Expand All @@ -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;
}

/**
Expand All @@ -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,
};
}

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -506,6 +510,7 @@ export interface IRelayConfig {
accessKey: string;
certifierKey: string;
callbackEndpoint: string;
paymentTimeoutSecond: number;
}

export interface IContractsConfig {
Expand Down
12 changes: 4 additions & 8 deletions packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 02cc315

Please sign in to comment.