Browse Source

ethconsole improvements.

Store session key in user's homedir for ease of use of ethconsole.
cl-refactor
Gav Wood 10 years ago
parent
commit
c8bbf5a0b0
  1. 16
      eth/main.cpp
  2. 1
      ethconsole/CMakeLists.txt
  3. 26
      ethconsole/main.cpp
  4. 6
      libjsconsole/JSConsole.h

16
eth/main.cpp

@ -1085,7 +1085,7 @@ int main(int argc, char** argv)
NodeMode nodeMode = NodeMode::Full;
bool interactive = false;
#if ETH_JSONRPC || !ETH_TRUE
int jsonrpc = -1;
int jsonRPCURL = -1;
#endif
string jsonAdmin;
string genesisJSON;
@ -1434,9 +1434,9 @@ int main(int argc, char** argv)
interactive = true;
#if ETH_JSONRPC || !ETH_TRUE
else if ((arg == "-j" || arg == "--json-rpc"))
jsonrpc = jsonrpc == -1 ? SensibleHttpPort : jsonrpc;
jsonRPCURL = jsonRPCURL == -1 ? SensibleHttpPort : jsonRPCURL;
else if (arg == "--json-rpc-port" && i + 1 < argc)
jsonrpc = atoi(argv[++i]);
jsonRPCURL = atoi(argv[++i]);
else if (arg == "--json-admin" && i + 1 < argc)
jsonAdmin = argv[++i];
#endif
@ -1743,15 +1743,15 @@ int main(int argc, char** argv)
else
cout << "Networking disabled. To start, use netstart or pass -b or a remote host." << endl;
if (useConsole && jsonrpc == -1)
jsonrpc = SensibleHttpPort;
if (useConsole && jsonRPCURL == -1)
jsonRPCURL = SensibleHttpPort;
#if ETH_JSONRPC || !ETH_TRUE
shared_ptr<dev::WebThreeStubServer> jsonrpcServer;
unique_ptr<jsonrpc::AbstractServerConnector> jsonrpcConnector;
if (jsonrpc > -1)
if (jsonRPCURL > -1)
{
jsonrpcConnector = unique_ptr<jsonrpc::AbstractServerConnector>(new jsonrpc::HttpServer(jsonrpc, "", "", SensibleHttpThreads));
jsonrpcConnector = unique_ptr<jsonrpc::AbstractServerConnector>(new jsonrpc::HttpServer(jsonRPCURL, "", "", SensibleHttpThreads));
jsonrpcServer = make_shared<dev::WebThreeStubServer>(*jsonrpcConnector.get(), web3, make_shared<SimpleAccountHolder>([&](){ return web3.ethereum(); }, getAccountPassword, keyManager), vector<KeyPair>(), keyManager, *gasPricer);
jsonrpcServer->setMiningBenefactorChanger([&](Address const& a) { beneficiary = a; });
jsonrpcServer->StartListening();
@ -1760,6 +1760,8 @@ int main(int argc, char** argv)
else
jsonrpcServer->addSession(jsonAdmin, SessionPermissions{{Priviledge::Admin}});
cout << "JSONRPC Admin Session Key: " << jsonAdmin << endl;
writeFile(getDataDir("web3") + "/session.key", jsonAdmin);
writeFile(getDataDir("web3") + "/session.url", "http://localhost:" + toString(jsonRPCURL));
}
#endif

1
ethconsole/CMakeLists.txt

@ -20,6 +20,7 @@ if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW)
eth_copy_dlls(${EXECUTABLE} CURL_DLLS)
endif()
target_link_libraries(${EXECUTABLE} jsconsole)
target_link_libraries(${EXECUTABLE} devcore)
if (APPLE)
install(TARGETS ${EXECUTABLE} DESTINATION bin)

26
ethconsole/main.cpp

@ -20,6 +20,7 @@
*/
#include <string>
#include <libdevcore/FileSystem.h>
#include <libjsconsole/JSRemoteConsole.h>
using namespace std;
using namespace dev;
@ -27,13 +28,30 @@ using namespace dev::eth;
int main(int argc, char** argv)
{
string remote;
if (argc == 1)
string remote = contentsString(getDataDir("web3") + "/session.rpc");
if (remote.empty())
remote = "http://localhost:8545";
else if (argc == 2)
remote = argv[1];
string sessionKey = contentsString(getDataDir("web3") + "/session.url");
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if (arg == "--url" && i + 1 < argc)
remote = argv[++i];
else if (arg == "--session-key" && i + 1 < argc)
sessionKey = argv[++i];
else
{
cerr << "Invalid argument: " << arg << endl;
exit(-1);
}
}
JSRemoteConsole console(remote);
if (!sessionKey.empty())
console.eval("web3.admin.setSessionKey('" + sessionKey + "')");
while (true)
console.readExpression();

6
libjsconsole/JSConsole.h

@ -46,9 +46,9 @@ public:
std::string cmd = "";
g_logPost = [](std::string const& a, char const*)
{
std::cout << "\r \r" << a << std::endl << std::flush;
std::cout << "\r \r" << a << std::endl << std::flush;
#if ETH_READLINE
rl_forced_update_display();
rl_forced_update_display();
#endif
};
@ -92,6 +92,8 @@ public:
}
}
void eval(std::string const& _expression) { m_engine.eval(_expression.c_str()); }
protected:
Engine m_engine;
Printer m_printer;

Loading…
Cancel
Save