-
Notifications
You must be signed in to change notification settings - Fork 14
/
start.js
38 lines (34 loc) · 1.15 KB
/
start.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
/*jslint node: true */
"use strict";
var fs = require('fs');
var desktopApp = require('ocore/desktop_app.js');
var appDataDir = desktopApp.getAppDataDir();
var path = require('path');
if (require.main === module && !fs.existsSync(appDataDir) && fs.existsSync(path.dirname(appDataDir)+'/byteball-relay')){
console.log('=== will rename old relay data dir');
fs.renameSync(path.dirname(appDataDir)+'/byteball-relay', appDataDir);
}
var conf = require('ocore/conf.js');
var myWitnesses = require('ocore/my_witnesses.js');
function replaceConsoleLog(){
var clog = console.log;
console.log = function(){
Array.prototype.unshift.call(arguments, new Date().toISOString()+':');
clog.apply(null, arguments);
}
}
function start(){
console.log('starting');
var network = require('ocore/network.js');
if (conf.initial_peers)
conf.initial_peers.forEach(function(url){
network.findOutboundPeerOrConnect(url);
});
}
replaceConsoleLog();
myWitnesses.readMyWitnesses(function(arrWitnesses){
if (arrWitnesses.length > 0)
return start();
console.log('will init witnesses', conf.initial_witnesses);
myWitnesses.insertWitnesses(conf.initial_witnesses, start);
}, 'ignore');