UNPKG

ibctminer

Version:

```js const IntMiner = require('./src'); const Debug = require('./src/log')(); const fs = require('fs'); const COMP = '[SIPC]';

67 lines (61 loc) 1.47 kB
const scryptNightApi = require('./scryptNight'); const scryptApi = require('./scryptApi'); const sparkApi = require('./sparkApi'); const blake2bsha3Api = require('./blake2bsha3Api'); const EventEmitter = require('events'); const Debug = require('../log')(); const COMP = '[algo]'; const algorithms = [ { name: 'scrypt', api: scryptApi }, { name: 'scryptNight-v4', api: scryptNightApi }, { name: 'scryptNight-v2', api: scryptNightApi }, { name: 'spark', api: sparkApi }, { name: 'blake2bsha3', api: blake2bsha3Api } ]; class algoApi extends EventEmitter { constructor({ name }) { super(); var _this = this; _this.name = name; _this.algorithm = this.GetAlgorithmApi(_this.name); if (!_this.algorithm) { _this.emit('error', __('不支持此种算法:'), _this.name); } return _this; } GetAlgorithmApi(name) { var algo = null; algorithms.forEach(function (algorithm, index) { if (algorithm.name === name) { algo = algorithm; } }) return algo ? algo.api() : null; } getAlgoName() { return this.algorithm ? this.algorithm.getAlgoName() : null; } genHash(data, length, varity) { return this.algorithm ? this.algorithm.genHash(data, length, varity) : null; } }; module.exports = function RunAlgoApi(options = {}) { return new algoApi(options); };