forked from 0xbitcoin/0xbitcoin-miner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
227 lines (145 loc) · 5.69 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const Miner = require("./0xbitcoinminer-accel");
const Vault = require("./lib/vault");
const miningLogger = require("./lib/mining-logger");
var prompt = require('prompt');
var pjson = require('./package.json');
var Web3 = require('web3')
var ContractInterface = require("./contracts/DeployedContractInfo")
var NetworkInterface = require("./lib/network-interface");
var PoolInterface = require("./lib/pool-interface");
var web3 = new Web3( );
var running = true;
console.log('Welcome to 0xBitcoin Miner!')
console.log('Version: ',pjson.version)
console.log('\n')
console.log('Type a command to get started. Type "help" for a list of commands.')
console.log('\n')
async function initPrompt()
{
var result = await promptForCommand();
initPrompt();
}
async function promptForCommand()
{
return new Promise(function (fulfilled,rejected) {
console.log('\n')
prompt.start();
prompt.get(['command'], async function (err, result) {
if(err){
console.log(err);
rejected(err);
}else{
var response = await handleCommand(result)
fulfilled( response );
}
});
});
}
initPrompt();
/*
if (process.argv.length <= 2) {
console. log("Please add a subsystem parameter (use 'npm run help' for help)");
process. exit(-1);
}
var subsystem_name = process.argv[2] ;
var subsystem_command = process.argv[3] ;
var subsystem_option = process.argv[4] ;
*/
async function handleCommand(result)
{
var split_command = result.command.split(' ');
//console.log( split_command )
var subsystem_name = split_command[0] ;
var subsystem_command = split_command[1] ;
var subsystem_option = split_command[2] ;
if(subsystem_name == 'account')
{
if(subsystem_command === 'new' || subsystem_command === 'list' )
{
Vault.requirePassword(true) //for encryption of private key !
}
var unlocked = await Vault.init(web3,miningLogger);
if(!unlocked)return false;
await Vault.handleAccountCommand(subsystem_command,subsystem_option)
}
if(subsystem_name == 'contract')
{
var unlocked = await Vault.init(web3,miningLogger);
if(!unlocked)return false;
await Vault.handleContractCommand(subsystem_command,subsystem_option)
}
if(subsystem_name == 'config')
{
var unlocked = await Vault.init(web3,miningLogger);
if(!unlocked)return false;
await Vault.handleConfigCommand(subsystem_command,subsystem_option)
}
if(subsystem_name == 'mine')
{
Vault.requirePassword(true) //for encryption of private key !
var unlocked = await Vault.init(web3,miningLogger);
if(!unlocked)return false;
NetworkInterface.init(web3, Vault, miningLogger);
Miner.init( web3, Vault, miningLogger );
Miner.setNetworkInterface( NetworkInterface );
Miner.setMiningStyle("solo")
Miner.mine(subsystem_command,subsystem_option)
}
//mining test
if(subsystem_name == 'test' && subsystem_command == 'mine')
{
Vault.requirePassword(true) //for encryption of private key !
var infura_provider_url = 'https://ropsten.infura.io/gmXEVo5luMPUGPqg6mhy';
var ropsten_contract_address = ContractInterface.networks.testnet.contracts._0xbitcointoken.blockchain_address
Vault.setWeb3ProviderUrl(infura_provider_url);
Vault.selectContract(ropsten_contract_address);
web3.setProvider(infura_provider_url)
var unlocked = await Vault.init(web3,miningLogger);
if(!unlocked)return false;
web3.setProvider(infura_provider_url)
Vault.selectContract(ropsten_contract_address);
NetworkInterface.init(web3, Vault, miningLogger);
Miner.init( web3, Vault, miningLogger );
Miner.setNetworkInterface( NetworkInterface );
Miner.setMiningStyle("solo")
Miner.mine(subsystem_command,subsystem_option)
}
if(subsystem_name == 'pool')
{
var unlocked = await Vault.init(web3,miningLogger);
if(!unlocked)return false;
await PoolInterface.init(web3, subsystem_command, Vault, miningLogger);
await PoolInterface.handlePoolCommand(subsystem_command,subsystem_option)
if( subsystem_command == "mine" ){
Miner.init( web3 , Vault, miningLogger );
Miner.setNetworkInterface( PoolInterface );
Miner.setMiningStyle("pool")
Miner.mine(subsystem_command,subsystem_option)
}
}
if(subsystem_name == 'help')
{
console.log('\n\n')
console.log('--0xBitcoin Miner Help--\n')
console.log('Available commands:\n')
console.log('"account new" - Create a new mining account ')
console.log('"account list" - List all mining accounts ')
console.log('"account select 0x####" - Select a primary mining account by address ')
console.log('"account balance" - List the ether and token balance of your selected account ')
console.log('"contract list" - List the selected token contract to mine')
console.log('"contract select 0x####" - Select a PoW token contract to mine ')
console.log('"config list" - Show your current configuration')
console.log('"config gasprice #" - Set the gasprice used to submit PoW to the token smartcontract ')
// console.log('"config cpu_threads #" - Set the number of CPU cores to use for mining ')
console.log('"config web3provider http://----:####" - Set the web3 provider url for submitting ethereum transactions ')
console.log('"pool mine" - Begin mining into a pool')
console.log('"pool list" - List the selected mining pool')
console.log('"pool select http://####.com:####" - Select a pool to mine into ')
console.log('"test mine" - Begin mining on Ropsten ')
console.log('"mine" - Begin mining ')
// console.log('\n')
// console.log('Encrypted data vault stored at '+ Vault.get0xBitcoinLocalFolderPath())
console.log('\n\n')
}
}
//init();