Skip to content

Commit c1809e3

Browse files
committed
Merge branch 'fund_accounts' of github.com:embark-framework/embark into fund_accounts
2 parents 20406ba + 9382f98 commit c1809e3

File tree

9 files changed

+13
-103
lines changed

9 files changed

+13
-103
lines changed

lib/cmds/blockchain/blockchain.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,8 @@ Blockchain.prototype.run = function() {
184184
};
185185

186186
Blockchain.prototype.createFundAndUnlockAccounts = function(cb) {
187-
console.dir('createFundAndUnlockAccounts');
188187
let devFunds = new DevFunds(this.config);
189188
devFunds.createFundAndUnlockAccounts((err) => {
190-
console.dir("=====> done!");
191-
console.dir(arguments);
192189
cb(err);
193190
});
194191
};

lib/cmds/blockchain/dev_funds.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class DevFunds {
1414
this.networkId = null;
1515
this.balance = Web3.utils.toWei("1", "ether");
1616
if (this.blockchainConfig.account.balance) {
17-
console.dir('[blockchain/dev_funds]: converting balance from ' + this.blockchainConfig.account.balance);
1817
this.balance = getWeiBalanceFromString(this.blockchainConfig.account.balance, this.web3);
19-
console.dir('[blockchain/dev_funds]: converted balance to ' + this.balance);
2018
}
2119
}
2220

@@ -36,7 +34,7 @@ class DevFunds {
3634
return;
3735
}
3836

39-
setInterval(function() { self._sendTx(); }, 3000);
37+
setInterval(function() { self._sendTx(); }, 1500);
4038
if (cb) {
4139
cb();
4240
}
@@ -57,7 +55,6 @@ class DevFunds {
5755
if (accounts.length > 1) {
5856
this.accounts = accounts.slice(1);
5957
}
60-
console.dir('----- CURRENT ACCOUNTS ' + this.accounts);
6158
cb();
6259
});
6360
}
@@ -66,89 +63,54 @@ class DevFunds {
6663
const numAccountsToCreate = numAccounts - (this.accounts.length + 1);
6764
if (numAccountsToCreate === 0) return cb();
6865

69-
console.dir("creating " + numAccountsToCreate + " new accounts with password " + password);
7066
async.timesLimit(numAccountsToCreate, 1, (_, next) => {
71-
console.dir("--- creating new account");
7267
this.web3.eth.personal.newAccount(password, next);
7368
}, (err, accounts) => {
74-
if (err) console.error(err);
75-
console.dir("-- accounts created are ");
76-
console.dir(accounts);
69+
if (err) return cb(err);
7770
this.accounts = accounts;
78-
cb(err);
71+
cb();
7972
});
8073
}
8174

8275
unlockAccounts(password, cb) {
83-
console.dir('--- CURRENT ACCOUNTS ' + this.accounts);
8476
async.each(this.accounts, (account, next) => {
85-
console.dir('-- unlocking account ' + account + ' with password ' + password);
8677
this.web3.eth.personal.unlockAccount(account, password).then((result) => {
87-
console.dir('-- unlocked account ' + account + ' with password ' + password + ' and result ' + result);
8878
next();
8979
}).catch(next);
90-
}, (err) => {
91-
console.dir('-- FINISHED UNLOCKING ACCOUNTS, err= ' + err);
92-
cb(err);
93-
});
80+
}, cb);
9481
}
9582

9683
fundAccounts(balance, cb) {
97-
console.dir('-- funding accounts...');
9884

9985
async.each(this.accounts, (account, next) => {
10086
this.web3.eth.getBalance(account).then(currBalance => {
10187
const remainingBalance = balance - currBalance;
102-
console.dir("---- account " + account + " balance needed = " + remainingBalance);
10388
if (remainingBalance <= 0) return next();
10489

105-
console.dir("-- funding account " + account + " with balance " + remainingBalance);
10690
this.web3.eth.sendTransaction({to: account, value: remainingBalance}).then((result) => {
107-
console.dir('FUNDING ACCT result: ' + JSON.stringify(result));
10891
next();
10992
}).catch(next);
110-
}, (err) => {
111-
console.dir('-- FINISHED FUNDING ACCOUNTS, err= ' + err);
112-
cb(err);
113-
});
93+
}, cb);
11494
});
11595
}
11696

