You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

5 years ago
/*!
* tracker/tracker.js
* Copyright © 2019 Katana Cryptographic Ltd. All Rights Reserved.
*/
'use strict'
const zmq = require('zeromq')
const network = require('../lib/bitcoin/network')
const keys = require('../keys')[network.key]
const BlockchainProcessor = require('./blockchain-processor')
const MempoolProcessor = require('./mempool-processor')
/**
* A class implementing a process tracking the blockchain
*/
class Tracker {
/**
* Constructor
*/
constructor() {
// Notification socket for client events
this.notifSock = zmq.socket('pub')
this.notifSock.bindSync(`tcp://*:${keys.ports.tracker}`)
// Initialize the blockchain processor
// and the mempool buffer
this.blockchainProcessor = new BlockchainProcessor(this.notifSock)
this.mempoolProcessor = new MempoolProcessor(this.notifSock)
}
/**
* Start the tracker
* @returns {Promise}
*/
async start() {
this.startupTimeout = setTimeout(async function() {
await this.blockchainProcessor.start()
await this.mempoolProcessor.start()
}.bind(this), 1500)
}
/**
* Stop the tracker
*/
async stop() {
clearTimeout(this.startupTimeout)
await this.blockchainProcessor.stop()
await this.mempoolProcessor.stop()
}
}
module.exports = Tracker