Skip to content

Commit

Permalink
[Relay] Clean up unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Nov 7, 2023
1 parent d32cad6 commit 07bbf3a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 146 deletions.
2 changes: 1 addition & 1 deletion packages/relay/src/DefaultServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
144 changes: 1 addition & 143 deletions packages/relay/src/routers/DefaultRouter.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand All @@ -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<ISignerItem> {
return this._relaySigners.getSigner();
}

/***
* 트팬잭션을 중계할 때 사용될 서명자
* @private
*/
private releaseRelaySigner(signer: ISignerItem) {
signer.using = false;
}

/**
* ERC20 토큰 컨트랙트를 리턴한다.
* 컨트랙트의 객체가 생성되지 않았다면 컨트랙트 주소를 이용하여 컨트랙트 객체를 생성한 후 반환한다.
* @private
*/
private async getTokenContract(): Promise<Token> {
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<Ledger> {
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<ShopCollection> {
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<PhoneLinkCollection> {
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<CurrencyRate> {
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));
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 @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/test/helper/Utility.ts
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down

0 comments on commit 07bbf3a

Please sign in to comment.