11797
createFundAndUnlockAccounts(cb) {
11898
async.waterfall([
11999
(next) => {
120-
console.dir('--- CONNECTING TO NODE');
121100
this.connectToNode(next);
122101
},
123102
(next) => {
124-
console.dir('--- CREATING THE ACCOUNTS');
125103
this.createAccounts(this.numAccounts, this.password, next);
126104
},
127105
(next) => {
128-
console.dir('--- UNLOCKING THE ACCOUNTS');
129106
this.unlockAccounts(this.password, next);
130107
},
131108
(next) => {
132-
console.dir('--- FUNDING THE ACCOUNTS');
133109
this.regularTxs();
134110
this.regularUnlocks();
135111
this.fundAccounts(this.balance, next);
136112
}
137-
], (err) => {
138-
console.dir(`--- COMPLETED THE ACCOUNTS (${this.accounts.join(', ')} and funded with ${this.balance} wei)`);
139-
if (err) console.error('Error creating, unlocking, and funding accounts', JSON.stringify(err));
140-
141-
// this.web3.eth.getAccounts().then((accounts) => {
142-
// let numAccts = accounts.length;
143-
// accounts.forEach((account) => {
144-
// this.web3.eth.getBalance(account).then((balance) => {
145-
// console.dir('[contracts/dev_funds]: account ' + account + ' has balance of ' + balance);
146-
// if(--numAccts === 0) cb(err);
147-
// });
148-
// });
149-
// });
150-
cb(err);
151-
});
113+
], cb);
152114
}
153115
}
154116

