Skip to content

Commit

Permalink
back to kaspa and testing new changes rpc connection
Browse files Browse the repository at this point in the history
  • Loading branch information
coinchimp committed Aug 9, 2024
1 parent db102db commit 679c0fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
40 changes: 23 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* every 10 minutes.
*/

import { RpcClient, Encoding, Resolver } from "../wasm/kaspa-dev";
import { RpcClient, Encoding, Resolver } from "../wasm/kaspa";
import config from "../config/config.json";
import dotenv from 'dotenv';
import Monitoring from './monitoring';
Expand Down Expand Up @@ -91,14 +91,20 @@ const startRpcConnection = async () => {
setupTransactionManager();
};

const stopRpcConnection = async () => {
if (rpc) {
await transactionManager!.stopProcessor();
await rpc.disconnect();
rpcConnected = false;
if (DEBUG) monitoring.debug(`Main: RPC connection closed`);
}
};
if (!rpcConnected) {
await startRpcConnection();
if (DEBUG) monitoring.debug('Main: RPC connection started');
}


// const stopRpcConnection = async () => {
// if (rpc) {
// await transactionManager!.stopProcessor();
// await rpc.disconnect();
// rpcConnected = false;
// if (DEBUG) monitoring.debug(`Main: RPC connection closed`);
// }
// };

// Transaction Manager setup
const setupTransactionManager = () => {
Expand All @@ -113,22 +119,22 @@ cron.schedule(`*/10 * * * *`, async () => {
const hours = now.getHours();

// Determine if it's 10 minutes before the payment interval
const isTenMinutesBefore = minutes === 50 && (hours % paymentInterval === paymentInterval - 1);
//const isTenMinutesBefore = minutes === 50 && (hours % paymentInterval === paymentInterval - 1);
// Determine if it's the payment interval time
const isPaymentTime = minutes === 0 && (hours % paymentInterval === 0);

if (isTenMinutesBefore && !rpcConnected) {
await startRpcConnection();
if (DEBUG) monitoring.debug('Main: RPC connection started 10 minutes before balance transfer');
}
// if (isTenMinutesBefore && !rpcConnected) {
// await startRpcConnection();
// if (DEBUG) monitoring.debug('Main: RPC connection started 10 minutes before balance transfer');
// }

if (isPaymentTime && rpcConnected) {
monitoring.log('Main: Running scheduled balance transfer');
try {
await transactionManager!.transferBalances();
setTimeout(async () => {
await stopRpcConnection();
}, 10 * 60 * 1000); // Disconnect 10 minutes after transaction
// setTimeout(async () => {
// await stopRpcConnection();
// }, 10 * 60 * 1000); // Disconnect 10 minutes after transaction
} catch (transactionError) {
monitoring.error(`Main: Transaction manager error: ${transactionError}`);
}
Expand Down
8 changes: 4 additions & 4 deletions src/trxs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Database from '../database';
import { sompiToKaspaStringWithSuffix, type IPaymentOutput, createTransactions, PrivateKey, UtxoProcessor, UtxoContext, type RpcClient } from "../../wasm/kaspa-dev";
import { sompiToKaspaStringWithSuffix, type IPaymentOutput, createTransactions, PrivateKey, UtxoProcessor, UtxoContext, type RpcClient } from "../../wasm/kaspa";
import Monitoring from '../monitoring';
import { DEBUG } from "../index";

Expand Down Expand Up @@ -95,9 +95,9 @@ export default class trxManager {
this.processor.start()
}

stopProcessor () {
this.processor.stop()
}
// stopProcessor () {
// this.processor.stop()
// }


}

0 comments on commit 679c0fd

Please sign in to comment.