Browse Source

Merge branch 'filter_logs' of https://github.com/ethereum/cpp-ethereum into logs

Conflicts:
	libweb3jsonrpc/abstractwebthreestubserver.h
	libweb3jsonrpc/spec.json
	test/webthreestubclient.h
cl-refactor
Marek Kotewicz 10 years ago
parent
commit
1b1c48b67b
  1. 3
      alethzero/MainWin.cpp
  2. 4
      libethereum/BlockChain.h
  3. 12
      libethereum/Client.cpp
  4. 6
      libjsqrc/ethereum.js
  5. 2
      libweb3jsonrpc/WebThreeStubServer.cpp
  6. 2
      libweb3jsonrpc/WebThreeStubServer.h
  7. 19
      libweb3jsonrpc/abstractwebthreestubserver.h
  8. 3
      libweb3jsonrpc/spec.json
  9. 35
      test/webthreestubclient.h
  10. 17
      third/MainWin.cpp
  11. 4
      third/MainWin.h

3
alethzero/MainWin.cpp

@ -1292,7 +1292,7 @@ void Main::on_blocks_currentItemChanged()
Transaction tx(block[1][txi].data());
auto ss = tx.safeSender();
h256 th = sha3(rlpList(ss, tx.nonce()));
auto receipt = ethereum()->blockChain().receipts(h).receipts[txi];
TransactionReceipt receipt = ethereum()->blockChain().receipts(h).receipts[txi];
s << "<h3>" << th << "</h3>";
s << "<h4>" << h << "[<b>" << txi << "</b>]</h4>";
s << "<br/>From: <b>" << pretty(ss).toHtmlEscaped().toStdString() << "</b> " << ss;
@ -1308,6 +1308,7 @@ void Main::on_blocks_currentItemChanged()
s << "<br/>R: <b>" << hex << nouppercase << tx.signature().r << "</b>";
s << "<br/>S: <b>" << hex << nouppercase << tx.signature().s << "</b>";
s << "<br/>Msg: <b>" << tx.sha3(eth::WithoutSignature) << "</b>";
s << "<div>Log Bloom: " << receipt.bloom() << "</div>";
s << "<div>Hex: <span style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">" << toHex(block[1][txi].data()) << "</span></div>";
auto r = receipt.rlp();
s << "<div>Receipt: " << toString(RLP(r)) << "</div>";

4
libethereum/BlockChain.h

@ -93,6 +93,10 @@ public:
/// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 _hash) const;
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
BlockInfo info(h256 _hash) const { return BlockInfo(block(_hash)); }
BlockInfo info() const { return BlockInfo(block()); }
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
BlockDetails details(h256 _hash) const { return queryExtras<BlockDetails, 0>(_hash, m_details, x_details, NullBlockDetails); }
BlockDetails details() const { return details(currentHash()); }

12
libethereum/Client.cpp

@ -232,12 +232,12 @@ void Client::appendFromNewPending(LogBloom _bloom, h256Set& o_changed) const
void Client::appendFromNewBlock(h256 _block, h256Set& o_changed) const
{
// auto d = m_bc.info(_block);
//
// lock_guard<mutex> l(m_filterLock);
// for (pair<h256, InstalledFilter> const& i: m_filters)
// if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom))
// o_changed.insert(i.first);
auto d = m_bc.info(_block);
lock_guard<mutex> l(m_filterLock);
for (pair<h256, InstalledFilter> const& i: m_filters)
if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom))
o_changed.insert(i.first);
}
void Client::setForceMining(bool _enable)

6
libjsqrc/ethereum.js

@ -599,7 +599,7 @@ var ethWatchMethods = function () {
return [
{ name: 'newFilter', call: newFilter },
{ name: 'uninstallFilter', call: 'eth_uninstallFilter' },
{ name: 'getMessages', call: 'eth_getMessages' }
{ name: 'logs', call: 'eth_getMessages' }
];
};
@ -904,6 +904,8 @@ Filter.prototype.messages = function() {
});
};
Filter.prototype.logs = Filter.prototype.messages;
function messageHandler(data) {
if(data._event !== undefined) {
web3.trigger(data._event, data._id, data.data);
@ -1060,4 +1062,4 @@ module.exports = web3;
},{"./lib/autoprovider":2,"./lib/contract":3,"./lib/httprpc":4,"./lib/main":5,"./lib/qt":6,"./lib/websocket":7}]},{},[])
//# sourceMappingURL=ethereum.js.map
//# sourceMappingURL=ethereum.js.map

2
libweb3jsonrpc/WebThreeStubServer.cpp

