-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrun-poa-node.js
37 lines (33 loc) · 1.02 KB
/
run-poa-node.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
function unlockAccounts() {
eth.accounts.forEach(function (account) {
console.log('Unlocking ' + account + '...');
personal.unlockAccount(account, '', 86400);
});
}
function pendingTransactions() {
if (web3.eth.pendingTransactions === undefined || web3.eth.pendingTransactions === null) {
return txpool.status.pending || txpool.status.queued;
}
else if (typeof web3.eth.pendingTransactions === "function") {
return web3.eth.pendingTransactions().length > 0;
}
else {
return web3.eth.pendingTransactions.length > 0 || web3.eth.getBlock('pending').transactions.length > 0;
}
}
function setupDevNode() {
web3.eth.filter("pending").watch(function () {
if (miner.hashrate > 0)
return;
console.log("== Pending transactions! Looking for next block...");
miner.start(8);
});
web3.eth.filter("latest").watch(function () {
if (!pendingTransactions()) {
console.log("== No transactions left. Stopping miner...");
miner.stop();
}
});
}
unlockAccounts();
setupDevNode();