Skip to content

Commit

Permalink
Add loyalty wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Mar 6, 2024
1 parent 5a0f842 commit 2fd1a81
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ relay:
forcedCloseSecond: 300
expoAccessToken: "${EXPO_ACCESS_TOKEN}"
relayEndpoint: "${RELAY_ENDPOINT}"
storePurchaseWaitingSecond: 694800
encryptKey: "${RELAY_ENCRYPT_KEY}"

contracts:
Expand Down
1 change: 0 additions & 1 deletion packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ relay:
forcedCloseSecond: 300
expoAccessToken: "${EXPO_ACCESS_TOKEN}"
relayEndpoint: "${RELAY_ENDPOINT}"
storePurchaseWaitingSecond: 694800
encryptKey: "${RELAY_ENCRYPT_KEY}"

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

/**
Expand All @@ -328,7 +327,6 @@ export class RelayConfig implements IRelayConfig {
this.forcedCloseSecond = defaults.forcedCloseSecond;
this.expoAccessToken = defaults.expoAccessToken;
this.relayEndpoint = defaults.relayEndpoint;
this.storePurchaseWaitingSecond = defaults.storePurchaseWaitingSecond;
this.encryptKey = defaults.encryptKey;
}

Expand All @@ -352,7 +350,6 @@ export class RelayConfig implements IRelayConfig {
forcedCloseSecond: 300,
expoAccessToken: "",
relayEndpoint: "",
storePurchaseWaitingSecond: 694800,
encryptKey: "",
};
}
Expand All @@ -371,8 +368,6 @@ export class RelayConfig implements IRelayConfig {
if (config.forcedCloseSecond !== undefined) this.forcedCloseSecond = config.forcedCloseSecond;
if (config.expoAccessToken !== undefined) this.expoAccessToken = config.expoAccessToken;
if (config.relayEndpoint !== undefined) this.relayEndpoint = config.relayEndpoint;
if (config.storePurchaseWaitingSecond !== undefined)
this.storePurchaseWaitingSecond = config.storePurchaseWaitingSecond;
if (config.encryptKey !== undefined) this.encryptKey = config.encryptKey;
}
}
Expand Down Expand Up @@ -614,7 +609,6 @@ export interface IRelayConfig {
forcedCloseSecond: number;
expoAccessToken: string;
relayEndpoint: string;
storePurchaseWaitingSecond: number;
encryptKey: string;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/relay/src/routers/StorePurchaseRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class StorePurchaseRouter {
[
body("purchaseId").exists().not().isEmpty(),
body("timestamp").exists().isNumeric(),
body("waiting").exists().isNumeric(),
body("account").exists().trim().isEthereumAddress(),
body("phone")
.exists()
Expand Down Expand Up @@ -261,6 +262,7 @@ export class StorePurchaseRouter {
const purchaseData: IStorePurchaseData = {
purchaseId: String(req.body.purchaseId).trim(),
timestamp: BigInt(String(req.body.timestamp).trim()),
waiting: BigInt(String(req.body.waiting).trim()),
account: String(req.body.account).trim(),
loyaltyType: ContractLoyaltyType.POINT,
currency: String(req.body.currency).trim(),
Expand Down
6 changes: 2 additions & 4 deletions packages/relay/src/scheduler/StorePurchaseScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ContractUtils } from "../utils/ContractUtils";
import { Scheduler } from "./Scheduler";

import * as hre from "hardhat";
import { BigNumber } from "ethers";

/**
* Creates blocks at regular intervals and stores them in IPFS and databases.
Expand Down Expand Up @@ -70,10 +71,7 @@ export class StorePurchaseScheduler extends Scheduler {
const stored = await (await this.getProviderContract()).purchasesOf(purchase.purchaseId);
if (stored) {
await this.storage.doneStorePurchase(purchase.purchaseId);
} else if (
purchase.timestamp <
ContractUtils.getTimeStampBigInt() - BigInt(this.config.relay.storePurchaseWaitingSecond)
) {
} else if (purchase.timestamp + purchase.waiting + BigInt(60) < ContractUtils.getTimeStampBigInt()) {
await this.storage.doneStorePurchase(purchase.purchaseId);
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/relay/src/storage/RelayStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ export class RelayStorage extends Storage {
this.queryForMapper("purchase", "postStorePurchase", {
purchaseId: data.purchaseId,
timestamp: data.timestamp.toString(),
waiting: data.waiting.toString(),
account: data.account.toLowerCase(),
loyaltyType: data.loyaltyType,
currency: data.currency,
Expand Down Expand Up @@ -734,6 +735,7 @@ export class RelayStorage extends Storage {
return {
purchaseId: m.purchaseId,
timestamp: BigInt(m.timestamp.toString()),
waiting: BigInt(m.waiting.toString()),
account: m.account,
loyaltyType: m.loyaltyType,
currency: m.currency,
Expand Down Expand Up @@ -789,6 +791,7 @@ export class RelayStorage extends Storage {
return {
account: m.account,
timestamp: BigInt(m.timestamp.toString()),
waiting: BigInt(m.waiting.toString()),
loyaltyType: m.loyaltyType,
currency: m.currency,
providePoint: BigNumber.from(m.providePoint.toString()).mul(GWI_UNIT),
Expand Down
4 changes: 4 additions & 0 deletions packages/relay/src/storage/mapper/purchase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(
"purchaseId" ,
"timestamp" ,
"waiting" ,
"account" ,
"loyaltyType" ,
"currency" ,
Expand All @@ -21,6 +22,7 @@
(
#{purchaseId} ,
#{timestamp} ,
#{waiting} ,
#{account} ,
#{loyaltyType} ,
#{currency} ,
Expand Down Expand Up @@ -56,6 +58,7 @@
SELECT
"purchaseId",
"timestamp",
"waiting",
"account",
"currency",
"loyaltyType",
Expand Down Expand Up @@ -83,6 +86,7 @@
SELECT
"purchaseId",
"timestamp",
"waiting",
"shopId",
"shopCurrency" as "currency",
"shopProvidedAmount" as "providedAmount"
Expand Down
1 change: 1 addition & 0 deletions packages/relay/src/storage/mapper/table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
(
"purchaseId" VARCHAR(66) NOT NULL,
"timestamp" BIGINT NOT NULL,
"waiting" BIGINT NOT NULL,
"account" VARCHAR(42) NOT NULL,
"loyaltyType" INTEGER NOT NULL,
"currency" VARCHAR(12) NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions packages/relay/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export interface IGraphPageInfo {
export interface IStorePurchaseData {
purchaseId: string;
timestamp: bigint;
waiting: bigint;
account: string;
loyaltyType: number;
currency: string;
Expand Down

0 comments on commit 2fd1a81

Please sign in to comment.