'use strict';
const UTXOPlasmaBlockChain = require("../lib/UTXOPlasmaBlockChain")
const MongoDB = require("../lib/MongoDB");
/**
* BeOn block chain
* @extends UTXOPlasmaBlockChain
*/
class BeOnBlockChain extends UTXOPlasmaBlockChain {
/**
* Create a BeOn block chain with the configuration object
* @param {Object} config configuration object
*/
constructor(config) {
super(config, MongoDB)
}
/**
* Start mining process on the chain
* @param {number} checkInterval interval to check for pending transactions and generate a block
*/
startMining(checkInterval = 500) {
if (this.mineTimer) {
clearInterval(this.mineTimer);
}
let running = false;
this.mineTimer = setInterval(async () => {
if(running){
return;
}
running = true;
try {
await this.generateNextBlock();
} catch (e) {
console.log(e);
throw e;
}
running = false;
}, checkInterval);
return this;
}
}
module.exports = BeOnBlockChain;