Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 22c7cfb

Browse files
committedMay 3, 2018
test_getLogHash
1 parent b387b57 commit 22c7cfb

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed
 

‎libweb3jsonrpc/Test.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,52 @@
2323
#include "Test.h"
2424
#include <jsonrpccpp/common/errors.h>
2525
#include <jsonrpccpp/common/exception.h>
26-
#include <libethereum/ClientTest.h>
26+
#include <libdevcore/CommonJS.h>
2727
#include <libethereum/ChainParams.h>
28+
#include <libethereum/ClientTest.h>
2829

2930
using namespace std;
3031
using namespace dev;
32+
using namespace dev::eth;
3133
using namespace dev::rpc;
3234
using namespace jsonrpc;
3335

3436
Test::Test(eth::Client& _eth): m_eth(_eth) {}
3537

38+
namespace
39+
{
40+
string logEntriesToLogHash(eth::LogEntries const& _logs)
41+
{
42+
RLPStream s;
43+
s.appendList(_logs.size());
44+
for (eth::LogEntry const& l : _logs)
45+
l.streamRLP(s);
46+
return toHexPrefixed(sha3(s.out()));
47+
}
48+
}
49+
50+
string Test::test_getLogHash(string const& _txHash)
51+
{
52+
h256 txHash;
53+
try
54+
{
55+
txHash = h256(_txHash);
56+
}
57+
catch (...)
58+
{
59+
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
60+
}
61+
62+
if (m_eth.blockChain().isKnownTransaction(txHash))
63+
{
64+
LocalisedTransaction t = m_eth.localisedTransaction(txHash);
65+
BlockReceipts const& blockReceipts = m_eth.blockChain().receipts(t.blockHash());
66+
if (blockReceipts.receipts.size() != 0)
67+
return logEntriesToLogHash(blockReceipts.receipts[t.transactionIndex()].log());
68+
}
69+
return toJS(dev::EmptyListSHA3);
70+
}
71+
3672
bool Test::test_setChainParams(Json::Value const& param1)
3773
{
3874
try

‎libweb3jsonrpc/Test.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class Test: public TestFace
4242
{
4343
return RPCModules{RPCModule{"test", "1.0"}};
4444
}
45-
46-
virtual bool test_setChainParams(const Json::Value &param1) override;
47-
virtual bool test_mineBlocks(int _number) override;
45+
virtual std::string test_getLogHash(std::string const& _param1) override;
46+
virtual bool test_setChainParams(const Json::Value& _param1) override;
47+
virtual bool test_mineBlocks(int _number) override;
4848
virtual bool test_modifyTimestamp(int _timestamp) override;
4949
virtual bool test_addBlock(std::string const& _rlp) override;
5050
virtual bool test_rewindToBlock(int _number) override;

‎libweb3jsonrpc/TestFace.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ namespace dev {
1414
public:
1515
TestFace()
1616
{
17+
this->bindAndAddMethod(
18+
jsonrpc::Procedure("test_getLogHash", jsonrpc::PARAMS_BY_POSITION,
19+
jsonrpc::JSON_BOOLEAN, "param1", jsonrpc::JSON_STRING, NULL),
20+
&dev::rpc::TestFace::test_getLogHashI);
1721
this->bindAndAddMethod(jsonrpc::Procedure("test_setChainParams", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &dev::rpc::TestFace::test_setChainParamsI);
1822
this->bindAndAddMethod(jsonrpc::Procedure("test_mineBlocks", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_mineBlocksI);
1923
this->bindAndAddMethod(jsonrpc::Procedure("test_modifyTimestamp", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_modifyTimestampI);
2024
this->bindAndAddMethod(jsonrpc::Procedure("test_addBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_addBlockI);
2125
this->bindAndAddMethod(jsonrpc::Procedure("test_rewindToBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_rewindToBlockI);
2226
}
23-
27+
inline virtual void test_getLogHashI(
28+
const Json::Value& request, Json::Value& response)
29+
{
30+
response = this->test_getLogHash(request[0u].asString());
31+
}
2432
inline virtual void test_setChainParamsI(const Json::Value &request, Json::Value &response)
2533
{
2634
response = this->test_setChainParams(request[0u]);
@@ -41,6 +49,7 @@ namespace dev {
4149
{
4250
response = this->test_rewindToBlock(request[0u].asInt());
4351
}
52+
virtual std::string test_getLogHash(const std::string& param1) = 0;
4453
virtual bool test_setChainParams(const Json::Value& param1) = 0;
4554
virtual bool test_mineBlocks(int param1) = 0;
4655
virtual bool test_modifyTimestamp(int param1) = 0;

‎libweb3jsonrpc/test.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
{ "name": "test_getLogHash", "params": [""], "order": [], "returns": ""},
23
{ "name": "test_setChainParams", "params": [{}], "order": [], "returns": false},
34
{ "name": "test_mineBlocks", "params": [0], "returns": false },
45
{ "name": "test_modifyTimestamp", "params": [0], "returns": false },

0 commit comments

Comments
 (0)
This repository has been archived.