forked from snissn/tokenpool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
167 lines (121 loc) · 4.78 KB
/
index.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var INFURA_ROPSTEN_URL = 'https://ropsten.infura.io/gmXEVo5luMPUGPqg6mhy';
var INFURA_MAINNET_URL = 'https://mainnet.infura.io/gmXEVo5luMPUGPqg6mhy';
var https_enabled = process.argv[2] === 'https';
var pool_env = 'production';
if( process.argv[2] == "test" )
{
pool_env = 'test'
}
if( process.argv[2] == "staging" )
{
pool_env = 'staging'
}
var cluster = require('cluster')
const poolConfig = require('./pool.config').config
console.log(poolConfig)
console.log('init');
fs = require('fs');
var redisInterface = require('./lib/redis-interface')
var peerInterface = require('./lib/peer-interface')
var tokenInterface = require('./lib/token-interface')
var webInterface = require('./lib/web-interface')
var webServer = require('./lib/web-server')
var diagnosticsManager = require('./lib/diagnostics-manager')
var accountConfig;
var Web3 = require('web3')
var web3 = new Web3()
var specified_web3 = poolConfig.web3provider;
if(specified_web3 != null)
{
web3.setProvider(specified_web3)
console.log('using web3',specified_web3)
}
if(pool_env == "test"){
console.log("Using test mode!!! - Ropsten ")
if(specified_web3 == null)
{
web3.setProvider(INFURA_ROPSTEN_URL)
}
accountConfig = require('./test.account.config').accounts;
}else if(pool_env == "staging"){
console.log("Using staging mode!!! - Mainnet ")
if(specified_web3 == null)
{
web3.setProvider(INFURA_MAINNET_URL)
}
accountConfig = require('./account.config').accounts;
}else{
if(specified_web3 == null)
{
web3.setProvider(INFURA_MAINNET_URL)
}
accountConfig = require('./account.config').accounts;
}
init(web3);
/*
async function init(web3)
{
// Code to run if we're in the master process
if (cluster.isMaster) {
// Count the machine's CPUs
// var cpuCount = require('os').cpus().length;
// Create a worker for each CPU
for (var i = 0; i < 6; i += 1) {
cluster.fork();
}
await redisInterface.init()
await webInterface.init(web3,accountConfig,poolConfig,redisInterface)
await tokenInterface.init(redisInterface,web3,accountConfig,poolConfig,pool_env)
await peerInterface.init(web3,accountConfig,poolConfig,redisInterface,tokenInterface,pool_env) //initJSONRPCServer();
await diagnosticsManager.init(redisInterface,webInterface,peerInterface)
await webServer.init(https_enabled,webInterface,peerInterface)
// Code to run if we're in a worker process
} else {
var worker_id = cluster.worker.id
if(worker_id == 1)
{
await redisInterface.init()
await tokenInterface.init(redisInterface,web3,accountConfig,poolConfig,pool_env)
await peerInterface.init(web3,accountConfig,poolConfig,redisInterface,tokenInterface,pool_env) //initJSONRPCServer();
tokenInterface.update();
peerInterface.update();
}
if(worker_id == 2)
{
await redisInterface.init()
await tokenInterface.init(redisInterface,web3,accountConfig,poolConfig,pool_env)
await peerInterface.init(web3,accountConfig,poolConfig,redisInterface,tokenInterface,pool_env) //initJSONRPCServer();
//tokenInterface.update();
peerInterface.listenForJSONRPC(8080);
}
}
}
*/
async function init(web3)
{
// Code to run if we're in the master process
if (cluster.isMaster) {
// Create a worker for each CPU
for (var i = 0; i < 8; i += 1) {
cluster.fork();
}
await redisInterface.init()
await webInterface.init(web3,accountConfig,poolConfig,redisInterface)
await tokenInterface.init(redisInterface,web3,accountConfig,poolConfig,pool_env)
await peerInterface.init(web3,accountConfig,poolConfig,redisInterface,tokenInterface,pool_env) //initJSONRPCServer();
await diagnosticsManager.init(redisInterface,webInterface,peerInterface)
await webServer.init(https_enabled,webInterface,peerInterface)
peerInterface.update();
// Code to run if we're in a worker process
} else {
var worker_id = cluster.worker.id
await redisInterface.init()
await tokenInterface.init(redisInterface,web3,accountConfig,poolConfig,pool_env)
await peerInterface.init(web3,accountConfig,poolConfig,redisInterface,tokenInterface,pool_env) //initJSONRPCServer();
await redisInterface.init()
await tokenInterface.init(redisInterface,web3,accountConfig,poolConfig,pool_env)
peerInterface.listenForJSONRPC(8080);
tokenInterface.update();
peerInterface.update();
}
}