Browse Source

Avoid the need for JSONRPC with devcore.

cl-refactor
Gav Wood 9 years ago
parent
commit
690760fc24
  1. 4
      libdevcore/CMakeLists.txt
  2. 60
      libdevcore/StructuredLogger.cpp

4
libdevcore/CMakeLists.txt

@ -20,7 +20,9 @@ target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${Boost_RANDOM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_RANDOM_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES}) if (JSONRPC)
target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES})
endif()
target_link_libraries(${EXECUTABLE} ${DB_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${DB_LIBRARIES})
# transitive dependencies for windows executables # transitive dependencies for windows executables

60
libdevcore/StructuredLogger.cpp

@ -23,8 +23,9 @@
#include "StructuredLogger.h" #include "StructuredLogger.h"
#include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/tcp.hpp>
#if ETH_JSONRPC
#include <json/json.h> #include <json/json.h>
#endif
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include "Guards.h" #include "Guards.h"
@ -45,16 +46,22 @@ void StructuredLogger::initialize(bool _enabled, std::string const& _timeFormat,
void StructuredLogger::outputJson(Json::Value const& _value, std::string const& _name) const void StructuredLogger::outputJson(Json::Value const& _value, std::string const& _name) const
{ {
#if ETH_JSONRPC
Json::Value event; Json::Value event;
static Mutex s_lock; static Mutex s_lock;
Json::FastWriter fastWriter; Json::FastWriter fastWriter;
Guard l(s_lock); Guard l(s_lock);
event[_name] = _value; event[_name] = _value;
(m_out.is_open() ? m_out : cout) << fastWriter.write(event) << endl; (m_out.is_open() ? m_out : cout) << fastWriter.write(event) << endl;
#else
(void)_value;
(void)_name;
#endif
} }
void StructuredLogger::starting(string const& _clientImpl, const char* _ethVersion) void StructuredLogger::starting(string const& _clientImpl, const char* _ethVersion)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
Json::Value event; Json::Value event;
@ -65,10 +72,15 @@ void StructuredLogger::starting(string const& _clientImpl, const char* _ethVersi
get().outputJson(event, "starting"); get().outputJson(event, "starting");
} }
#else
(void)_clientImpl;
(void)_ethVersion;
#endif
} }
void StructuredLogger::stopping(string const& _clientImpl, const char* _ethVersion) void StructuredLogger::stopping(string const& _clientImpl, const char* _ethVersion)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
Json::Value event; Json::Value event;
@ -79,6 +91,10 @@ void StructuredLogger::stopping(string const& _clientImpl, const char* _ethVersi
get().outputJson(event, "stopping"); get().outputJson(event, "stopping");
} }
#else
(void)_clientImpl;
(void)_ethVersion;
#endif
} }
void StructuredLogger::p2pConnected( void StructuredLogger::p2pConnected(
@ -88,6 +104,7 @@ void StructuredLogger::p2pConnected(
string const& _remoteVersion, string const& _remoteVersion,
unsigned int _numConnections) unsigned int _numConnections)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
std::stringstream addrStream; std::stringstream addrStream;
@ -101,10 +118,18 @@ void StructuredLogger::p2pConnected(
get().outputJson(event, "p2p.connected"); get().outputJson(event, "p2p.connected");
} }
#else
(void)_id;
(void)_addr;
(void)_ts;
(void)_remoteVersion;
(void)_numConnections;
#endif
} }
void StructuredLogger::p2pDisconnected(string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) void StructuredLogger::p2pDisconnected(string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
std::stringstream addrStream; std::stringstream addrStream;
@ -117,6 +142,11 @@ void StructuredLogger::p2pDisconnected(string const& _id, bi::tcp::endpoint cons
get().outputJson(event, "p2p.disconnected"); get().outputJson(event, "p2p.disconnected");
} }
#else
(void)_id;
(void)_addr;
(void)_numConnections;
#endif
} }
void StructuredLogger::minedNewBlock( void StructuredLogger::minedNewBlock(
@ -125,6 +155,7 @@ void StructuredLogger::minedNewBlock(
string const& _chainHeadHash, string const& _chainHeadHash,
string const& _prevHash) string const& _prevHash)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
Json::Value event; Json::Value event;
@ -136,6 +167,12 @@ void StructuredLogger::minedNewBlock(
get().outputJson(event, "eth.miner.new_block"); get().outputJson(event, "eth.miner.new_block");
} }
#else
(void)_hash;
(void)_blockNumber;
(void)_chainHeadHash;
(void)_prevHash;
#endif
} }
void StructuredLogger::chainReceivedNewBlock( void StructuredLogger::chainReceivedNewBlock(
@ -145,6 +182,7 @@ void StructuredLogger::chainReceivedNewBlock(
string const& _remoteID, string const& _remoteID,
string const& _prevHash) string const& _prevHash)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
Json::Value event; Json::Value event;
@ -157,6 +195,13 @@ void StructuredLogger::chainReceivedNewBlock(
get().outputJson(event, "eth.chain.received.new_block"); get().outputJson(event, "eth.chain.received.new_block");
} }
#else
(void)_hash;
(void)_blockNumber;
(void)_chainHeadHash;
(void)_remoteID;
(void)_prevHash;
#endif
} }
void StructuredLogger::chainNewHead( void StructuredLogger::chainNewHead(
@ -165,6 +210,7 @@ void StructuredLogger::chainNewHead(
string const& _chainHeadHash, string const& _chainHeadHash,
string const& _prevHash) string const& _prevHash)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
Json::Value event; Json::Value event;
@ -176,10 +222,17 @@ void StructuredLogger::chainNewHead(
get().outputJson(event, "eth.miner.new_block"); get().outputJson(event, "eth.miner.new_block");
} }
#else
(void)_hash;
(void)_blockNumber;
(void)_chainHeadHash;
(void)_prevHash;
#endif
} }
void StructuredLogger::transactionReceived(string const& _hash, string const& _remoteId) void StructuredLogger::transactionReceived(string const& _hash, string const& _remoteId)
{ {
#if ETH_JSONRPC
if (get().m_enabled) if (get().m_enabled)
{ {
Json::Value event; Json::Value event;
@ -189,7 +242,10 @@ void StructuredLogger::transactionReceived(string const& _hash, string const& _r
get().outputJson(event, "eth.tx.received"); get().outputJson(event, "eth.tx.received");
} }
#else
(void)_hash;
(void)_remoteId;
#endif
} }
} }

Loading…
Cancel
Save