diff --git a/packages/relay/src/DefaultServer.ts b/packages/relay/src/DefaultServer.ts index 464b96f0..436d0bd3 100644 --- a/packages/relay/src/DefaultServer.ts +++ b/packages/relay/src/DefaultServer.ts @@ -35,7 +35,7 @@ export class DefaultServer extends WebService { this.config = config; this.storage = storage; this.relaySigners = new RelaySigners(this.config); - this.defaultRouter = new DefaultRouter(this, this.config, this.storage, this.relaySigners); + this.defaultRouter = new DefaultRouter(this); this.ledgerRouter = new LedgerRouter(this, this.config, this.storage, this.relaySigners); this.shopRouter = new ShopRouter(this, this.config, this.storage, this.relaySigners); this.paymentRouter = new PaymentRouter(this, this.config, this.storage, this.relaySigners); diff --git a/packages/relay/src/routers/DefaultRouter.ts b/packages/relay/src/routers/DefaultRouter.ts index 37c75ff5..2ef23d3a 100644 --- a/packages/relay/src/routers/DefaultRouter.ts +++ b/packages/relay/src/routers/DefaultRouter.ts @@ -1,12 +1,6 @@ -import { CurrencyRate, Ledger, PhoneLinkCollection, ShopCollection, Token } from "../../typechain-types"; -import { Config } from "../common/Config"; import { WebService } from "../service/WebService"; -import * as hre from "hardhat"; - import express from "express"; -import { ISignerItem, RelaySigners } from "../contract/Signers"; -import { RelayStorage } from "../storage/RelayStorage"; export class DefaultRouter { /** @@ -15,154 +9,18 @@ export class DefaultRouter { */ private _web_service: WebService; - /** - * The configuration of the database - * @private - */ - private readonly _config: Config; - - private readonly _relaySigners: RelaySigners; - - /** - * ERC20 토큰 컨트랙트 - * @private - */ - private _tokenContract: Token | undefined; - - /** - * 사용자의 원장 컨트랙트 - * @private - */ - private _ledgerContract: Ledger | undefined; - - /** - * 사용자의 원장 컨트랙트 - * @private - */ - private _shopContract: ShopCollection | undefined; - - /** - * 이메일 지갑주소 링크 컨트랙트 - * @private - */ - private _phoneLinkerContract: PhoneLinkCollection | undefined; - - /** - * 환률 컨트랙트 - * @private - */ - private _currencyRateContract: CurrencyRate | undefined; - - private _storage: RelayStorage; - /** * * @param service WebService - * @param config Configuration */ - constructor(service: WebService, config: Config, storage: RelayStorage, relaySigners: RelaySigners) { + constructor(service: WebService) { this._web_service = service; - this._config = config; - - this._storage = storage; - this._relaySigners = relaySigners; } private get app(): express.Application { return this._web_service.app; } - /*** - * 트팬잭션을 중계할 때 사용될 서명자 - * @private - */ - private async getRelaySigner(): Promise { - return this._relaySigners.getSigner(); - } - - /*** - * 트팬잭션을 중계할 때 사용될 서명자 - * @private - */ - private releaseRelaySigner(signer: ISignerItem) { - signer.using = false; - } - - /** - * ERC20 토큰 컨트랙트를 리턴한다. - * 컨트랙트의 객체가 생성되지 않았다면 컨트랙트 주소를 이용하여 컨트랙트 객체를 생성한 후 반환한다. - * @private - */ - private async getTokenContract(): Promise { - if (this._tokenContract === undefined) { - const tokenFactory = await hre.ethers.getContractFactory("Token"); - this._tokenContract = tokenFactory.attach(this._config.contracts.tokenAddress); - } - return this._tokenContract; - } - - /** - * 사용자의 원장 컨트랙트를 리턴한다. - * 컨트랙트의 객체가 생성되지 않았다면 컨트랙트 주소를 이용하여 컨트랙트 객체를 생성한 후 반환한다. - * @private - */ - private async getLedgerContract(): Promise { - if (this._ledgerContract === undefined) { - const ledgerFactory = await hre.ethers.getContractFactory("Ledger"); - this._ledgerContract = ledgerFactory.attach(this._config.contracts.ledgerAddress); - } - return this._ledgerContract; - } - - private async getShopContract(): Promise { - if (this._shopContract === undefined) { - const shopFactory = await hre.ethers.getContractFactory("ShopCollection"); - this._shopContract = shopFactory.attach(this._config.contracts.shopAddress); - } - return this._shopContract; - } - - /** - * 이메일 지갑주소 링크 컨트랙트를 리턴한다. - * 컨트랙트의 객체가 생성되지 않았다면 컨트랙트 주소를 이용하여 컨트랙트 객체를 생성한 후 반환한다. - * @private - */ - private async getPhoneLinkerContract(): Promise { - if (this._phoneLinkerContract === undefined) { - const linkCollectionFactory = await hre.ethers.getContractFactory("PhoneLinkCollection"); - this._phoneLinkerContract = linkCollectionFactory.attach(this._config.contracts.phoneLinkerAddress); - } - return this._phoneLinkerContract; - } - - /** - * 환률 컨트랙트를 리턴한다. - * 컨트랙트의 객체가 생성되지 않았다면 컨트랙트 주소를 이용하여 컨트랙트 객체를 생성한 후 반환한다. - * @private - */ - private async getCurrencyRateContract(): Promise { - if (this._currencyRateContract === undefined) { - const factory = await hre.ethers.getContractFactory("CurrencyRate"); - this._currencyRateContract = factory.attach(this._config.contracts.currencyRateAddress); - } - return this._currencyRateContract; - } - - /** - * Make the response data - * @param code The result code - * @param data The result data - * @param error The error - * @private - */ - private makeResponseData(code: number, data: any, error?: any): any { - return { - code, - data, - error, - }; - } - public registerRoutes() { // Get Health Status this.app.get("/", [], this.getHealthStatus.bind(this)); diff --git a/packages/relay/src/routers/LedgerRouter.ts b/packages/relay/src/routers/LedgerRouter.ts index 1fceed31..7e0fb3b7 100644 --- a/packages/relay/src/routers/LedgerRouter.ts +++ b/packages/relay/src/routers/LedgerRouter.ts @@ -3,7 +3,6 @@ import { Config } from "../common/Config"; import { logger } from "../common/Logger"; import { WebService } from "../service/WebService"; import { ContractUtils } from "../utils/ContractUtils"; -import { Validation } from "../validation"; import { body, validationResult } from "express-validator"; import * as hre from "hardhat"; diff --git a/packages/relay/test/helper/Utility.ts b/packages/relay/test/helper/Utility.ts index 063ed3f2..718cbf01 100644 --- a/packages/relay/test/helper/Utility.ts +++ b/packages/relay/test/helper/Utility.ts @@ -1,6 +1,6 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; -import { handleNetworkError } from "../../src/network/ErrorTypes"; import { DefaultServer } from "../../src/DefaultServer"; +import { handleNetworkError } from "../../src/network/ErrorTypes"; export class TestServer extends DefaultServer {}