diff --git a/src/index.ts b/src/index.ts index a449ea8..cd2194d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,6 +66,8 @@ const startRpcConnection = async () => { const resolverOptions = config.node ? { urls: config.node } : undefined; const resolver = new Resolver(resolverOptions); + if (DEBUG) monitoring.debug(`Main: Resolver(${resolverOptions})`); + rpc = new RpcClient({ resolver: resolver, encoding: Encoding.Borsh, @@ -73,7 +75,11 @@ const startRpcConnection = async () => { }); if (DEBUG) monitoring.debug(`Main: Starting RPC connection`); - await rpc.connect(); + try { + await rpc.connect(); + } catch (rpcError) { + throw Error('RPC connection error'); + } const serverInfo = await rpc.getServerInfo(); if (!serverInfo.isSynced || !serverInfo.hasUtxoIndex) { throw Error('Provided node is either not synchronized or lacks the UTXO index.'); @@ -132,8 +138,12 @@ cron.schedule(`*/10 * * * *`, async () => { setInterval(() => { const now = new Date(); const minutes = now.getMinutes(); - const remainingMinutes = paymentInterval * 60 - (minutes % (paymentInterval * 60)); - const remainingTime = remainingMinutes === paymentInterval * 60 ? 0 : remainingMinutes; + const hours = now.getHours(); + + const nextTransferHours = paymentInterval - (hours % paymentInterval); + const remainingMinutes = nextTransferHours * 60 - minutes; + const remainingTime = remainingMinutes === nextTransferHours * 60 ? 0 : remainingMinutes; + if (DEBUG) monitoring.debug(`Main: ${remainingTime} minutes until the next balance transfer`); }, 10 * 60 * 1000); // 10 minutes in milliseconds diff --git a/src/trxs/index.ts b/src/trxs/index.ts index a21fc81..c12fa8a 100644 --- a/src/trxs/index.ts +++ b/src/trxs/index.ts @@ -1,5 +1,3 @@ -// @ts-ignore -//globalThis.WebSocket = require('websocket').w3cwebsocket; // W3C WebSocket module shim import Database from '../database'; import { sompiToKaspaStringWithSuffix, type IPaymentOutput, createTransactions, PrivateKey, UtxoProcessor, UtxoContext, type RpcClient } from "../../wasm/kaspa"; import Monitoring from '../monitoring';