UNPKG

intchains_ibctminer

Version:

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

91 lines (84 loc) 2.79 kB
const EventEmitter = require('events'); const Debug = require('../log')(); const COMP = '[cpu]'; class cpu extends EventEmitter { constructor({ devPath, algo, varity, crypto }) { super(); var _this = this; _this.devPath = devPath; _this.algo = algo; _this.varity = varity; _this.crypto = crypto; _this.MinerShouldStop = false; Debug.IbctLogDbg(COMP, 'DevPath: ', _this.devPath, '; Miner:CPU; Algo:', _this.algo.getAlgoName(), '; Crypto: ', _this.crypto.getCryptoName()); } getInfo() { /* 返回矿机信息,包括矿机名,固件版本。*/ Debug.IbctLogDbg(COMP, 'getInfo'); } async init(params) { /* 初始化硬件 */ Debug.IbctLogDbg(COMP, 'init'); } async setDevice() { /* 设置Miner参数,电压, 频率,目标温度,报警温度。 */ Debug.IbctLogDbg(COMP, 'setDevice'); } async stopScanWork() { this.MinerShouldStop = true; } async scanWork(Job, Callback) { /* 更新Work */ var _this = this; var result; if (!_this.algo || !_this.crypto) { Callback('Set Algo or Crypto First'); return } _this.MinerShouldStop = false; _this.work = Job; Job.snonce = 0xffffaaaaffffaaaa; for (var i = Job.snonce; i <= (Job.snonce + 0x10); i++) { Debug.IbctLogInfo(COMP, 'scanWork ', i.toString('16'), '12: ', Job.snonce.toString('16')); if (_this.crypto.setWorkData) { _this.crypto.setWorkData(_this.work, 'start nonce', i); } if (_this.algo.genHash) { result = _this.algo.genHash(_this.work.data, _this.work.data.length, 0x30); Debug.IbctLogInfo(COMP, result, _this.crypto.checkHash(_this.work.target, Buffer.from(result, 'hex'))); if (_this.crypto.checkHash && _this.crypto.checkHash(_this.work.target, Buffer.from(result, 'hex'))) { Debug.IbctLogDbg(COMP, 'Nonce:', Job.snonce); Callback(null, Job.snonce); } } break; } Callback(null, null); } async stop() { /* 停止硬件工作并关闭硬件 */ Debug.IbctLogDbg(COMP, 'stop'); } async getState() { /* 获取当前设备状态, 温度,电压,频率,功耗等 */ Debug.IbctLogDbg(COMP, 'getState'); } } module.exports = function Getcpu(options = {}) { return new cpu(options); };