diff --git a/packages/relay/config/config.yaml b/packages/relay/config/config.yaml index b86f8425..e463350f 100644 --- a/packages/relay/config/config.yaml +++ b/packages/relay/config/config.yaml @@ -20,13 +20,23 @@ database: connectionTimeoutMillis: 2000 max: 100 -graph: - host: "${GRAPH_DATABASE_HOST}" - user: "${GRAPH_DATABASE_USER}" - password: "${GRAPH_DATABASE_PASSWORD}" - database: "${GRAPH_DATABASE_NAME}" - scheme: "${GRAPH_DATABASE_SCHEME}" - port: "${GRAPH_DATABASE_PORT}" +graph_sidechain: + host: "${GRAPH_SIDECHAIN_DATABASE_HOST}" + user: "${GRAPH_SIDECHAIN_DATABASE_USER}" + password: "${GRAPH_SIDECHAIN_DATABASE_PASSWORD}" + database: "${GRAPH_SIDECHAIN_DATABASE_NAME}" + scheme: "${GRAPH_SIDECHAIN_DATABASE_SCHEME}" + port: "${GRAPH_SIDECHAIN_DATABASE_PORT}" + connectionTimeoutMillis: 2000 + max: 100 + +graph_mainchain: + host: "${GRAPH_MAINCHAIN_DATABASE_HOST}" + user: "${GRAPH_MAINCHAIN_DATABASE_USER}" + password: "${GRAPH_MAINCHAIN_DATABASE_PASSWORD}" + database: "${GRAPH_MAINCHAIN_DATABASE_NAME}" + scheme: "${GRAPH_MAINCHAIN_DATABASE_SCHEME}" + port: "${GRAPH_MAINCHAIN_DATABASE_PORT}" connectionTimeoutMillis: 2000 max: 100 diff --git a/packages/relay/config/config_test.yaml b/packages/relay/config/config_test.yaml index aeb0dee2..59173f45 100644 --- a/packages/relay/config/config_test.yaml +++ b/packages/relay/config/config_test.yaml @@ -20,13 +20,23 @@ database: connectionTimeoutMillis: 2000 max: 100 -graph: - host: "${GRAPH_DATABASE_HOST}" - user: "${GRAPH_DATABASE_USER}" - password: "${GRAPH_DATABASE_PASSWORD}" - database: "${GRAPH_DATABASE_NAME}" - scheme: "${GRAPH_DATABASE_SCHEME}" - port: "${GRAPH_DATABASE_PORT}" +graph_sidechain: + host: "${GRAPH_SIDECHAIN_DATABASE_HOST}" + user: "${GRAPH_SIDECHAIN_DATABASE_USER}" + password: "${GRAPH_SIDECHAIN_DATABASE_PASSWORD}" + database: "${GRAPH_SIDECHAIN_DATABASE_NAME}" + scheme: "${GRAPH_SIDECHAIN_DATABASE_SCHEME}" + port: "${GRAPH_SIDECHAIN_DATABASE_PORT}" + connectionTimeoutMillis: 2000 + max: 100 + +graph_mainchain: + host: "${GRAPH_MAINCHAIN_DATABASE_HOST}" + user: "${GRAPH_MAINCHAIN_DATABASE_USER}" + password: "${GRAPH_MAINCHAIN_DATABASE_PASSWORD}" + database: "${GRAPH_MAINCHAIN_DATABASE_NAME}" + scheme: "${GRAPH_MAINCHAIN_DATABASE_SCHEME}" + port: "${GRAPH_MAINCHAIN_DATABASE_PORT}" connectionTimeoutMillis: 2000 max: 100 diff --git a/packages/relay/env/.env.sample b/packages/relay/env/.env.sample index c2deef57..ba902828 100644 --- a/packages/relay/env/.env.sample +++ b/packages/relay/env/.env.sample @@ -23,12 +23,20 @@ DATABASE_PASSWORD=12345678 DATABASE_PORT=5432 # GRAPH DATABASE INFO -GRAPH_DATABASE_HOST=127.0.0.1 -GRAPH_DATABASE_USER=agora -GRAPH_DATABASE_NAME=graph -GRAPH_DATABASE_SCHEME=sgd2 -GRAPH_DATABASE_PASSWORD=12345678 -GRAPH_DATABASE_PORT=5432 +GRAPH_SIDECHAIN_DATABASE_HOST=127.0.0.1 +GRAPH_SIDECHAIN_DATABASE_USER=agora +GRAPH_SIDECHAIN_DATABASE_NAME=graph +GRAPH_SIDECHAIN_DATABASE_SCHEME=sgd2 +GRAPH_SIDECHAIN_DATABASE_PASSWORD=12345678 +GRAPH_SIDECHAIN_DATABASE_PORT=5432 + +# GRAPH DATABASE INFO +GRAPH_MAINCHAIN_DATABASE_HOST=127.0.0.1 +GRAPH_MAINCHAIN_DATABASE_USER=agora +GRAPH_MAINCHAIN_DATABASE_NAME=graph +GRAPH_MAINCHAIN_DATABASE_SCHEME=sgd3 +GRAPH_MAINCHAIN_DATABASE_PASSWORD=12345678 +GRAPH_MAINCHAIN_DATABASE_PORT=5432 # 0xDc245797409fb79446523Fa1A4ca97294eef22EE DEPLOYER=0x2b5d5cc406b66c0398d0b8327d340cb4f6e30540621802e115506fe001398ba3 diff --git a/packages/relay/src/DefaultServer.ts b/packages/relay/src/DefaultServer.ts index b3c1ad96..d4b2c9dd 100644 --- a/packages/relay/src/DefaultServer.ts +++ b/packages/relay/src/DefaultServer.ts @@ -20,6 +20,7 @@ import { StorePurchaseRouter } from "./routers/StorePurchaseRouter"; import { TokenRouter } from "./routers/TokenRouter"; import { GraphStorage } from "./storage/GraphStorage"; import { RelayStorage } from "./storage/RelayStorage"; +import { HistoryRouter } from "./routers/HistoryRouter"; export class DefaultServer extends WebService { private readonly config: Config; @@ -32,13 +33,15 @@ export class DefaultServer extends WebService { public readonly paymentRouter: PaymentRouter; public readonly relaySigners: RelaySigners; public readonly storage: RelayStorage; - public readonly graph: GraphStorage; + public readonly graph_sidechain: GraphStorage; + public readonly graph_mainchain: GraphStorage; private readonly sender: INotificationSender; public readonly etcRouter: ETCRouter; public readonly purchaseRouter: StorePurchaseRouter; public readonly tokenRouter: TokenRouter; public readonly phoneLinkRouter: PhoneLinkRouter; public readonly bridgeRouter: BridgeRouter; + public readonly historyRouter: HistoryRouter; private readonly metrics: Metrics; @@ -46,7 +49,8 @@ export class DefaultServer extends WebService { config: Config, contractManager: ContractManager, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, schedules?: Scheduler[], handler?: INotificationEventHandler ) { @@ -77,7 +81,8 @@ export class DefaultServer extends WebService { this.config = config; this.contractManager = contractManager; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.sender = new NotificationSender(this.config, handler); this.relaySigners = new RelaySigners(this.config); this.defaultRouter = new DefaultRouter(this, this.config, this.contractManager, this.metrics); @@ -87,7 +92,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, this.relaySigners ); this.shopRouter = new ShopRouter( @@ -96,7 +102,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, this.relaySigners, this.sender ); @@ -106,7 +113,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, this.relaySigners, this.sender ); @@ -116,7 +124,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, this.sender ); this.purchaseRouter = new StorePurchaseRouter( @@ -125,7 +134,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph + this.graph_sidechain, + this.graph_mainchain ); this.tokenRouter = new TokenRouter( this, @@ -133,7 +143,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, this.relaySigners ); this.phoneLinkRouter = new PhoneLinkRouter( @@ -142,7 +153,8 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, this.relaySigners ); @@ -152,7 +164,19 @@ export class DefaultServer extends WebService { this.contractManager, this.metrics, this.storage, - this.graph, + this.graph_sidechain, + this.graph_mainchain, + this.relaySigners + ); + + this.historyRouter = new HistoryRouter( + this, + this.config, + this.contractManager, + this.metrics, + this.storage, + this.graph_sidechain, + this.graph_mainchain, this.relaySigners ); @@ -164,7 +188,7 @@ export class DefaultServer extends WebService { contractManager: this.contractManager, storage: this.storage, metrics: this.metrics, - graph: this.graph, + graph: this.graph_sidechain, signers: this.relaySigners, }) ); @@ -198,6 +222,7 @@ export class DefaultServer extends WebService { this.tokenRouter.registerRoutes(); this.phoneLinkRouter.registerRoutes(); this.bridgeRouter.registerRoutes(); + this.historyRouter.registerRoutes(); for (const m of this.schedules) await m.start(); diff --git a/packages/relay/src/common/Config.ts b/packages/relay/src/common/Config.ts index 4ce7f8a6..b7ada4c5 100644 --- a/packages/relay/src/common/Config.ts +++ b/packages/relay/src/common/Config.ts @@ -12,7 +12,8 @@ export class Config implements IConfig { public database: DatabaseConfig; - public graph: DatabaseConfig; + public graph_sidechain: DatabaseConfig; + public graph_mainchain: DatabaseConfig; public logging: LoggingConfig; @@ -27,7 +28,8 @@ export class Config implements IConfig { constructor() { this.server = new ServerConfig(); this.database = new DatabaseConfig(); - this.graph = new DatabaseConfig(); + this.graph_sidechain = new DatabaseConfig(); + this.graph_mainchain = new DatabaseConfig(); this.logging = new LoggingConfig(); this.scheduler = new SchedulerConfig(); this.relay = new RelayConfig(); @@ -70,7 +72,8 @@ export class Config implements IConfig { }) as IConfig; this.server.readFromObject(cfg.server); this.database.readFromObject(cfg.database); - this.graph.readFromObject(cfg.graph); + this.graph_sidechain.readFromObject(cfg.graph_sidechain); + this.graph_mainchain.readFromObject(cfg.graph_mainchain); this.logging.readFromObject(cfg.logging); this.scheduler.readFromObject(cfg.scheduler); this.relay.readFromObject(cfg.relay); @@ -515,7 +518,8 @@ export interface IMetricsConfig { export interface IConfig { server: IServerConfig; database: IDatabaseConfig; - graph: DatabaseConfig; + graph_sidechain: DatabaseConfig; + graph_mainchain: DatabaseConfig; logging: ILoggingConfig; scheduler: ISchedulerConfig; relay: IRelayConfig; diff --git a/packages/relay/src/main.ts b/packages/relay/src/main.ts index 487d4fc1..5bf4d3a5 100644 --- a/packages/relay/src/main.ts +++ b/packages/relay/src/main.ts @@ -28,7 +28,8 @@ async function main() { await ContractUtils.delay(1000); const storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; if (config.scheduler.enable) { @@ -60,7 +61,7 @@ async function main() { const contractManager = new ContractManager(config); await contractManager.attach(); - server = new DefaultServer(config, contractManager, storage, graph, schedulers); + server = new DefaultServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); return server.start().catch((error: any) => { // handle specific listen errors with friendly messages switch (error.code) { diff --git a/packages/relay/src/routers/BridgeRouter.ts b/packages/relay/src/routers/BridgeRouter.ts index 066dedb3..87a818b9 100644 --- a/packages/relay/src/routers/BridgeRouter.ts +++ b/packages/relay/src/routers/BridgeRouter.ts @@ -22,7 +22,8 @@ export class BridgeRouter { private readonly metrics: Metrics; private readonly relaySigners: RelaySigners; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; constructor( service: WebService, @@ -30,7 +31,8 @@ export class BridgeRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, relaySigners: RelaySigners ) { this.web_service = service; @@ -39,7 +41,8 @@ export class BridgeRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.relaySigners = relaySigners; } diff --git a/packages/relay/src/routers/ETCRouter.ts b/packages/relay/src/routers/ETCRouter.ts index cba594c7..b4e51b47 100644 --- a/packages/relay/src/routers/ETCRouter.ts +++ b/packages/relay/src/routers/ETCRouter.ts @@ -19,7 +19,8 @@ export class ETCRouter { private readonly contractManager: ContractManager; private readonly metrics: Metrics; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; private readonly sender: INotificationSender; constructor( @@ -28,7 +29,8 @@ export class ETCRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, sender: INotificationSender ) { this.web_service = service; @@ -36,7 +38,8 @@ export class ETCRouter { this.contractManager = contractManager; this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.sender = sender; } diff --git a/packages/relay/src/routers/HistoryRouter.ts b/packages/relay/src/routers/HistoryRouter.ts new file mode 100644 index 00000000..6b25664e --- /dev/null +++ b/packages/relay/src/routers/HistoryRouter.ts @@ -0,0 +1,363 @@ +import { Config } from "../common/Config"; +import { logger } from "../common/Logger"; +import { ContractManager } from "../contract/ContractManager"; +import { ISignerItem, RelaySigners } from "../contract/Signers"; +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 { body, param, query, validationResult } from "express-validator"; + +import { AddressZero } from "@ethersproject/constants"; + +import express from "express"; + +import { BigNumber, ethers } from "ethers"; +import { Validation } from "../validation"; +import { toChecksumAddress } from "ethereumjs-util"; +import { PhoneNumberFormat, PhoneNumberUtil } from "google-libphonenumber"; + +export class HistoryRouter { + private web_service: WebService; + private readonly config: Config; + private readonly contractManager: ContractManager; + private readonly metrics: Metrics; + private readonly relaySigners: RelaySigners; + private storage: RelayStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; + private phoneUtil: PhoneNumberUtil; + + constructor( + service: WebService, + config: Config, + contractManager: ContractManager, + metrics: Metrics, + storage: RelayStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, + relaySigners: RelaySigners + ) { + this.phoneUtil = PhoneNumberUtil.getInstance(); + this.web_service = service; + this.config = config; + this.contractManager = contractManager; + this.metrics = metrics; + + this.storage = storage; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; + this.relaySigners = relaySigners; + } + + private get app(): express.Application { + return this.web_service.app; + } + + /*** + * 트팬잭션을 중계할 때 사용될 서명자 + * @private + */ + private async getRelaySigner(provider?: ethers.providers.Provider): Promise { + if (provider === undefined) provider = this.contractManager.sideChainProvider; + return this.relaySigners.getSigner(provider); + } + + /*** + * 트팬잭션을 중계할 때 사용될 서명자 + * @private + */ + private releaseRelaySigner(signer: ISignerItem) { + signer.using = false; + } + + /** + * 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() { + this.app.get( + "/v1/token/main/history/:account", + [ + param("account").exists().trim().isEthereumAddress(), + query("pageNumber").exists().trim().isNumeric(), + query("pageSize").exists().trim().isNumeric(), + ], + this.token_main_history.bind(this) + ); + this.app.get( + "/v1/token/side/history/:account", + [ + param("account").exists().trim().isEthereumAddress(), + query("pageNumber").exists().trim().isNumeric(), + query("pageSize").exists().trim().isNumeric(), + ], + this.token_side_history.bind(this) + ); + this.app.get( + "/v1/ledger/history/account/:account", + [ + param("account").exists().trim().isEthereumAddress(), + query("pageNumber").exists().trim().isNumeric(), + query("pageSize").exists().trim().isNumeric(), + query("pageType").exists().trim().isNumeric(), + ], + this.ledger_history_account.bind(this) + ); + this.app.get( + "/v1/ledger/history/phone/:phone", + [ + param("phone").exists(), + query("pageNumber").exists().trim().isNumeric(), + query("pageSize").exists().trim().isNumeric(), + ], + this.ledger_history_phone.bind(this) + ); + } + + private async token_main_history(req: express.Request, res: express.Response) { + logger.http(`GET /v1/token/main/history ${req.ip}:${JSON.stringify(req.params)}`); + const account: string = String(req.params.account).trim(); + + let pageSize = Number(req.query.pageSize); + if (pageSize > 50) pageSize = 50; + let pageNumber = Number(req.query.pageNumber); + if (pageNumber < 1) pageNumber = 1; + + try { + const histories = await this.graph_mainchain.getTokenTransferHistory(account, pageNumber, pageSize); + const pageInfo = await this.graph_mainchain.getTokenTransferPageInfo(account, pageSize); + + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + pageInfo, + items: histories.map((m) => { + return { + from: m.from, + to: m.to, + value: m.value.toString(), + blockTimestamp: m.blockTimestamp.toString(), + }; + }), + }) + ); + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`GET /v1/token/main/history : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } + } + + private async token_side_history(req: express.Request, res: express.Response) { + logger.http(`GET /v1/token/side/history ${req.ip}:${JSON.stringify(req.params)}`); + + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() })); + } + + const account: string = String(req.params.account).trim(); + + let pageSize = Number(req.query.pageSize); + if (pageSize > 50) pageSize = 50; + let pageNumber = Number(req.query.pageNumber); + if (pageNumber < 1) pageNumber = 1; + + try { + const histories = await this.graph_sidechain.getTokenTransferHistory(account, pageNumber, pageSize); + const pageInfo = await this.graph_sidechain.getTokenTransferPageInfo(account, pageSize); + + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + pageInfo, + items: histories.map((m) => { + return { + from: m.from, + to: m.to, + value: m.value.toString(), + blockTimestamp: m.blockTimestamp.toString(), + }; + }), + }) + ); + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`GET /v1/token/side/history : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } + } + + private async ledger_history_account(req: express.Request, res: express.Response) { + logger.http(`GET /v1/ledger/history/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() })); + } + + const account: string = String(req.params.account).trim(); + + let pageSize = Number(req.query.pageSize); + if (pageSize > 50) pageSize = 50; + let pageNumber = Number(req.query.pageNumber); + if (pageNumber < 1) pageNumber = 1; + let pageType = Number(req.query.pageType); + + try { + const histories = await this.graph_sidechain.getAccountLedgerHistory( + account, + pageType, + pageNumber, + pageSize + ); + const pageInfo = await this.graph_sidechain.getAccountLedgerHistoryPageInfo(account, pageType, pageSize); + + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + pageInfo, + items: histories.map((m) => { + return { + account: m.account, + pageType: m.pageType, + action: m.action, + cancel: m.cancel, + loyaltyType: m.loyaltyType, + amountPoint: m.amountPoint.toString(), + amountToken: m.amountToken.toString(), + amountValue: m.amountValue.toString(), + feePoint: m.feePoint.toString(), + feeToken: m.feeToken.toString(), + feeValue: m.feeValue.toString(), + balancePoint: m.balancePoint.toString(), + balanceToken: m.balanceToken.toString(), + purchaseId: m.purchaseId, + paymentId: m.paymentId, + shopId: m.shopId, + blockNumber: m.blockNumber.toString(), + blockTimestamp: m.blockTimestamp.toString(), + transactionHash: m.transactionHash, + }; + }), + }) + ); + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`GET /v1/ledger/history/account : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } + } + + private async ledger_history_phone(req: express.Request, res: express.Response) { + logger.http(`GET /v1/ledger/history/phone ${req.ip}:${JSON.stringify(req.params)}`); + + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() })); + } + let phone: string = String(req.params.phone).trim(); + try { + const number = this.phoneUtil.parseAndKeepRawInput(phone, "ZZ"); + if (!this.phoneUtil.isValidNumber(number)) { + return res.status(200).json(ResponseMessage.getErrorMessage("2007")); + } else { + phone = this.phoneUtil.format(number, PhoneNumberFormat.INTERNATIONAL); + } + } catch (error) { + return res.status(200).json(ResponseMessage.getErrorMessage("2007")); + } + const phoneHash: string = ContractUtils.getPhoneHash(phone); + + let pageSize = Number(req.query.pageSize); + if (pageSize > 50) pageSize = 50; + let pageNumber = Number(req.query.pageNumber); + if (pageNumber < 1) pageNumber = 1; + + try { + const account: string = await this.contractManager.sidePhoneLinkerContract.toAddress(phoneHash); + if (account !== AddressZero) { + const histories = await this.graph_sidechain.getAccountLedgerHistory(account, 1, pageNumber, pageSize); + const pageInfo = await this.graph_sidechain.getAccountLedgerHistoryPageInfo(account, 1, pageSize); + + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + pageInfo, + type: "account", + items: histories.map((m) => { + return { + account: m.account, + pageType: m.pageType, + action: m.action, + cancel: m.cancel, + loyaltyType: m.loyaltyType, + amountPoint: m.amountPoint.toString(), + amountToken: m.amountToken.toString(), + amountValue: m.amountValue.toString(), + feePoint: m.feePoint.toString(), + feeToken: m.feeToken.toString(), + feeValue: m.feeValue.toString(), + balancePoint: m.balancePoint.toString(), + balanceToken: m.balanceToken.toString(), + purchaseId: m.purchaseId, + paymentId: m.paymentId, + shopId: m.shopId, + blockNumber: m.blockNumber.toString(), + blockTimestamp: m.blockTimestamp.toString(), + transactionHash: m.transactionHash, + }; + }), + }) + ); + } else { + const histories = await this.graph_sidechain.getPhoneLedgerHistory(phoneHash, pageNumber, pageSize); + const pageInfo = await this.graph_sidechain.getPhoneLedgerHistoryPageInfo(phoneHash, pageSize); + + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + pageInfo, + type: "phone", + items: histories.map((m) => { + return { + phone: m.phone, + action: m.action, + amount: m.amount.toString(), + balance: m.balance.toString(), + purchaseId: m.purchaseId, + shopId: m.shopId, + blockNumber: m.blockNumber.toString(), + blockTimestamp: m.blockTimestamp.toString(), + transactionHash: m.transactionHash, + }; + }), + }) + ); + } + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`GET /v1/ledger/history/phone : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } + } +} diff --git a/packages/relay/src/routers/LedgerRouter.ts b/packages/relay/src/routers/LedgerRouter.ts index 81292818..c15ed58c 100644 --- a/packages/relay/src/routers/LedgerRouter.ts +++ b/packages/relay/src/routers/LedgerRouter.ts @@ -26,7 +26,8 @@ export class LedgerRouter { private readonly metrics: Metrics; private readonly relaySigners: RelaySigners; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; private phoneUtil: PhoneNumberUtil; constructor( @@ -35,7 +36,8 @@ export class LedgerRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, relaySigners: RelaySigners ) { this.phoneUtil = PhoneNumberUtil.getInstance(); @@ -45,7 +47,8 @@ export class LedgerRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.relaySigners = relaySigners; } diff --git a/packages/relay/src/routers/PaymentRouter.ts b/packages/relay/src/routers/PaymentRouter.ts index 9741e37b..021c3e3e 100644 --- a/packages/relay/src/routers/PaymentRouter.ts +++ b/packages/relay/src/routers/PaymentRouter.ts @@ -41,7 +41,8 @@ export class PaymentRouter { private readonly metrics: Metrics; private readonly relaySigners: RelaySigners; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; private readonly _sender: INotificationSender; constructor( @@ -50,7 +51,8 @@ export class PaymentRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, relaySigners: RelaySigners, sender: INotificationSender ) { @@ -60,7 +62,8 @@ export class PaymentRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.relaySigners = relaySigners; this._sender = sender; } diff --git a/packages/relay/src/routers/PhoneLinkRouter.ts b/packages/relay/src/routers/PhoneLinkRouter.ts index ad2b9c91..c789fe6a 100644 --- a/packages/relay/src/routers/PhoneLinkRouter.ts +++ b/packages/relay/src/routers/PhoneLinkRouter.ts @@ -21,7 +21,8 @@ export class PhoneLinkRouter { private readonly metrics: Metrics; private readonly relaySigners: RelaySigners; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; constructor( service: WebService, @@ -29,7 +30,8 @@ export class PhoneLinkRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, relaySigners: RelaySigners ) { this.web_service = service; @@ -38,7 +40,8 @@ export class PhoneLinkRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.relaySigners = relaySigners; } diff --git a/packages/relay/src/routers/ShopRouter.ts b/packages/relay/src/routers/ShopRouter.ts index ddb5ad90..6234b156 100644 --- a/packages/relay/src/routers/ShopRouter.ts +++ b/packages/relay/src/routers/ShopRouter.ts @@ -38,7 +38,8 @@ export class ShopRouter { private readonly metrics: Metrics; private readonly relaySigners: RelaySigners; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; private readonly _sender: INotificationSender; @@ -48,7 +49,8 @@ export class ShopRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, relaySigners: RelaySigners, sender: INotificationSender ) { @@ -58,7 +60,8 @@ export class ShopRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.relaySigners = relaySigners; this._sender = sender; } @@ -1231,13 +1234,13 @@ export class ShopRouter { let pageNumber = Number(req.query.pageNumber); if (pageNumber < 1) pageNumber = 1; - const shops = await this.graph.getShopList(pageNumber, pageSize); - const pageInfo = await this.graph.getShopPageInfo(pageSize); + const shops = await this.graph_sidechain.getShopList(pageNumber, pageSize); + const pageInfo = await this.graph_sidechain.getShopPageInfo(pageSize); this.metrics.add("success", 1); return res.status(200).json( this.makeResponseData(0, { pageInfo, - shops: shops.map((m) => { + items: shops.map((m) => { return { shopId: m.shopId, name: m.name, diff --git a/packages/relay/src/routers/StorePurchaseRouter.ts b/packages/relay/src/routers/StorePurchaseRouter.ts index bbf70cfa..96e8db32 100644 --- a/packages/relay/src/routers/StorePurchaseRouter.ts +++ b/packages/relay/src/routers/StorePurchaseRouter.ts @@ -23,7 +23,8 @@ export class StorePurchaseRouter { private readonly contractManager: ContractManager; private readonly metrics: Metrics; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; constructor( service: WebService, @@ -31,7 +32,8 @@ export class StorePurchaseRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage ) { this.web_service = service; this.config = config; @@ -39,7 +41,8 @@ export class StorePurchaseRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; } private get app(): express.Application { diff --git a/packages/relay/src/routers/TokenRouter.ts b/packages/relay/src/routers/TokenRouter.ts index ceadede0..e1eb320b 100644 --- a/packages/relay/src/routers/TokenRouter.ts +++ b/packages/relay/src/routers/TokenRouter.ts @@ -17,6 +17,7 @@ import express from "express"; import { BigNumber, ethers } from "ethers"; import { Validation } from "../validation"; +import { toChecksumAddress } from "ethereumjs-util"; export class TokenRouter { private web_service: WebService; @@ -25,7 +26,8 @@ export class TokenRouter { private readonly metrics: Metrics; private readonly relaySigners: RelaySigners; private storage: RelayStorage; - private graph: GraphStorage; + private graph_sidechain: GraphStorage; + private graph_mainchain: GraphStorage; constructor( service: WebService, @@ -33,7 +35,8 @@ export class TokenRouter { contractManager: ContractManager, metrics: Metrics, storage: RelayStorage, - graph: GraphStorage, + graph_sidechain: GraphStorage, + graph_mainchain: GraphStorage, relaySigners: RelaySigners ) { this.web_service = service; @@ -42,7 +45,8 @@ export class TokenRouter { this.metrics = metrics; this.storage = storage; - this.graph = graph; + this.graph_sidechain = graph_sidechain; + this.graph_mainchain = graph_mainchain; this.relaySigners = relaySigners; } @@ -324,6 +328,8 @@ export class TokenRouter { private async chain_main_info(req: express.Request, res: express.Response) { logger.http(`GET /v1/chain/main/info ${req.ip}:${JSON.stringify(req.params)}`); try { + console.log(this.contractManager.mainTokenId); + console.log(this.contractManager.mainLoyaltyBridgeContract.address); this.metrics.add("success", 1); return res.status(200).json( this.makeResponseData(0, { @@ -353,6 +359,7 @@ export class TokenRouter { return res.status(200).json(msg); } } + /** * 사이드체인의 체인 정보 * GET /v1/chain/side/info diff --git a/packages/relay/src/storage/GraphStorage.ts b/packages/relay/src/storage/GraphStorage.ts index f0ed4cc6..db851c51 100644 --- a/packages/relay/src/storage/GraphStorage.ts +++ b/packages/relay/src/storage/GraphStorage.ts @@ -1,5 +1,13 @@ import { IDatabaseConfig } from "../common/Config"; -import { IGraphPageInfo, IGraphShopData, IStatisticsAccountInfo, IStatisticsShopInfo } from "../types"; +import { + IGraphAccountLedgerHistoryData, + IGraphPageInfo, + IGraphPhoneLedgerHistoryData, + IGraphShopData, + IGraphTokenTransferHistoryData, + IStatisticsAccountInfo, + IStatisticsShopInfo, +} from "../types"; import { Utils } from "../utils/Utils"; import { Storage } from "./Storage"; @@ -25,6 +33,8 @@ export class GraphStorage extends Storage { public async initialize() { await super.initialize(); MybatisMapper.createMapper([path.resolve(Utils.getInitCWD(), "src/storage/graph/shop.xml")]); + MybatisMapper.createMapper([path.resolve(Utils.getInitCWD(), "src/storage/graph/user.xml")]); + MybatisMapper.createMapper([path.resolve(Utils.getInitCWD(), "src/storage/graph/token.xml")]); MybatisMapper.createMapper([path.resolve(Utils.getInitCWD(), "src/storage/graph/statistics.xml")]); await this.createTables(); } @@ -86,6 +96,58 @@ export class GraphStorage extends Storage { }); } + public getTokenTransferHistory( + account: string, + pageNumber: number, + pageSize: number + ): Promise { + return new Promise(async (resolve, reject) => { + this.queryForMapper("token", "getTokenTransferHistory", { + scheme: this.scheme, + pageNumber, + pageSize, + account, + }) + .then((result) => { + return resolve( + result.rows.map((m) => { + return { + from: toChecksumAddress("0x" + m.from.toString("hex")), + to: toChecksumAddress("0x" + m.to.toString("hex")), + value: BigNumber.from(m.value).mul(GraphStorage.AmountUnit), + blockTimestamp: BigNumber.from(m.block_timestamp), + }; + }) + ); + }) + .catch((reason) => { + if (reason instanceof Error) return reject(reason); + return reject(new Error(reason)); + }); + }); + } + + public getTokenTransferPageInfo(account: string, pageSize: number): Promise { + return new Promise(async (resolve, reject) => { + this.queryForMapper("token", "getTokenTransferHistoryPageInfo", { scheme: this.scheme, pageSize, account }) + .then((result) => { + if (result.rows.length > 0) { + const m = result.rows[0]; + return resolve({ + totalCount: Number(m.totalCount), + totalPages: Number(m.totalPages), + }); + } else { + return reject(new Error("")); + } + }) + .catch((reason) => { + if (reason instanceof Error) return reject(reason); + return reject(new Error(reason)); + }); + }); + } + public getPhoneAccountStatistics(): Promise { return new Promise(async (resolve, reject) => { this.queryForMapper("statistics", "getPhoneAccountStatistics", { scheme: this.scheme }) @@ -188,4 +250,143 @@ export class GraphStorage extends Storage { }); }); } + + public getAccountLedgerHistory( + account: string, + pageType: number, + pageNumber: number, + pageSize: number + ): Promise { + return new Promise(async (resolve, reject) => { + this.queryForMapper("user", "getAccountLedgerHistory", { + scheme: this.scheme, + pageType, + pageNumber, + pageSize, + account, + }) + .then((result) => { + return resolve( + result.rows.map((m) => { + return { + account: toChecksumAddress("0x" + m.account.toString("hex")), + pageType: m.page_type, + action: m.action, + cancel: m.cancel, + loyaltyType: m.loyalty_type, + amountPoint: BigNumber.from(m.amount_point).mul(GraphStorage.AmountUnit), + amountToken: BigNumber.from(m.amount_token).mul(GraphStorage.AmountUnit), + amountValue: BigNumber.from(m.amount_value).mul(GraphStorage.AmountUnit), + feePoint: BigNumber.from(m.fee_point).mul(GraphStorage.AmountUnit), + feeToken: BigNumber.from(m.fee_token).mul(GraphStorage.AmountUnit), + feeValue: BigNumber.from(m.fee_value).mul(GraphStorage.AmountUnit), + balancePoint: BigNumber.from(m.balance_point).mul(GraphStorage.AmountUnit), + balanceToken: BigNumber.from(m.balance_token).mul(GraphStorage.AmountUnit), + purchaseId: m.purchase_id, + paymentId: m.payment_id, + shopId: m.shop_id, + blockNumber: BigNumber.from(m.block_number), + blockTimestamp: BigNumber.from(m.block_timestamp), + transactionHash: m.transaction_hash, + }; + }) + ); + }) + .catch((reason) => { + if (reason instanceof Error) return reject(reason); + return reject(new Error(reason)); + }); + }); + } + + public getAccountLedgerHistoryPageInfo( + account: string, + pageType: number, + pageSize: number + ): Promise { + return new Promise(async (resolve, reject) => { + this.queryForMapper("user", "getAccountLedgerHistoryPageInfo", { + scheme: this.scheme, + pageSize, + account, + pageType, + }) + .then((result) => { + if (result.rows.length > 0) { + const m = result.rows[0]; + return resolve({ + totalCount: Number(m.totalCount), + totalPages: Number(m.totalPages), + }); + } else { + return reject(new Error("")); + } + }) + .catch((reason) => { + if (reason instanceof Error) return reject(reason); + return reject(new Error(reason)); + }); + }); + } + + public getPhoneLedgerHistory( + phone: string, + pageNumber: number, + pageSize: number + ): Promise { + return new Promise(async (resolve, reject) => { + this.queryForMapper("user", "getPhoneLedgerHistory", { + scheme: this.scheme, + pageNumber, + pageSize, + phone, + }) + .then((result) => { + return resolve( + result.rows.map((m) => { + return { + phone: m.phone, + action: m.action, + amount: BigNumber.from(m.amount).mul(GraphStorage.AmountUnit), + balance: BigNumber.from(m.balance).mul(GraphStorage.AmountUnit), + purchaseId: m.purchase_id, + shopId: m.shop_id, + blockNumber: BigNumber.from(m.block_number), + blockTimestamp: BigNumber.from(m.block_timestamp), + transactionHash: m.transaction_hash, + }; + }) + ); + }) + .catch((reason) => { + if (reason instanceof Error) return reject(reason); + return reject(new Error(reason)); + }); + }); + } + + public getPhoneLedgerHistoryPageInfo(phone: string, pageSize: number): Promise { + return new Promise(async (resolve, reject) => { + this.queryForMapper("user", "getPhoneLedgerHistoryPageInfo", { + scheme: this.scheme, + pageSize, + phone, + }) + .then((result) => { + if (result.rows.length > 0) { + const m = result.rows[0]; + return resolve({ + totalCount: Number(m.totalCount), + totalPages: Number(m.totalPages), + }); + } else { + return reject(new Error("")); + } + }) + .catch((reason) => { + if (reason instanceof Error) return reject(reason); + return reject(new Error(reason)); + }); + }); + } } diff --git a/packages/relay/src/storage/graph/shop.xml b/packages/relay/src/storage/graph/shop.xml index 661e9841..d05e73a0 100644 --- a/packages/relay/src/storage/graph/shop.xml +++ b/packages/relay/src/storage/graph/shop.xml @@ -43,7 +43,9 @@ ) SELECT RowInfo.total_count as "totalCount", - CEIL(RowInfo.total_count / ${pageSize}) AS "totalPages" + CEIL(CAST(RowInfo.total_count AS FLOAT) / ${pageSize}) AS "totalPages" FROM RowInfo; + + diff --git a/packages/relay/src/storage/graph/token.xml b/packages/relay/src/storage/graph/token.xml new file mode 100644 index 00000000..35f55015 --- /dev/null +++ b/packages/relay/src/storage/graph/token.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/packages/relay/src/storage/graph/user.xml b/packages/relay/src/storage/graph/user.xml new file mode 100644 index 00000000..3c30a5af --- /dev/null +++ b/packages/relay/src/storage/graph/user.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + diff --git a/packages/relay/src/types/index.ts b/packages/relay/src/types/index.ts index 92f87d26..9adaebe4 100644 --- a/packages/relay/src/types/index.ts +++ b/packages/relay/src/types/index.ts @@ -233,6 +233,47 @@ export interface IGraphPageInfo { totalPages: number; } +export interface IGraphTokenTransferHistoryData { + from: string; + to: string; + value: BigNumber; + blockTimestamp: BigNumber; +} + +export interface IGraphAccountLedgerHistoryData { + account: string; + pageType: number; + action: string; + cancel: boolean; + loyaltyType: BigNumber; + amountPoint: BigNumber; + amountToken: BigNumber; + amountValue: BigNumber; + feePoint: BigNumber; + feeToken: BigNumber; + feeValue: BigNumber; + balancePoint: BigNumber; + balanceToken: BigNumber; + purchaseId: string; + paymentId: string; + shopId: string; + blockNumber: BigNumber; + blockTimestamp: BigNumber; + transactionHash: string; +} + +export interface IGraphPhoneLedgerHistoryData { + phone: string; + action: string; + amount: BigNumber; + balance: BigNumber; + purchaseId: string; + shopId: string; + blockNumber: BigNumber; + blockTimestamp: BigNumber; + transactionHash: string; +} + export interface IStorePurchaseData { purchaseId: string; timestamp: bigint; diff --git a/packages/relay/test/Approval.test.ts b/packages/relay/test/Approval.test.ts index dea38d66..1f963221 100644 --- a/packages/relay/test/Approval.test.ts +++ b/packages/relay/test/Approval.test.ts @@ -174,13 +174,14 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new ApprovalScheduler("*/1 * * * * *")); schedulers.push(new WatchScheduler("*/1 * * * * *")); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/Bridge.test.ts b/packages/relay/test/Bridge.test.ts index e0378c89..984bccb3 100644 --- a/packages/relay/test/Bridge.test.ts +++ b/packages/relay/test/Bridge.test.ts @@ -80,9 +80,10 @@ describe("Test of Bridge", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/DelegatedTransfer.test.ts b/packages/relay/test/DelegatedTransfer.test.ts index 68ccf26c..18661c9b 100644 --- a/packages/relay/test/DelegatedTransfer.test.ts +++ b/packages/relay/test/DelegatedTransfer.test.ts @@ -80,9 +80,10 @@ describe("Test of delegated transfer", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/DelegatorApproval.test.ts b/packages/relay/test/DelegatorApproval.test.ts index ff9b98be..ee0b23fe 100644 --- a/packages/relay/test/DelegatorApproval.test.ts +++ b/packages/relay/test/DelegatorApproval.test.ts @@ -174,13 +174,14 @@ describe("Test of Delegator", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new DelegatorApprovalScheduler("*/1 * * * * *")); schedulers.push(new WatchScheduler("*/1 * * * * *")); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/ETC.test.ts b/packages/relay/test/ETC.test.ts index ca6ecbf5..b1e97516 100644 --- a/packages/relay/test/ETC.test.ts +++ b/packages/relay/test/ETC.test.ts @@ -81,10 +81,11 @@ describe("Test for ETC", function () { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const contractManager = new ContractManager(config); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/Endpoints.test.ts b/packages/relay/test/Endpoints.test.ts index 25e69cdb..f2c3d087 100644 --- a/packages/relay/test/Endpoints.test.ts +++ b/packages/relay/test/Endpoints.test.ts @@ -191,9 +191,10 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { @@ -315,9 +316,10 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { @@ -491,9 +493,10 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/ForcedClose.test.ts b/packages/relay/test/ForcedClose.test.ts index f546a6bc..7c115669 100644 --- a/packages/relay/test/ForcedClose.test.ts +++ b/packages/relay/test/ForcedClose.test.ts @@ -171,9 +171,10 @@ describe("Test of Server", function () { const schedulers: Scheduler[] = []; schedulers.push(new CloseScheduler("*/1 * * * * *")); schedulers.push(new WatchScheduler("*/1 * * * * *")); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -374,9 +375,10 @@ describe("Test of Server", function () { schedulers.push(new ApprovalScheduler("*/1 * * * * *")); schedulers.push(new CloseScheduler("*/1 * * * * *")); schedulers.push(new WatchScheduler("*/1 * * * * *")); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/LoyaltyBridge.test.ts b/packages/relay/test/LoyaltyBridge.test.ts index eb957b87..0f785dcc 100644 --- a/packages/relay/test/LoyaltyBridge.test.ts +++ b/packages/relay/test/LoyaltyBridge.test.ts @@ -80,9 +80,10 @@ describe("Test of LoyaltyBridge", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/LoyaltyTransfer.test.ts b/packages/relay/test/LoyaltyTransfer.test.ts index d92a7d8d..d26c02f1 100644 --- a/packages/relay/test/LoyaltyTransfer.test.ts +++ b/packages/relay/test/LoyaltyTransfer.test.ts @@ -80,9 +80,10 @@ describe("Test of LoyaltyTransfer", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/Payment.test.ts b/packages/relay/test/Payment.test.ts index b4918416..c93ec4af 100644 --- a/packages/relay/test/Payment.test.ts +++ b/packages/relay/test/Payment.test.ts @@ -211,9 +211,10 @@ describe("Test of Server", function () { const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -672,12 +673,13 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -1067,12 +1069,13 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -1426,12 +1429,13 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -1697,12 +1701,13 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -2086,12 +2091,13 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { @@ -2540,12 +2546,21 @@ describe("Test of Server", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers, mobilePhone); + server = new TestServer( + config, + contractManager, + storage, + graph_sidechain, + graph_mainchain, + schedulers, + mobilePhone + ); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/Shop.test.ts b/packages/relay/test/Shop.test.ts index 23bbb720..61daac7f 100644 --- a/packages/relay/test/Shop.test.ts +++ b/packages/relay/test/Shop.test.ts @@ -165,11 +165,12 @@ describe("Test for Shop", function () { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler("*/1 * * * * *")); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/ShopWithdraw.test.ts b/packages/relay/test/ShopWithdraw.test.ts index 8d8ce007..fd0a65bd 100644 --- a/packages/relay/test/ShopWithdraw.test.ts +++ b/packages/relay/test/ShopWithdraw.test.ts @@ -260,9 +260,10 @@ describe("Test for Shop", () => { before("Create TestServer", async () => { serverURL = new URL(`http://127.0.0.1:${config.server.port}`); storage = await RelayStorage.make(config.database); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain); }); before("Start TestServer", async () => { diff --git a/packages/relay/test/TempararyAccount.test.ts b/packages/relay/test/TempararyAccount.test.ts index fb10c7b2..ee200947 100644 --- a/packages/relay/test/TempararyAccount.test.ts +++ b/packages/relay/test/TempararyAccount.test.ts @@ -212,9 +212,10 @@ describe("Test of Server", function () { const schedulers: Scheduler[] = []; schedulers.push(new WatchScheduler(expression)); - const graph = await GraphStorage.make(config.graph); + const graph_sidechain = await GraphStorage.make(config.graph_sidechain); + const graph_mainchain = await GraphStorage.make(config.graph_mainchain); await contractManager.attach(); - server = new TestServer(config, contractManager, storage, graph, schedulers); + server = new TestServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers); }); before("Start TestServer", async () => {