@ -394,7 +394,7 @@ std::string WebThreeStubServer::db_get(std::string const& _name, std::string con
return toJS(dev::asBytes(ret));
}
Json::Value WebThreeStubServer::eth_getMessages(int const& _id)
Json::Value WebThreeStubServer::eth_getLogs(int const& _id)
{
if (!client())
return Json::Value();

2
libweb3jsonrpc/WebThreeStubServer.h

@ -76,7 +76,7 @@ public:
virtual double eth_countAt(std::string const& _address);
virtual int eth_defaultBlock();
virtual std::string eth_gasPrice();
virtual Json::Value eth_getMessages(int const& _id);
virtual Json::Value eth_getLogs(int const& _id);
virtual bool eth_listening();
virtual bool eth_mining();
virtual int eth_newFilter(Json::Value const& _json);

19
libweb3jsonrpc/abstractwebthreestubserver.h

@ -28,11 +28,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("eth_compilers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_compilersI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_filterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_filterLogsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_getLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_getLogsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_lll", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_lllI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_logs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_logsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_newFilterString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newFilterStringI);
@ -138,14 +137,14 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_defaultBlock();
}
inline virtual void eth_filterLogsI(const Json::Value& request, Json::Value& response)
inline virtual void eth_gasPriceI(const Json::Value& request, Json::Value& response)
{
response = this->eth_filterLogs(request[0u].asInt());
response = this->eth_gasPrice();
}
inline virtual void eth_gasPriceI(const Json::Value& request, Json::Value& response)
inline virtual void eth_getLogsI(const Json::Value& request, Json::Value& response)
{
response = this->eth_gasPrice();
response = this->eth_getLogs(request[0u].asInt());
}
inline virtual void eth_listeningI(const Json::Value& request, Json::Value& response)
@ -158,11 +157,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_lll(request[0u].asString());
}
inline virtual void eth_logsI(const Json::Value& request, Json::Value& response)
{
response = this->eth_logs(request[0u]);
}
inline virtual void eth_miningI(const Json::Value& request, Json::Value& response)
{
response = this->eth_mining();
@ -314,11 +308,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value eth_compilers() = 0;
virtual double eth_countAt(const std::string& param1) = 0;
virtual int eth_defaultBlock() = 0;
virtual Json::Value eth_filterLogs(const int& param1) = 0;
virtual std::string eth_gasPrice() = 0;
virtual Json::Value eth_getLogs(const int& param1) = 0;
virtual bool eth_listening() = 0;
virtual std::string eth_lll(const std::string& param1) = 0;
virtual Json::Value eth_logs(const Json::Value& param1) = 0;
virtual bool eth_mining() = 0;
virtual int eth_newFilter(const Json::Value& param1) = 0;
virtual int eth_newFilterString(const std::string& param1) = 0;

3
libweb3jsonrpc/spec.json

@ -37,8 +37,7 @@
{ "method": "eth_newFilterString", "params": [""], "order": [], "returns": 0},
{ "method": "eth_uninstallFilter", "params": [0], "order": [], "returns": true},
{ "method": "eth_changed", "params": [0], "order": [], "returns": false},
{ "method": "eth_filterLogs", "params": [0], "order": [], "returns": []},
{ "method": "eth_logs", "params": [{}], "order": [], "returns": []},
{ "method": "eth_getLogs", "params": [0], "order": [], "returns": []},
{ "method": "db_put", "params": ["", "", ""], "order": [], "returns": true},
{ "method": "db_get", "params": ["", ""], "order": [], "returns": ""},

35
test/webthreestubclient.h

@ -216,26 +216,26 @@ p.append(param3);
}
Json::Value eth_filterLogs(const int& param1) throw (jsonrpc::JsonRpcException)
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_filterLogs",p);
if (result.isArray())
return result;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
Json::Value eth_getLogs(const int& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
if (result.isString())
return result.asString();
p.append(param1);
Json::Value result = this->client->CallMethod("eth_getLogs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -266,19 +266,6 @@ p.append(param3);
}
Json::Value eth_logs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_logs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool eth_mining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;

17
third/MainWin.cpp

@ -182,7 +182,7 @@ void Main::onKeysChanged()
installBalancesWatch();
}
unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f)
unsigned Main::installWatch(dev::eth::LogFilter const& _tf, std::function<void()> const& _f)
{
auto ret = ethereum()->installWatch(_tf);
m_handlers[ret] = _f;
@ -198,37 +198,34 @@ unsigned Main::installWatch(dev::h256 _tf, std::function<void()> const& _f)
void Main::installWatches()
{
installWatch(dev::eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); });
installWatch(dev::eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); });
installWatch(dev::eth::LogFilter().topic((u256)(u160)c_config).topic((u256)0), [=](){ installNameRegWatch(); });
installWatch(dev::eth::LogFilter().topic((u256)(u160)c_config).topic((u256)1), [=](){ installCurrenciesWatch(); });
installWatch(dev::eth::ChainChangedFilter, [=](){ onNewBlock(); });
}
void Main::installNameRegWatch()
{
ethereum()->uninstallWatch(m_nameRegFilter);
m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
m_nameRegFilter = installWatch(dev::eth::LogFilter().topic(ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
}
void Main::installCurrenciesWatch()
{
ethereum()->uninstallWatch(m_currenciesFilter);
m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
m_currenciesFilter = installWatch(dev::eth::LogFilter().topic(ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
}
void Main::installBalancesWatch()
{
dev::eth::MessageFilter tf;
dev::eth::LogFilter tf;
vector<Address> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys)
{
tf.altered(i.address());
for (auto c: altCoins)
tf.altered(c, (u160)i.address());
}
tf.address(c).topic((u256)(u160)i.address());
ethereum()->uninstallWatch(m_balancesFilter);
m_balancesFilter = installWatch(tf, [=](){ onBalancesChange(); });

4
third/MainWin.h

@ -40,7 +40,7 @@ namespace dev { class WebThreeDirect;
namespace eth {
class Client;
class State;
class MessageFilter;
class LogFilter;
}
namespace shh {
class WhisperHost;
@ -95,7 +95,7 @@ private:
void readSettings(bool _skipGeometry = false);
void writeSettings();
unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::eth::LogFilter const& _tf, std::function<void()> const& _f);
unsigned installWatch(dev::h256 _tf, std::function<void()> const& _f);
void onNewBlock();

Loading…
Cancel
Save