Skip to content

Commit 94151f6

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 882182f + 35eb665 commit 94151f6

File tree

17 files changed

+181
-127
lines changed

17 files changed

+181
-127
lines changed

.eslintrc.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": ["standard"],
7+
"globals": {
8+
"Atomics": "readonly",
9+
"SharedArrayBuffer": "readonly"
10+
},
11+
"parserOptions": {
12+
"ecmaVersion": 2018,
13+
"sourceType": "module"
14+
},
15+
"rules": {
16+
}
17+
};

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"show_coverage": "node src/tests/browser/show-coverage.test.js",
2121
"build_terminal_worker": "webpack --config build_webpack/webpack.terminal-worker.config.js",
2222
"commands": "npm run build_terminal_menu && npm run build_terminal_worker && node --max_old_space_size=10240 dist_bundle/terminal-menu-bundle.js",
23-
"test": "mocha-webpack"
23+
"test": "mocha-webpack",
24+
"lint": "eslint --ext .js src/consts"
2425
},
2526
"repository": {
2627
"type": "git",
@@ -100,6 +101,13 @@
100101
"compression-webpack-plugin": "^1.1.9",
101102
"cross-env": "^5.1.3",
102103
"eslint": "^5.10.0",
104+
"eslint-config-standard": "^12.0.0",
105+
"eslint-plugin-import": "^2.16.0",
106+
"eslint-plugin-node": "^8.0.1",
107+
"eslint-plugin-promise": "^4.0.1",
108+
"eslint-plugin-standard": "^4.0.0",
109+
"eslint-friendly-formatter": "^3.0.0",
110+
"eslint-loader": "^1.7.1",
103111
"express": "^4.16.3",
104112
"extract-text-webpack-plugin": "^3.0.2",
105113
"friendly-errors-webpack-plugin": "^1.6.1",

src/common/blockchain/interface-blockchain/mining/Interface-Blockchain-Mining.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class InterfaceBlockchainMining extends InterfaceBlockchainMiningBasic{
214214
}
215215

216216
} else
217-
if (!answer.result)
217+
if (!(answer && answer.result))
218218
console.error( "block ", block.height ," was not mined...");
219219

