-
Notifications
You must be signed in to change notification settings - Fork 4
/
iminer.js
93 lines (75 loc) · 1.99 KB
/
iminer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const argv = require('yargs').argv;
const fs = require('fs');
const DB = require('./DB').DB;
const Miner = require('./Miner');
const CONFIG_FILENAME = 'config.json';
const MINER_LOAD_LIMIT = 90;
let config = {
dbhost : 'localhost',
dbname : 'trinity',
dbuser : 'root',
dbpass : '',
loglevel : 'info',
load: 10,
port : 0,
difficulty: 18,
reward_ratio : {
pos : 4000,
poa: 4000,
pow: 1600,
ref: 400,
},
mode:'verify'
};
console.trace = function (...msg) {
console.log(...msg);
};
console.debug = function (...msg) {
console.log(...msg);
};
console.silly = function (...msg) {
console.log(...msg);
};
console.fatal = function (...msg) {
console.log(...msg);
process.exit(1);
};
console.info("Application started");
let config_filename = argv.config || CONFIG_FILENAME;
console.info('Loading config from', config_filename, '...');
let cfg = {};
try {
cfg = JSON.parse(fs.readFileSync(config_filename, 'utf8'));
config = Object.assign(config, cfg);
} catch (e) {
console.info('No configuration file found.')
}
config = Object.assign(config, argv);
console.info(`config = ${JSON.stringify(config)}`);
require('console-stamp')(console, {datePrefix: '[', pattern:'yyyy.mm.dd HH:MM:ss', level: config.loglevel, extend:{fatal:0, debug:4, trace:5, silly:6}, include:['silly', 'trace','debug','info','warn','error','fatal']});
let db = new DB({
host: config.dbhost,
port: config.dbport,
user: config.dbuser,
database: config.dbname,
password: config.dbpass.toString(),
dateStrings: true,
multipleStatements: true
},config);
BigInt.prototype.toJSON = function() { return this.toString() }
let start_miner = function(config, db) {
let load = Math.min(config.load, MINER_LOAD_LIMIT);
console.info(`Starting miner with load ${load}`);
let miner = new Miner(config, db);
};
/*
let starter = async function(config, db, callback) {
if(!db.isConnected){
setTimeout(starter, 1000, config, db, callback);
return;
}
callback(config, db);
};
starter(config, db, start_miner);
*/
start_miner(config, db);