From 419727878b105b6bb6fa6515f775336da7b0e7cc Mon Sep 17 00:00:00 2001 From: perfogic Date: Wed, 27 Nov 2024 12:00:57 +0700 Subject: [PATCH] update import code --- .../apis/controllers/bitcoin.controller.ts | 2 +- .../src/services/relayer/index.ts | 6 +-- .../src/services/watched_scripts/index.ts | 46 ++++++++++++------- packages/orchestrator/src/utils/dest.ts | 2 +- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/packages/orchestrator/src/apis/controllers/bitcoin.controller.ts b/packages/orchestrator/src/apis/controllers/bitcoin.controller.ts index 58eab7f..da5f123 100644 --- a/packages/orchestrator/src/apis/controllers/bitcoin.controller.ts +++ b/packages/orchestrator/src/apis/controllers/bitcoin.controller.ts @@ -1,5 +1,5 @@ import { AppBitcoinQueryClient } from "@oraichain/bitcoin-bridge-contracts-sdk"; -import { Dest } from "@oraichain/bitcoin-bridge-contracts-sdk/build/CwBitcoin.types"; +import { Dest } from "@oraichain/bitcoin-bridge-contracts-sdk/build/AppBitcoin.types"; import { Request, Response } from "express"; import httpStatus from "http-status"; import RelayerService from "../../services/relayer"; diff --git a/packages/orchestrator/src/services/relayer/index.ts b/packages/orchestrator/src/services/relayer/index.ts index 9c7bb95..ab45a88 100644 --- a/packages/orchestrator/src/services/relayer/index.ts +++ b/packages/orchestrator/src/services/relayer/index.ts @@ -2,10 +2,8 @@ import { AppBitcoinClient, LightClientBitcoinClient, } from "@oraichain/bitcoin-bridge-contracts-sdk"; -import { - Dest, - WrappedHeader, -} from "@oraichain/bitcoin-bridge-contracts-sdk/build/CwBitcoin.types"; +import { Dest } from "@oraichain/bitcoin-bridge-contracts-sdk/build/AppBitcoin.types"; +import { WrappedHeader } from "@oraichain/bitcoin-bridge-contracts-sdk/build/LightClientBitcoin.types"; import { BitcoinNetwork, redeemScript } from "@oraichain/bitcoin-bridge-lib-js"; import { commitmentBytes, diff --git a/packages/orchestrator/src/services/watched_scripts/index.ts b/packages/orchestrator/src/services/watched_scripts/index.ts index aa40649..72108dc 100644 --- a/packages/orchestrator/src/services/watched_scripts/index.ts +++ b/packages/orchestrator/src/services/watched_scripts/index.ts @@ -1,9 +1,9 @@ -import { AppBitcoinClient } from '@oraichain/bitcoin-bridge-contracts-sdk'; -import { Dest as SdkDest } from '@oraichain/bitcoin-bridge-contracts-sdk/build/CwBitcoin.types'; -import { Logger } from 'winston'; -import { logger } from '../../configs/logger'; -import { TableName } from '../../utils/db'; -import { DuckDbNode } from '../db'; +import { AppBitcoinClient } from "@oraichain/bitcoin-bridge-contracts-sdk"; +import { Dest as SdkDest } from "@oraichain/bitcoin-bridge-contracts-sdk/build/AppBitcoin.types"; +import { Logger } from "winston"; +import { logger } from "../../configs/logger"; +import { TableName } from "../../utils/db"; +import { DuckDbNode } from "../db"; export interface WatchedScriptsInterface { script: string; @@ -23,10 +23,13 @@ export interface StoredWatchedScriptsInterface { class WatchedScriptsService { logger: Logger; - constructor(protected db: DuckDbNode, protected appBitcoinClient: AppBitcoinClient) { + constructor( + protected db: DuckDbNode, + protected appBitcoinClient: AppBitcoinClient + ) { this.db = db; this.appBitcoinClient = appBitcoinClient; - this.logger = logger('WatchedScriptsService'); + this.logger = logger("WatchedScriptsService"); } async insertScript(data: WatchedScriptsInterface) { @@ -36,18 +39,22 @@ class WatchedScriptsService { ...data, dest: JSON.stringify(data.dest), sigsetIndex: parseInt(data.sigsetIndex.toString()), - sigsetCreateTime: parseInt(data.sigsetCreateTime.toString()) + sigsetCreateTime: parseInt(data.sigsetCreateTime.toString()), }; await this.db.insert(TableName.WatchedScripts, { - ...insertedData + ...insertedData, }); - this.logger.info(`Inserted new script with address ${data.address}, data: ${JSON.stringify(insertedData)}`); + this.logger.info( + `Inserted new script with address ${ + data.address + }, data: ${JSON.stringify(insertedData)}` + ); } } async getScript(script: string): Promise { const data = await this.db.select(TableName.WatchedScripts, { - where: { script: script } + where: { script: script }, }); if (data.length === 0) { return null; @@ -66,15 +73,22 @@ class WatchedScriptsService { async removeExpired() { // TODO: Implement this by a single sql try { - this.logger.info('Start removing expired scripts'); + this.logger.info("Start removing expired scripts"); const checkpointConfig = await this.appBitcoinClient.checkpointConfig(); const currentTime = Math.floor(Date.now() / 1000); - const scripts: WatchedScriptsInterface[] = await this.db.select(TableName.WatchedScripts, {}); + const scripts: WatchedScriptsInterface[] = await this.db.select( + TableName.WatchedScripts, + {} + ); let count = 0; for (const script of scripts) { - if (script.sigsetCreateTime !== null && BigInt(script.sigsetCreateTime) + BigInt(checkpointConfig.max_age) < BigInt(currentTime)) { + if ( + script.sigsetCreateTime !== null && + BigInt(script.sigsetCreateTime) + BigInt(checkpointConfig.max_age) < + BigInt(currentTime) + ) { await this.db.delete(TableName.WatchedScripts, { - where: { address: script.address } + where: { address: script.address }, }); count++; } diff --git a/packages/orchestrator/src/utils/dest.ts b/packages/orchestrator/src/utils/dest.ts index 8495eff..88eee28 100644 --- a/packages/orchestrator/src/utils/dest.ts +++ b/packages/orchestrator/src/utils/dest.ts @@ -1,4 +1,4 @@ -import { Dest as SdkDest } from "@oraichain/bitcoin-bridge-contracts-sdk/build/CwBitcoin.types"; +import { Dest as SdkDest } from "@oraichain/bitcoin-bridge-contracts-sdk/build/AppBitcoin.types"; import { Dest as WasmDest } from "@oraichain/bitcoin-bridge-wasm-sdk"; export function convertWasmDestToSdkDest(