Skip to content

Commit

Permalink
adding processor for maturity event between transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
coinchimp committed Aug 11, 2024
1 parent 5ff4ed4 commit 9b54296
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"dotenv": "^16.4.5",
"events": "^3.3.0",
"node-cron": "^3.0.3",
"p-queue": "^8.0.1",
"pg": "^8.12.0"
Expand Down
29 changes: 17 additions & 12 deletions src/trxs/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EventEmitter } from 'events'
import Database from '../database';
import { sompiToKaspaStringWithSuffix, type IPaymentOutput, createTransactions, PrivateKey, UtxoProcessor, UtxoContext, type RpcClient } from "../../wasm/kaspa";
import Monitoring from '../monitoring';
import { DEBUG } from "../index";

export default class trxManager {
export default class trxManager extends EventEmitter {
private networkId: string;
private privateKey: PrivateKey;
private address: string;
Expand All @@ -14,6 +15,7 @@ export default class trxManager {


constructor(networkId: string, privKey: string, databaseUrl: string, rpc: RpcClient) {
super()
this.monitoring = new Monitoring();
this.networkId = networkId;
if (DEBUG) this.monitoring.debug(`TrxManager: Network ID is: ${this.networkId}`);
Expand Down Expand Up @@ -71,12 +73,14 @@ export default class trxManager {
});

for (const transaction of transactions) {
if (DEBUG) this.monitoring.debug(`TrxManager: Payment with ransaction ID: ${transaction.id} to be signed`);
await transaction.sign([this.privateKey]);
if (DEBUG) this.monitoring.debug(`TrxManager: Payment with ransaction ID: ${transaction.id} to be submitted`);
await transaction.submit(this.processor.rpc);
if (DEBUG) this.monitoring.debug(`TrxManager: Payment with ransaction ID: ${transaction.id} submitted`);
await new Promise(resolve => setTimeout(resolve, 5000)); // 5-second delay
if (DEBUG) this.monitoring.debug(`TrxManager: Payment with transaction ID: ${transaction.id} to be signed`);
transaction.sign([this.privateKey]);
this.on('time-to-submit', () => {
if (DEBUG) this.monitoring.debug(`TrxManager: Payment with transaction ID: ${transaction.id} to be submitted`);
transaction.submit(this.processor.rpc);
if (DEBUG) this.monitoring.debug(`TrxManager: Payment with transaction ID: ${transaction.id} submitted`);
//await new Promise(resolve => setTimeout(resolve, 5000)); // 5-second delay
})
}

if (DEBUG) this.monitoring.debug(`TrxManager: summary.finalTransactionId: ${summary.finalTransactionId}`);
Expand All @@ -92,12 +96,13 @@ export default class trxManager {
if (DEBUG) this.monitoring.debug(`TrxManager: registerProcessor - tracking pool address`);
await this.context.trackAddresses([ this.address ])
})
this.processor.start()
}

// stopProcessor () {
// this.processor.stop()
// }
this.processor.addEventListener('maturity', () => {
if (DEBUG) this.monitoring.debug(`TrxManager: maturity event`)
this.emit('time-to-submit')
})

this.processor.start()
}

}

0 comments on commit 9b54296

Please sign in to comment.