Skip to content

Commit

Permalink
update import code
Browse files Browse the repository at this point in the history
  • Loading branch information
perfogic committed Nov 27, 2024
1 parent ad98f43 commit 4197278
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
6 changes: 2 additions & 4 deletions packages/orchestrator/src/services/relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 30 additions & 16 deletions packages/orchestrator/src/services/watched_scripts/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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<WatchedScriptsInterface | null> {
const data = await this.db.select(TableName.WatchedScripts, {
where: { script: script }
where: { script: script },
});
if (data.length === 0) {
return null;
Expand All @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestrator/src/utils/dest.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 4197278

Please sign in to comment.