Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ibudisteanu committed Mar 23, 2019
2 parents 882182f + 35eb665 commit 94151f6
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 127 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": ["standard"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
};
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"show_coverage": "node src/tests/browser/show-coverage.test.js",
"build_terminal_worker": "webpack --config build_webpack/webpack.terminal-worker.config.js",
"commands": "npm run build_terminal_menu && npm run build_terminal_worker && node --max_old_space_size=10240 dist_bundle/terminal-menu-bundle.js",
"test": "mocha-webpack"
"test": "mocha-webpack",
"lint": "eslint --ext .js src/consts"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -100,6 +101,13 @@
"compression-webpack-plugin": "^1.1.9",
"cross-env": "^5.1.3",
"eslint": "^5.10.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"express": "^4.16.3",
"extract-text-webpack-plugin": "^3.0.2",
"friendly-errors-webpack-plugin": "^1.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class InterfaceBlockchainMining extends InterfaceBlockchainMiningBasic{
}

} else
if (!answer.result)
if (!(answer && answer.result))
console.error( "block ", block.height ," was not mined...");

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

}

export default InterfaceBlockchainMining;
export default InterfaceBlockchainMining;
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class MiningTransactionsSelector{
// if (transaction.timeLock !== 0 && this.blockchain.blocks.length-1 < transaction.timeLock )
// throw { message: "blockHeight < timeLock", timeLock: transaction.timeLock, blockHeight: this.blockchain.blocks.length-1 };

//validating its own transaction
if (transaction.from.addresses[0].unencodedAddress.equals( this.blockchain.mining.unencodedMinerAddress ) )
return true;

if( transaction.timeLock + consts.BLOCKCHAIN.FORKS.IMMUTABILITY_LENGTH/2 < this.blockchain.blocks.length )
throw {message: "transaction is too old"};

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

//validating its own transaction
if (transaction.from.addresses[0].unencodedAddress.equals( this.blockchain.mining.unencodedMinerAddress ) )
return true;

//verify fee
if (transaction.fee < this.blockchain.transactions.wizard.calculateFeeWizzard( transaction.serializeTransaction(), miningFeePerByte ) )
throw {message: "fee is too small"};
Expand Down Expand Up @@ -129,7 +129,7 @@ class MiningTransactionsSelector{
bRemoveTransaction = true;

} catch (exception){
//console.warn('Error Including Transaction', exception);
console.warn('Error Including Transaction', exception);

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

} catch (exception){

console.warn('Error Including Transaction', exception);

}

console.log(infoTx);
Expand Down
5 changes: 3 additions & 2 deletions src/common/mining-pools/miner/Miner-Pool-Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ class MinerPoolSettings {

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

}

Expand Down
19 changes: 11 additions & 8 deletions src/common/mining-pools/miner/mining/Miner-Pool-Mining.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class MinerPoolMining extends InheritedPoolMining {

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

this._isBeingMining = new Promise( async (resolve)=>{
this._isBeingMining = new Promise( async (resolve) => {

try {

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

let answer = await this._run();

if (!answer) answer = {
hash: consts.BLOCKCHAIN.BLOCKS_MAX_TARGET_BUFFER,
nonce: 0,
};
if (!answer) {
await Blockchain.blockchain.sleep(10000); // nu mineaza, poate dormi
resolve(false);
return false;
}

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

if (!this._miningWork.resolved)
if (answer.hashes != 0)
answer.hashes = workEnd - workStart;

this.resetForced = false;
this._miningWork.resolved = true;
if (!this.resetForced)
this._miningWork.resolved = true;
else this.resetForced = false;

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

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

} catch (exception) {
console.log("Pool Mining Exception 2", exception);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/consts/const_run_time.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports.debug = false
exports.debug = false
2 changes: 1 addition & 1 deletion src/consts/const_testing.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports.debug = true
exports.debug = true
20 changes: 10 additions & 10 deletions src/consts/global.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
let global = {};
let global = {}

global.TERMINATED = false;
global.MINIBLOCKCHAIN_LIGHT_CONFIGURATION_SAVED = true;
global.MINIBLOCKCHAIN_LIGHT_SAVED = true;
global.MINIBLOCKCHAIN_ADVANCED_SAVED = true;
global.POOL_SAVED = true;
global.INTERFACE_BLOCKCHAIN_SAVED = true;
global.INTERFACE_BLOCKCHAIN_LOADING = false;
global.SEMAPHORE_PROCESS_DONE = true;
global.TERMINATED = false
global.MINIBLOCKCHAIN_LIGHT_CONFIGURATION_SAVED = true
global.MINIBLOCKCHAIN_LIGHT_SAVED = true
global.MINIBLOCKCHAIN_ADVANCED_SAVED = true
global.POOL_SAVED = true
global.INTERFACE_BLOCKCHAIN_SAVED = true
global.INTERFACE_BLOCKCHAIN_LOADING = false
global.SEMAPHORE_PROCESS_DONE = true

export default global
export default global
31 changes: 20 additions & 11 deletions src/node/jsonRpc/Methods/Account/DeleteAccount.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {authenticatedMethod, RpcMethod} from './../../../../jsonRpc';
import {isEmpty} from 'lodash';
import {isEmpty, isString} from 'lodash';

/**
* Delete an account from the wallet
*/
class DeleteAccount extends RpcMethod
{
class DeleteAccount extends RpcMethod {
constructor(name, oWallet) {
super(name);
this._oWallet = oWallet;
Expand All @@ -16,21 +16,30 @@ class DeleteAccount extends RpcMethod

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

if (oAddress === null)
{
if (oAddress === null) {
throw new Error('Account not found.');
}

if (await this._oWallet.isAddressEncrypted(oAddress) && isEmpty(sPassword))
{
const bAddressIsEncrypted = await this._oWallet.isAddressEncrypted(oAddress);

if (bAddressIsEncrypted && (isEmpty(sPassword) || isString(sPassword) === false)) {
throw new Error('Account is encrypted and a password was not provided. (Password must be provided as the second parameter).');
}

let oDeleteResult = await this._oWallet.deleteAddress(oAddress, false, sPassword);
let oDeleteResult = await this._oWallet.deleteAddress(oAddress, false, bAddressIsEncrypted ? sPassword.split(' ') : null);

if (oDeleteResult.result === false) {
if (bAddressIsEncrypted) {
// try also with the password as non-array
oDeleteResult = await this._oWallet.deleteAddress(oAddress, false, sPassword);

if (oDeleteResult.result === false)
{
throw new Error(`Unable to delete the account. Reason: ${oDeleteResult.message}`);
if (oDeleteResult.result === false) {
throw new Error(`Unable to delete the account. Reason: ${oDeleteResult.message}`);
}
}
else {
throw new Error(`Unable to delete the account. Reason: ${oDeleteResult.message}`);
}
}

return true;
Expand Down
19 changes: 7 additions & 12 deletions src/node/jsonRpc/Methods/Account/EncryptAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import MnemonicWords from 'mnemonic.js';
/**
* Encrypt an account from the wallet
*/
class DeleteAccount extends RpcMethod
{
class EncryptAccount extends RpcMethod {
constructor(name, oWallet) {
super(name);
this._oWallet = oWallet;
Expand All @@ -15,29 +14,25 @@ class DeleteAccount extends RpcMethod
let sAddress = args[0] || null;
let oAddress = this._oWallet.getAddress(sAddress);

if (oAddress === null)
{
if (oAddress === null) {
throw new Error('Account not found.');
}

if (await this._oWallet.isAddressEncrypted(oAddress))
{
if (await this._oWallet.isAddressEncrypted(oAddress)) {
throw new Error('Account is already encrypted.');
}

const sPassword = (new MnemonicWords(4 * 32)).toWords(4 * 32).join(' ');
const bEncryptedSuccessfully = await this._oWallet.encryptAddress(oAddress, sPassword);
const bEncryptedSuccessfully = await this._oWallet.encryptAddress(oAddress, sPassword.split(' '));

// Only check against "true" because the way encryptAddress() method returns the results
if (bEncryptedSuccessfully === true)
{
if (bEncryptedSuccessfully === true) {
return sPassword;
}
else
{
else {
throw new Error('Unable to encrypt account.');
}
}
}

export default authenticatedMethod(DeleteAccount);
export default authenticatedMethod(EncryptAccount);
9 changes: 3 additions & 6 deletions src/node/jsonRpc/Methods/Account/ExportAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {authenticatedMethod, RpcMethod} from './../../../../jsonRpc';
/**
* Export an existing account from the wallet
*/
class ExportAccount extends RpcMethod
{
class ExportAccount extends RpcMethod {
constructor(name, oWallet) {
super(name);
this._oWallet = oWallet;
Expand All @@ -14,15 +13,13 @@ class ExportAccount extends RpcMethod
let sAddress = args[0] || null;
let oAddress = this._oWallet.getAddress(sAddress);

if (oAddress === null)
{
if (oAddress === null) {
throw new Error('Account not found.');
}

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

if (aExportResult.result === false)
{
if (aExportResult.result === false) {
throw new Error(`Unable to export the account. Reason: ${aExportResult.message}`);
}

Expand Down
9 changes: 3 additions & 6 deletions src/node/jsonRpc/Methods/Account/ImportAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {isObject} from 'lodash';
/**
* Import an account into the wallet
*/
class ImportAccount extends RpcMethod
{
class ImportAccount extends RpcMethod {
constructor(name, oWallet) {
super(name);
this._oWallet = oWallet;
Expand All @@ -14,15 +13,13 @@ class ImportAccount extends RpcMethod
async getHandler(args) {
let oData = args[0] || null;

if (isObject(oData) === false)
{
if (isObject(oData) === false) {
throw new Error('First parameter must be an Object');
}

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

if (aImportResult.result === false)
{
if (aImportResult.result === false) {
throw new Error(`Unable to import the account. Reason: ${aImportResult.message}`);
}

Expand Down
20 changes: 7 additions & 13 deletions src/node/jsonRpc/Methods/Account/NewAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import MnemonicWords from 'mnemonic.js';
/**
* Create a new account into the wallet
*/
class NewAccount extends RpcMethod
{
class NewAccount extends RpcMethod {
constructor(name, oWallet) {
super(name);
this._oWallet = oWallet;
Expand All @@ -15,35 +14,30 @@ class NewAccount extends RpcMethod
const bEncrypt = args[0] || false;
let oAddress;

try
{
try {
oAddress = await this._oWallet.createNewAddress();
}
catch (e)
{
catch (e) {
throw new Error(`Unable to create a new account. Reason: ${e.message}`);
}

let aResult = {
address: oAddress.address
};

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

// Only check against "true" because the way encryptAddress() method returns the results
if (bEncryptedSuccessfully === true)
{
if (bEncryptedSuccessfully === true) {
return aResult;
}

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

if (aDeleteResult.result === false)
{
if (aDeleteResult.result === false) {
throw new Error(`Unable to encrypt account. Reason: ${aDeleteResult.message}`);
}

Expand Down
Loading

0 comments on commit 94151f6

Please sign in to comment.