Skip to content

Commit

Permalink
[Relay] Clean up import
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Apr 30, 2024
1 parent bc28e6a commit 0664fb3
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 97 deletions.
53 changes: 0 additions & 53 deletions packages/relay/src/routers/BridgeRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Metrics } from "../metrics/Metrics";
import { WebService } from "../service/WebService";
import { GraphStorage } from "../storage/GraphStorage";
import { RelayStorage } from "../storage/RelayStorage";
import { ContractLoyaltyType } from "../types";
import { ContractUtils } from "../utils/ContractUtils";
import { ResponseMessage } from "../utils/Errors";
import { Validation } from "../validation";
Expand Down Expand Up @@ -110,58 +109,6 @@ export class BridgeRouter {
);
}

private async balance_account(req: express.Request, res: express.Response) {
logger.http(`GET /v1/ledger/balance/account/:account ${req.ip}:${JSON.stringify(req.params)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

try {
let account: string = String(req.params.account).trim();
if (ContractUtils.isTemporaryAccount(account)) {
const realAccount = await this.storage.getRealAccount(account);
if (realAccount === undefined) {
return res.status(200).json(ResponseMessage.getErrorMessage("2004"));
} else {
account = realAccount;
}
}
const loyaltyType = await this.contractManager.sideLedgerContract.loyaltyTypeOf(account);
if (loyaltyType === ContractLoyaltyType.POINT) {
const balance = await this.contractManager.sideLedgerContract.pointBalanceOf(account);
const value = BigNumber.from(balance);
this.metrics.add("success", 1);
return res.status(200).json(
this.makeResponseData(0, {
account,
loyaltyType,
point: { balance: balance.toString(), value: value.toString() },
token: { balance: "0", value: "0" },
})
);
} else {
const balance = await this.contractManager.sideLedgerContract.tokenBalanceOf(account);
const value = await this.contractManager.sideCurrencyRateContract.convertTokenToPoint(balance);
this.metrics.add("success", 1);
return res.status(200).json(
this.makeResponseData(0, {
account,
loyaltyType,
point: { balance: "0", value: "0" },
token: { balance: balance.toString(), value: value.toString() },
})
);
}
} catch (error: any) {
const msg = ResponseMessage.getEVMErrorMessage(error);
logger.error(`GET /v1/ledger/balance/account/:account : ${msg.error.message}`);
this.metrics.add("failure", 1);
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
}

private async getDepositIdMainChain(account: string): Promise<string> {
while (true) {
const id = ContractUtils.getRandomId(account);
Expand Down
1 change: 0 additions & 1 deletion packages/relay/src/routers/DefaultRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { WebService } from "../service/WebService";

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

export class DefaultRouter {
private web_service: WebService;
Expand Down
3 changes: 1 addition & 2 deletions packages/relay/src/routers/ETCRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { RelayStorage } from "../storage/RelayStorage";
import { ContractUtils } from "../utils/ContractUtils";
import { ResponseMessage } from "../utils/Errors";

import { body, validationResult } from "express-validator";

import express from "express";
import { body, validationResult } from "express-validator";

export class ETCRouter {
private web_service: WebService;
Expand Down
14 changes: 5 additions & 9 deletions packages/relay/src/routers/HistoryRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { Metrics } from "../metrics/Metrics";
import { WebService } from "../service/WebService";
import { GraphStorage } from "../storage/GraphStorage";
import { RelayStorage } from "../storage/RelayStorage";
import { ResponseMessage } from "../utils/Errors";
import { ContractUtils } from "../utils/ContractUtils";
import { ResponseMessage } from "../utils/Errors";

import { body, param, query, validationResult } from "express-validator";

// tslint:disable-next-line:no-implicit-dependencies
import { AddressZero } from "@ethersproject/constants";

import { ethers } from "ethers";
import express from "express";

import { BigNumber, ethers } from "ethers";
import { Validation } from "../validation";
import { toChecksumAddress } from "ethereumjs-util";
import { param, query, validationResult } from "express-validator";
import { PhoneNumberFormat, PhoneNumberUtil } from "google-libphonenumber";

export class HistoryRouter {
Expand Down Expand Up @@ -219,7 +215,7 @@ export class HistoryRouter {
if (pageSize > 50) pageSize = 50;
let pageNumber = Number(req.query.pageNumber);
if (pageNumber < 1) pageNumber = 1;
let pageType = Number(req.query.pageType);
const pageType = Number(req.query.pageType);

try {
const histories = await this.graph_sidechain.getAccountLedgerHistory(
Expand Down
1 change: 0 additions & 1 deletion packages/relay/src/routers/LedgerRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Validation } from "../validation";

// tslint:disable-next-line:no-implicit-dependencies
import { AddressZero } from "@ethersproject/constants";

import { BigNumber, ethers } from "ethers";
import express from "express";
import { body, param, query, validationResult } from "express-validator";
Expand Down
8 changes: 3 additions & 5 deletions packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ import { ResponseMessage } from "../utils/Errors";
import { HTTPClient } from "../utils/Utils";
import { Validation } from "../validation";

import { BigNumber, ContractTransaction, ethers } from "ethers";
import { body, query, validationResult } from "express-validator";

import express from "express";

// tslint:disable-next-line:no-implicit-dependencies
import { AddressZero } from "@ethersproject/constants";
import { BigNumber, ContractTransaction, ethers } from "ethers";
import express from "express";
import { body, query, validationResult } from "express-validator";

export class PaymentRouter {
private web_service: WebService;
Expand Down
3 changes: 1 addition & 2 deletions packages/relay/src/routers/PhoneLinkRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { RelayStorage } from "../storage/RelayStorage";
import { ContractUtils } from "../utils/ContractUtils";
import { ResponseMessage } from "../utils/Errors";

import { body, param, validationResult } from "express-validator";

import { ethers } from "ethers";
import express from "express";
import { body, param, validationResult } from "express-validator";

export class PhoneLinkRouter {
private web_service: WebService;
Expand Down
15 changes: 7 additions & 8 deletions packages/relay/src/routers/ShopRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import { INotificationSender } from "../delegator/NotificationSender";
import { WebService } from "../service/WebService";
import { GraphStorage } from "../storage/GraphStorage";
import { RelayStorage } from "../storage/RelayStorage";
import { ContractUtils } from "../utils/ContractUtils";
import { Validation } from "../validation";

import { body, param, query, validationResult } from "express-validator";
import * as hre from "hardhat";

import { ContractTransaction, ethers } from "ethers";
import express from "express";
import {
ContractShopStatus,
ContractShopUpdateEvent,
Expand All @@ -23,8 +15,15 @@ import {
TaskResultCode,
TaskResultType,
} from "../types";
import { ContractUtils } from "../utils/ContractUtils";
import { ResponseMessage } from "../utils/Errors";
import { HTTPClient } from "../utils/Utils";
import { Validation } from "../validation";

import { ContractTransaction, ethers } from "ethers";
import express from "express";
import { body, param, query, validationResult } from "express-validator";
import * as hre from "hardhat";

// tslint:disable-next-line:no-implicit-dependencies
import { AddressZero } from "@ethersproject/constants";
Expand Down
6 changes: 2 additions & 4 deletions packages/relay/src/routers/StorePurchaseRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { RelayStorage } from "../storage/RelayStorage";
import { ContractLoyaltyType, GWI_UNIT, IStorePurchaseData, PHONE_NULL } from "../types";
import { ResponseMessage } from "../utils/Errors";

import { body, query, validationResult } from "express-validator";

import express from "express";

// tslint:disable-next-line:no-implicit-dependencies
import { BigNumber } from "@ethersproject/bignumber";
// tslint:disable-next-line:no-implicit-dependencies
import { AddressZero } from "@ethersproject/constants";
import express from "express";
import { body, query, validationResult } from "express-validator";

export class StorePurchaseRouter {
private web_service: WebService;
Expand Down
13 changes: 5 additions & 8 deletions packages/relay/src/routers/TokenRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ import { Metrics } from "../metrics/Metrics";
import { WebService } from "../service/WebService";
import { GraphStorage } from "../storage/GraphStorage";
import { RelayStorage } from "../storage/RelayStorage";
import { ResponseMessage } from "../utils/Errors";
import { ContractUtils } from "../utils/ContractUtils";
import { ResponseMessage } from "../utils/Errors";
import { Validation } from "../validation";

import { body, param, query, validationResult } from "express-validator";

// tslint:disable-next-line:no-implicit-dependencies
import { AddressZero } from "@ethersproject/constants";

import express from "express";

import { BigNumber, ethers } from "ethers";
import { Validation } from "../validation";
import { toChecksumAddress } from "ethereumjs-util";
import express from "express";
import { body, param, validationResult } from "express-validator";

export class TokenRouter {
private web_service: WebService;
Expand Down
4 changes: 1 addition & 3 deletions packages/relay/src/storage/RelayStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IDatabaseConfig } from "../common/Config";
import { Utils } from "../utils/Utils";
import { Storage } from "./Storage";

import { BigNumber } from "ethers";
import { BigNumber, Wallet } from "ethers";
import MybatisMapper from "mybatis-mapper";

import path from "path";
Expand All @@ -23,8 +23,6 @@ import { ContractUtils } from "../utils/ContractUtils";

import * as hre from "hardhat";

import { Wallet } from "ethers";

/**
* The class that inserts and reads the ledger into the database.
*/
Expand Down
1 change: 0 additions & 1 deletion packages/relay/src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { verifyMessage } from "@ethersproject/wallet";
import * as crypto from "crypto";

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

export enum LoyaltyNetworkID {
LYT,
Expand Down

0 comments on commit 0664fb3

Please sign in to comment.