Browse Source

Merge pull request #204 from caktux/clientguard

neth: use ClientGuard
cl-refactor
Gav Wood 11 years ago
parent
commit
c1feb9d717
  1. 49
      neth/main.cpp

49
neth/main.cpp

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

Loading…
Cancel
Save