From d6f79609de60967309e0c94d2c797414c1172c15 Mon Sep 17 00:00:00 2001 From: Vincent Gariepy Date: Tue, 10 Jun 2014 17:13:23 -0400 Subject: [PATCH] neth: use ClientGuard --- neth/main.cpp | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/neth/main.cpp b/neth/main.cpp index dce147812..7804c4c63 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -451,7 +451,6 @@ int main(int argc, char** argv) logwin = newwin(height * 2 / 5 - 2, width * 2 / 3, qheight, 0); nc::nc_window_streambuf outbuf(logwin, std::cout); - g_logVerbosity = 1; // Force verbosity level for now consolewin = newwin(qheight, width / 4, 0, 0); nc::nc_window_streambuf coutbuf(consolewin, ccout); @@ -479,9 +478,8 @@ int main(int argc, char** argv) c.startNetwork(listenPort, remoteHost, remotePort, mode, peers, publicIP, upnp); if (mining) { - c.lock(); + ClientGuard g(&c); c.startMining(); - c.unlock(); } #if ETH_JSONRPC @@ -516,12 +514,6 @@ int main(int argc, char** argv) ccout << "Address:" << endl; ccout << toHex(us.address().asArray()) << endl << endl; - c.lock(); - auto const& st = c.state(); - auto const& bc = c.blockChain(); - ccout << "Genesis hash: " << bc.genesisHash() << endl; - c.unlock(); - mvwprintw(mainwin, 1, 1, " > "); clrtoeol(); @@ -535,36 +527,31 @@ int main(int argc, char** argv) { eth::uint port; iss >> port; - c.lock(); + ClientGuard g(&c); c.startNetwork((short)port); - c.unlock(); } else if (cmd == "connect") { string addr; eth::uint port; iss >> addr >> port; - c.lock(); + ClientGuard g(&c); c.connect(addr, (short)port); - c.unlock(); } else if (cmd == "netstop") { - c.lock(); + ClientGuard g(&c); c.stopNetwork(); - c.unlock(); } else if (cmd == "minestart") { - c.lock(); + ClientGuard g(&c); c.startMining(); - c.unlock(); } else if (cmd == "minestop") { - c.lock(); + ClientGuard g(&c); c.stopMining(); - c.unlock(); } #if ETH_JSONRPC else if (cmd == "jsonport") @@ -619,7 +606,7 @@ int main(int argc, char** argv) } else if (cmd == "transact") { - c.lock(); + ClientGuard g(&c); auto const& bc = c.blockChain(); auto h = bc.currentHash(); auto blockData = bc.block(h); @@ -696,11 +683,10 @@ int main(int argc, char** argv) c.transact(secret, amount, dest, data, gas, gasPrice); } } - c.unlock(); } else if (cmd == "send") { - c.lock(); + ClientGuard g(&c); vector s; s.push_back("Address"); vector l; @@ -739,11 +725,10 @@ int main(int argc, char** argv) c.transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice); } } - c.unlock(); } else if (cmd == "contract") { - c.lock(); + ClientGuard g(&c); auto const& bc = c.blockChain(); auto h = bc.currentHash(); auto blockData = bc.block(h); @@ -797,7 +782,7 @@ int main(int argc, char** argv) cnote << "Init:"; cnote << ssc.str(); } - c.lock(); + ClientGuard g(&c); u256 minGas = (u256)c.state().createGas(init.size(), 0); if (endowment < 0) cwarn << "Invalid endowment"; @@ -810,7 +795,6 @@ int main(int argc, char** argv) c.transact(us.secret(), endowment, init, gas, gasPrice); } } - c.unlock(); } else if (cmd == "inspect") { @@ -821,7 +805,7 @@ int main(int argc, char** argv) cwarn << "Invalid address length"; else { - c.lock(); + ClientGuard g(&c); auto h = h160(fromHex(rechex)); stringstream s; auto mem = c.state().storage(h); @@ -835,8 +819,6 @@ int main(int argc, char** argv) ofs.open(outFile, ofstream::binary); ofs.write(s.str().c_str(), s.str().length()); ofs.close(); - - c.unlock(); } } else if (cmd == "help") @@ -849,7 +831,11 @@ int main(int argc, char** argv) // Lock to prevent corrupt block-chain errors - c.lock(); + ClientGuard g(&c); + + auto const& st = c.state(); + auto const& bc = c.blockChain(); + ccout << "Genesis hash: " << bc.genesisHash() << endl; // Blocks y = 1; @@ -970,9 +956,6 @@ int main(int argc, char** argv) else mvwprintw(consolewin, qheight - 1, width / 4 - 12, "Mining OFF"); - // Unlock - c.unlock(); - wmove(consolewin, 1, x); // Addresses