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.
61 lines
1.4 KiB
61 lines
1.4 KiB
/*!
|
|
* tracker/tracker.js
|
|
* Copyright © 2019 – Katana Cryptographic Ltd. All Rights Reserved.
|
|
*/
|
|
'use strict'
|
|
|
|
const zmq = require('zeromq/v5-compat')
|
|
const network = require('../lib/bitcoin/network')
|
|
const keys = require('../keys')[network.key]
|
|
const BlockchainProcessor = require('./blockchain-processor')
|
|
const MempoolProcessor = require('./mempool-processor')
|
|
const util = require('../lib/util')
|
|
|
|
|
|
/**
|
|
* A class implementing a process tracking the blockchain
|
|
*/
|
|
class Tracker {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
constructor() {
|
|
// Notification socket for client events
|
|
this.notifSock = zmq.socket('pub')
|
|
this.notifSock.bind(`tcp://127.0.0.1:${keys.ports.tracker}`, () => {
|
|
// Initialize the blockchain processor
|
|
// and the mempool buffer
|
|
this.initialized = true
|
|
this.blockchainProcessor = new BlockchainProcessor(this.notifSock)
|
|
this.mempoolProcessor = new MempoolProcessor(this.notifSock)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Start the tracker
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async start() {
|
|
if (!this.initialized) {
|
|
await util.delay(1000)
|
|
|
|
return this.start()
|
|
}
|
|
|
|
await this.blockchainProcessor.start()
|
|
await this.mempoolProcessor.start()
|
|
}
|
|
|
|
/**
|
|
* Stop the tracker
|
|
*/
|
|
async stop() {
|
|
clearTimeout(this.startupTimeout)
|
|
await this.blockchainProcessor.stop()
|
|
await this.mempoolProcessor.stop()
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Tracker
|
|
|