220220
if (this.reset) { // it was reset
@@ -479,4 +479,4 @@ class InterfaceBlockchainMining extends InterfaceBlockchainMiningBasic{
479479

480480
}
481481

482-
export default InterfaceBlockchainMining;
482+
export default InterfaceBlockchainMining;

src/common/blockchain/interface-blockchain/mining/transactions-selector/Mining-Transactions-Selector.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ class MiningTransactionsSelector{
5555
// if (transaction.timeLock !== 0 && this.blockchain.blocks.length-1 < transaction.timeLock )
5656
// throw { message: "blockHeight < timeLock", timeLock: transaction.timeLock, blockHeight: this.blockchain.blocks.length-1 };
5757

58+
//validating its own transaction
59+
if (transaction.from.addresses[0].unencodedAddress.equals( this.blockchain.mining.unencodedMinerAddress ) )
60+
return true;
61+
5862
if( transaction.timeLock + consts.BLOCKCHAIN.FORKS.IMMUTABILITY_LENGTH/2 < this.blockchain.blocks.length )
5963
throw {message: "transaction is too old"};
6064

6165
if( transaction.timeLock - consts.BLOCKCHAIN.FORKS.IMMUTABILITY_LENGTH/2 > this.blockchain.blocks.length )
6266
throw {message: "transaction is in future"};
6367

64-
//validating its own transaction
65-
if (transaction.from.addresses[0].unencodedAddress.equals( this.blockchain.mining.unencodedMinerAddress ) )
66-
return true;
67-
6868
//verify fee
6969
if (transaction.fee < this.blockchain.transactions.wizard.calculateFeeWizzard( transaction.serializeTransaction(), miningFeePerByte ) )
7070
throw {message: "fee is too small"};
@@ -129,7 +129,7 @@ class MiningTransactionsSelector{
129129
bRemoveTransaction = true;
130130

131131
} catch (exception){
132-
//console.warn('Error Including Transaction', exception);
132+
console.warn('Error Including Transaction', exception);
133133

134134
if(!missingFirstNonce)
135135
if( exception.message === 'Nonce is invalid' || exception.message === 'Nonce is not right 2' || exception.message === 'Nonce is not right' ){
@@ -152,6 +152,8 @@ class MiningTransactionsSelector{
152152

153153
} catch (exception){
154154

155+
console.warn('Error Including Transaction', exception);
156+
155157
}
156158

157159
console.log(infoTx);

src/common/mining-pools/miner/Miner-Pool-Settings.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ class MinerPoolSettings {
231231

232232
await this.addPoolList("/pool/1/BACMpool/0.01/21dc1f57cb7338963ea159877b4ade97b71dd11ac17292e3852bdc33a26a17e4/https:$$pool.bacm.ro:443", undefined, true);
233233
await this.addPoolList("/pool/1/Balanel_si_Miaunel/0.02/cd7217ad76118df5357ae7a094aa48096daae8a67767bd3acbc8638dc68955ac/https:$$webd.pool.coffee:8443", undefined, true);
234-
await this.addPoolList("/pool/1/WMP/0.02/773a8d5f7ce3c0dba0b7216c35d2768b1a6abef716fa2a46d875d6ca0e2c115e/https:$$server.webdollarminingpool.com:443", undefined, true);
235-
await this.addPoolList("/pool/1/WebDollarPoolWin/0.01/f1b0f18143178cbc6edd3fa8ae0183a60f58a1791a094d2616632b8a542efd73/https:$$webdollarpool.win:8888", undefined, true);
234+
await this.addPoolList("/pool/1/WMP/0.02/d02e26e60a5b0631a0b71e7dc72bb7492fd018dad64531498df369ec14f87962/https:$$server.webdollarminingpool.com:443", undefined, true);
235+
await this.addPoolList("/pool/1/WMP-ASIA/0.02/773a8d5f7ce3c0dba0b7216c35d2768b1a6abef716fa2a46d875d6ca0e2c115e/https:$$singapore.webdollarminingpool.com:443", undefined, true);
236+
await this.addPoolList("/pool/1/WebDollarPoolWin/0.01/60ba45707efcf2292e1c8d4c6a16b602a58aa8bee04d7d3645198afa4f8435e0/https:$$webdollarpool.win:80", undefined, true);
236237

237238
}
238239

src/common/mining-pools/miner/mining/Miner-Pool-Mining.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class MinerPoolMining extends InheritedPoolMining {
168168

169169
let timeInitial = new Date().getTime();
170170

171-
this._isBeingMining = new Promise( async (resolve)=>{
171+
this._isBeingMining = new Promise( async (resolve) => {
172172

173173
try {
174174

@@ -179,20 +179,22 @@ class MinerPoolMining extends InheritedPoolMining {
179179

180180
let answer = await this._run();
181181

182-
if (!answer) answer = {
183-
hash: consts.BLOCKCHAIN.BLOCKS_MAX_TARGET_BUFFER,
184-
nonce: 0,
185-
};
182+
if (!answer) {
183+
await Blockchain.blockchain.sleep(10000); // nu mineaza, poate dormi
184+
resolve(false);
185+
return false;
186+
}
186187

187188
answer.timeDiff = new Date().getTime() - timeInitial;
188189
answer.id = workId;
189190
answer.h = workHeight;
190191

191-
if (!this._miningWork.resolved)
192+
if (answer.hashes != 0)
192193
answer.hashes = workEnd - workStart;
193194

194-
this.resetForced = false;
195-
this._miningWork.resolved = true;
195+
if (!this.resetForced)
196+
this._miningWork.resolved = true;
197+
else this.resetForced = false;
196198

197199
this.minerPoolManagement.minerPoolProtocol.pushWork( answer, this._miningWork.poolSocket );
198200

@@ -210,6 +212,7 @@ class MinerPoolMining extends InheritedPoolMining {
210212
await this._isBeingMining;
211213

212214
} catch (exception) {
215+
console.log("Pool Mining Exception 2", exception);
213216
}
214217

215218
}

src/consts/const_run_time.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exports.debug = false
1+
exports.debug = false

src/consts/const_testing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exports.debug = true
1+
exports.debug = true

src/consts/global.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
let global = {};
1+
let global = {}
22

3-
global.TERMINATED = false;
4-
global.MINIBLOCKCHAIN_LIGHT_CONFIGURATION_SAVED = true;
5-
global.MINIBLOCKCHAIN_LIGHT_SAVED = true;
6-
global.MINIBLOCKCHAIN_ADVANCED_SAVED = true;
7-
global.POOL_SAVED = true;
8-
global.INTERFACE_BLOCKCHAIN_SAVED = true;
9-
global.INTERFACE_BLOCKCHAIN_LOADING = false;
10-
global.SEMAPHORE_PROCESS_DONE = true;
3+
global.TERMINATED = false
4+
global.MINIBLOCKCHAIN_LIGHT_CONFIGURATION_SAVED = true
5+
global.MINIBLOCKCHAIN_LIGHT_SAVED = true
6+
global.MINIBLOCKCHAIN_ADVANCED_SAVED = true
7+
global.POOL_SAVED = true
8+
global.INTERFACE_BLOCKCHAIN_SAVED = true
9+
global.INTERFACE_BLOCKCHAIN_LOADING = false
10+
global.SEMAPHORE_PROCESS_DONE = true
1111

12-
export default global
12+
export default global

src/node/jsonRpc/Methods/Account/DeleteAccount.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {authenticatedMethod, RpcMethod} from './../../../../jsonRpc';
2-
import {isEmpty} from 'lodash';
2+
import {isEmpty, isString} from 'lodash';
3+
34
/**
45
* Delete an account from the wallet
56
*/
6-
class DeleteAccount extends RpcMethod
7-
{
7+
class DeleteAccount extends RpcMethod {
88
constructor(name, oWallet) {
99
super(name);
1010
this._oWallet = oWallet;
@@ -16,21 +16,30 @@ class DeleteAccount extends RpcMethod
1616

1717
let oAddress = this._oWallet.getAddress(sAddress);
1818

19-
if (oAddress === null)
20-
{
19+
if (oAddress === null) {
2120
throw new Error('Account not found.');
2221
}
2322

24-
if (await this._oWallet.isAddressEncrypted(oAddress) && isEmpty(sPassword))
25-
{
23+
const bAddressIsEncrypted = await this._oWallet.isAddressEncrypted(oAddress);
24+
25+
if (bAddressIsEncrypted && (isEmpty(sPassword) || isString(sPassword) === false)) {
2626
throw new Error('Account is encrypted and a password was not provided. (Password must be provided as the second parameter).');
2727
}
2828

29-
let oDeleteResult = await this._oWallet.deleteAddress(oAddress, false, sPassword);
29+
let oDeleteResult = await this._oWallet.deleteAddress(oAddress, false, bAddressIsEncrypted ? sPassword.split(' ') : null);
30+
31+
if (oDeleteResult.result === false) {
32+
if (bAddressIsEncrypted) {
33+
// try also with the password as non-array
34+
oDeleteResult = await this._oWallet.deleteAddress(oAddress, false, sPassword);
3035

31-
if (oDeleteResult.result === false)
32-
{
33-
throw new Error(`Unable to delete the account. Reason: ${oDeleteResult.message}`);
36+
if (oDeleteResult.result === false) {
37+
throw new Error(`Unable to delete the account. Reason: ${oDeleteResult.message}`);
38+
}
39+
}
40+
else {
41+
throw new Error(`Unable to delete the account. Reason: ${oDeleteResult.message}`);
42+
}
3443
}
3544

3645
return true;

src/node/jsonRpc/Methods/Account/EncryptAccount.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import MnemonicWords from 'mnemonic.js';
44
/**
55
* Encrypt an account from the wallet
66
*/
7-
class DeleteAccount extends RpcMethod
8-
{
7+
class EncryptAccount extends RpcMethod {
98
constructor(name, oWallet) {
109
super(name);
1110
this._oWallet = oWallet;
@@ -15,29 +14,25 @@ class DeleteAccount extends RpcMethod
1514
let sAddress = args[0] || null;
1615
let oAddress = this._oWallet.getAddress(sAddress);
1716

18-
if (oAddress === null)
19-
{
17+
if (oAddress === null) {
2018
throw new Error('Account not found.');
2119
}
2220

23-
if (await this._oWallet.isAddressEncrypted(oAddress))
24-
{
21+
if (await this._oWallet.isAddressEncrypted(oAddress)) {
2522
throw new Error('Account is already encrypted.');
2623
}
2724

2825
const sPassword = (new MnemonicWords(4 * 32)).toWords(4 * 32).join(' ');
29-
const bEncryptedSuccessfully = await this._oWallet.encryptAddress(oAddress, sPassword);
26+
const bEncryptedSuccessfully = await this._oWallet.encryptAddress(oAddress, sPassword.split(' '));
3027

3128
// Only check against "true" because the way encryptAddress() method returns the results
32-
if (bEncryptedSuccessfully === true)
33-
{
29+
if (bEncryptedSuccessfully === true) {
3430
return sPassword;
3531
}
36-
else
37-
{
32+
else {
3833
throw new Error('Unable to encrypt account.');
3934
}
4035
}
4136
}
4237

43-
export default authenticatedMethod(DeleteAccount);
38+
export default authenticatedMethod(EncryptAccount);

src/node/jsonRpc/Methods/Account/ExportAccount.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {authenticatedMethod, RpcMethod} from './../../../../jsonRpc';
33
/**
44
* Export an existing account from the wallet
55
*/
6-
class ExportAccount extends RpcMethod
7-
{
6+
class ExportAccount extends RpcMethod {
87
constructor(name, oWallet) {
98
super(name);
109
this._oWallet = oWallet;
@@ -14,15 +13,13 @@ class ExportAccount extends RpcMethod
1413
let sAddress = args[0] || null;
1514
let oAddress = this._oWallet.getAddress(sAddress);
1615

17-
if (oAddress === null)
18-
{
16+
if (oAddress === null) {
1917
throw new Error('Account not found.');
2018
}
2119

2220
const aExportResult = await this._oWallet.exportAddressToJSON(oAddress.address);
2321

24-
if (aExportResult.result === false)
25-
{
22+
if (aExportResult.result === false) {
2623
throw new Error(`Unable to export the account. Reason: ${aExportResult.message}`);
2724
}
2825

src/node/jsonRpc/Methods/Account/ImportAccount.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {isObject} from 'lodash';
44
/**
55
* Import an account into the wallet
66
*/
7-
class ImportAccount extends RpcMethod
8-
{
7+
class ImportAccount extends RpcMethod {
98
constructor(name, oWallet) {
109
super(name);
1110
this._oWallet = oWallet;
@@ -14,15 +13,13 @@ class ImportAccount extends RpcMethod
1413
async getHandler(args) {
1514
let oData = args[0] || null;
1615

17-
if (isObject(oData) === false)
18-
{
16+
if (isObject(oData) === false) {
1917
throw new Error('First parameter must be an Object');
2018
}
2119

2220
const aImportResult = await this._oWallet.importAddressFromJSON(oData);
2321

24-
if (aImportResult.result === false)
25-
{
22+
if (aImportResult.result === false) {
2623
throw new Error(`Unable to import the account. Reason: ${aImportResult.message}`);
2724
}
2825

src/node/jsonRpc/Methods/Account/NewAccount.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import MnemonicWords from 'mnemonic.js';
44
/**
55
* Create a new account into the wallet
66
*/
7-
class NewAccount extends RpcMethod
8-
{
7+
class NewAccount extends RpcMethod {
98
constructor(name, oWallet) {
109
super(name);
1110
this._oWallet = oWallet;
@@ -15,35 +14,30 @@ class NewAccount extends RpcMethod
1514
const bEncrypt = args[0] || false;
1615
let oAddress;
1716

18-
try
19-
{
17+
try {
2018
oAddress = await this._oWallet.createNewAddress();
2119
}
22-
catch (e)
23-
{
20+
catch (e) {
2421
throw new Error(`Unable to create a new account. Reason: ${e.message}`);
2522
}
2623

2724
let aResult = {
2825
address: oAddress.address
2926
};
3027

31-
if (bEncrypt)
32-
{
28+
if (bEncrypt) {
3329
// 3 words per one integer of 32bits => 4 integers * 3 words => 12 words
3430
aResult['password'] = (new MnemonicWords(4 * 32)).toWords(4 * 32).join(' ');
35-
const bEncryptedSuccessfully = await this._oWallet.encryptAddress(oAddress, aResult['password']);
31+
const bEncryptedSuccessfully = await this._oWallet.encryptAddress(oAddress, aResult['password'].split(' '));
3632

3733
// Only check against "true" because the way encryptAddress() method returns the results
38-
if (bEncryptedSuccessfully === true)
39-
{
34+
if (bEncryptedSuccessfully === true) {
4035
return aResult;
4136
}
4237

4338
const aDeleteResult = await this._oWallet.deleteAddress(oAddress);
4439

45-
if (aDeleteResult.result === false)
46-
{
40+
if (aDeleteResult.result === false) {
4741
throw new Error(`Unable to encrypt account. Reason: ${aDeleteResult.message}`);
4842
}
4943

0 commit comments

Comments
 (0)