lib/contracts/accountParser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class AccountParser {
3030
if (accountConfig.balance) {
3131
hexBalance = getHexBalanceFromString(accountConfig.balance, web3);
3232
//hexBalance = getHexBalanceFromString(accountConfig.balance, web3);
33-
console.dir('[contracts/accountParser]: balance ' + accountConfig.balance + ' converted to hex ' + hexBalance);
3433
}
3534
if (accountConfig.privateKey) {
3635
if (!accountConfig.privateKey.startsWith('0x')) {

lib/contracts/blockchain.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class Blockchain {
5151
const protocol = (this.contractsConfig.deployment.type === "rpc") ? this.contractsConfig.deployment.protocol : 'ws';
5252
let provider;
5353
this.web3Endpoint = utils.buildUrl(protocol, this.contractsConfig.deployment.host, this.contractsConfig.deployment.port);//`${protocol}://${this.contractsConfig.deployment.host}:${this.contractsConfig.deployment.port}`;
54-
console.dir('[blockchain/contracts]: web3 endpoint: ' + this.web3Endpoint);
5554
const providerOptions = {
5655
web3: this.web3,
5756
accountsConfig: this.contractsConfig.deployment.accounts,
@@ -65,7 +64,6 @@ class Blockchain {
6564

6665
async.waterfall([
6766
function checkNode(next) {
68-
console.dir('[blockchain/contracts]: check node');
6967
self.assertNodeConnection(true, (err) => {
7068
if (err && self.web3StartedInProcess) {
7169
// Already started blockchain in another node, we really have a node problem
@@ -79,19 +77,16 @@ class Blockchain {
7977
}
8078
self.web3StartedInProcess = true;
8179
self.startBlockchainNode(() => {
82-
console.dir('[blockchain/contracts]: starting blockchain node');
8380
// Need to re-initialize web3 to connect to the new blockchain node
8481
provider.stop();
8582
self.initWeb3(cb);
8683
});
8784
});
8885
},
8986
function startProvider(next) {
90-
console.dir('[blockchain/contracts]: starting web3 provider');
9187
provider.startWeb3Provider(next);
9288
},
9389
function fundAccountsIfNeeded(next) {
94-
console.dir('[blockchain/contracts]: funding accounts');
9590
self.isWeb3Ready = true;
9691
provider.fundAccounts(next);
9792
}
@@ -184,11 +179,7 @@ class Blockchain {
184179
});
185180

186181
this.events.setCommandHandler("blockchain:gasPrice", function(cb) {
187-
console.dir('[blockchain/contracts]: getting gas price...');
188-
self.getGasPrice((gp) => {
189-
console.dir('[blockchain/contracts]: got gasPrice of ' + gp);
190-
cb(gp);
191-
});
182+
self.getGasPrice(cb);
192183
});
193184

194185
}
@@ -287,16 +278,7 @@ class Blockchain {
287278
}
288279
let accountConfig = self.blockchainConfig.account;
289280
let selectedAccount = accountConfig && accountConfig.address;
290-
console.dir('[contracts/blockchain]: setting default account of ' + (selectedAccount || accounts[0]));
291281
self.setDefaultAccount(selectedAccount || accounts[0]);
292-
console.dir('[contracts/blockchain]: accounts on node = ');
293-
//let numAccts = accounts.length;
294-
self.web3.eth.getAccounts().then((accounts) => {
295-
accounts.forEach((account) => {
296-
self.web3.eth.getBalance(account).then((balance) => console.dir('[contracts/blockchain]: account ' + account + ' has balance of ' + balance));
297-
//if(--numAccts === 0) cb();
298-
});
299-
});
300282
cb();
301283
});
302284
}

lib/contracts/contract_deployer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class ContractDeployer {
201201
},
202202
function getGasPriceForNetwork(next) {
203203
self.events.request("blockchain:gasPrice", (gasPrice) => {
204-
console.dir('[contracts/contracts]: got gasPrice of ' + gasPrice);
205204
contract.gasPrice = contract.gasPrice || gasPrice;
206205
next();
207206
});

lib/contracts/contracts.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,18 @@ class ContractsManager {
5454
self.contracts = {};
5555
async.waterfall([
5656
function loadContractFiles(callback) {
57-
console.dir('[contracts/contracts]: load contract files');
5857
self.events.request("config:contractsFiles", (contractsFiles) => {
5958
self.contractsFiles = contractsFiles;
6059
callback();
6160
});
6261
},
6362
function loadContractConfigs(callback) {
64-
console.dir('[contracts/contracts]: load contract configs');
6563
self.events.request("config:contractsConfig", (contractsConfig) => {
6664
self.contractsConfig = cloneDeep(contractsConfig);
6765
callback();
6866
});
6967
},
7068
function compileContracts(callback) {
71-
console.dir('[contracts/contracts]: compile contracts');
7269
self.events.emit("status", __("Compiling..."));
7370
if (process.env.isTest && self.compiledContracts && Object.keys(self.compiledContracts).length) {
7471
// Only compile once for tests
@@ -80,7 +77,6 @@ class ContractsManager {
8077
});
8178
},
8279
function prepareContractsFromConfig(callback) {
83-
console.dir('[contracts/contracts]: prepare contracts from config');
8480
self.events.emit("status", __("Building..."));
8581
let className, contract;
8682
for (className in self.contractsConfig.contracts) {
@@ -94,11 +90,9 @@ class ContractsManager {
9490
callback();
9591
},
9692
function getGasPriceForNetwork(callback) {
97-
console.dir('[contracts/contracts]: gas price for network, passed in gasPrice from config: ' + self.contractsConfig.gasPrice);
9893
return callback(null, self.contractsConfig.gasPrice);
9994
},
10095
function prepareContractsFromCompilation(gasPrice, callback) {
101-
console.dir('[contracts/contracts]: using gasprice ' + gasPrice + ', prepare contracts from compilation');
10296
let className, compiledContract, contractConfig, contract;
10397
for (className in self.compiledContracts) {
10498
compiledContract = self.compiledContracts[className];
@@ -126,7 +120,6 @@ class ContractsManager {
126120
callback();
127121
},
128122
function setDeployIntention(callback) {
129-
console.dir('[contracts/contracts]: set deploy intention');
130123
let className, contract;
131124
for (className in self.contracts) {
132125
contract = self.contracts[className];
@@ -144,7 +137,6 @@ class ContractsManager {
144137
},
145138
/*eslint complexity: ["error", 11]*/
146139
function dealWithSpecialConfigs(callback) {
147-
console.dir('[contracts/contracts]: deal with special configs');
148140
let className, contract, parentContractName, parentContract;
149141
let dictionary = Object.keys(self.contracts);
150142

@@ -194,7 +186,6 @@ class ContractsManager {
194186
callback();
195187
},
196188
function removeContractsWithNoCode(callback) {
197-
console.dir('[contracts/contracts]: remove Contracts with no code');
198189
let className, contract;
199190
let dictionary = Object.keys(self.contracts);
200191
for (className in self.contracts) {
@@ -216,7 +207,6 @@ class ContractsManager {
216207
/*eslint complexity: ["error", 16]*/
217208
/*eslint max-depth: ["error", 16]*/
218209
function determineDependencies(callback) {
219-
console.dir('[contracts/contracts]: determining dependencies');
220210
let className, contract;
221211
for (className in self.contracts) {
222212
contract = self.contracts[className];

lib/contracts/deploy_manager.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class DeployManager {
6767
async.waterfall([
6868
function buildContracts(callback) {
6969
self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => {
70-
console.dir('[contracts/deploy_manager]: done building contracts');
7170
callback(err);
7271
});
7372
},
@@ -83,28 +82,20 @@ class DeployManager {
8382

8483
// TODO: could be implemented as an event (beforeDeployAll)
8584
function checkIsConnectedToBlockchain(callback) {
86-
console.dir('[contracts/deploy_manager]: checking connection to blockchain');
8785
self.blockchain.onReady(() => {
88-
console.dir('[contracts/deploy_manager]: onReady called, asserting node connection');
89-
self.blockchain.assertNodeConnection((err) => {
90-
console.dir('[contracts/deploy_manager]: node connection asserted, err: ' + JSON.stringify(err));
91-
callback(err);
92-
});
86+
self.blockchain.assertNodeConnection(callback);
9387
});
9488
},
9589

9690
// TODO: this can be done on the fly or as part of the initialization
9791
function determineDefaultAccount(callback) {
98-
console.dir('[contracts/deploy_manager]: determining default acct');
9992
self.blockchain.determineDefaultAccount((err) => {
10093
callback(err);
10194
});
10295
},
10396

10497
function deployAllContracts(callback) {
105-
console.dir('[contracts/deploy_manager]: deploying all contracts');
10698
self.deployAll(function (err) {
107-
console.dir('[contracts/deploy_manager]: done deploying all contracts, err: ' + JSON.stringify(err));
10899
if (!err) {
109100
self.events.emit('contractsDeployed');
110101
}
@@ -115,7 +106,6 @@ class DeployManager {
115106
});
116107
},
117108
function runAfterDeploy(callback) {
118-
console.dir('[contracts/deploy_manager]: emitting and running actions for event "contracts:deploy:afterAll"');
119109
self.plugins.emitAndRunActionsForEvent('contracts:deploy:afterAll', callback);
120110
}
121111
], function (err, _result) {

lib/contracts/fundAccount.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ const async = require('async');
22
const TARGET = 0x7FFFFFFFFFFFFFFF;
33
const ALREADY_FUNDED = 'alreadyFunded';
44

5-
function fundAccount(web3, accountAddress, hexBalance, nonce, callback) {
5+
function fundAccount(web3, accountAddress, hexBalance, callback) {
66
if (!hexBalance) {
77
hexBalance = TARGET;
88
}
99
const targetBalance = (typeof hexBalance === 'string') ? parseInt(hexBalance, 16) : hexBalance;
1010
let accountBalance;
1111
let coinbaseAddress;
12+
let lastNonce;
1213
let gasPrice;
1314

1415
async.waterfall([
@@ -51,23 +52,17 @@ function fundAccount(web3, accountAddress, hexBalance, nonce, callback) {
5152
if (err) {
5253
return next(err);
5354
}
55+
lastNonce = nonce;
5456
next();
5557
});
5658
},
5759
function sendTransaction(next) {
58-
console.dir('[contracts/fundAccount]: sending tx ' + JSON.stringify({
59-
from: coinbaseAddress,
60-
to: accountAddress,
61-
value: targetBalance - accountBalance,
62-
gasPrice: gasPrice,
63-
nonce: nonce
64-
}));
6560
web3.eth.sendTransaction({
6661
from: coinbaseAddress,
6762
to: accountAddress,
6863
value: targetBalance - accountBalance,
6964
gasPrice: gasPrice,
70-
nonce: nonce
65+
nonce: lastNonce
7166
}, next);
7267
}
7368
], (err) => {

lib/contracts/provider.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ class Provider {
7878
if (!self.isDev) {
7979
return callback();
8080
}
81-
let nonce = 0;
8281
async.each(self.accounts, (account, eachCb) => {
83-
console.dir('[contracts/provider]: nonce is ' + nonce);
84-
fundAccount(self.web3, account.address, account.hexBalance, nonce++, (err) => {
85-
eachCb(err);
86-
});
82+
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
8783
}, callback);
8884
}
8985

0 commit comments

Comments
 (0)