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

Commit 9c54389

Browse files
committed
string test_getLogHash(txHash)
1 parent b387b57 commit 9c54389

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

libweb3jsonrpc/Test.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,37 @@
2525
#include <jsonrpccpp/common/exception.h>
2626
#include <libethereum/ClientTest.h>
2727
#include <libethereum/ChainParams.h>
28+
#include <libdevcore/CommonJS.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+
string exportLog(eth::LogEntries const& _logs)
39+
{
40+
RLPStream s;
41+
s.appendList(_logs.size());
42+
for (eth::LogEntry const& l : _logs)
43+
l.streamRLP(s);
44+
return toHexPrefixed(sha3(s.out()));
45+
}
46+
47+
string Test::test_getLogHash(string const& _txHash)
48+
{
49+
if (m_eth.blockChain().isKnownTransaction(h256(_txHash)))
50+
{
51+
LocalisedTransaction t = m_eth.localisedTransaction(h256(_txHash));
52+
BlockReceipts const& blockReceipts = m_eth.blockChain().receipts(t.blockHash());
53+
if (blockReceipts.receipts.size() != 0)
54+
return exportLog(blockReceipts.receipts[t.transactionIndex()].log());
55+
}
56+
return toJS(dev::EmptyListSHA3);
57+
}
58+
3659
bool Test::test_setChainParams(Json::Value const& param1)
3760
{
3861
try

libweb3jsonrpc/Test.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Test: public TestFace
4242
{
4343
return RPCModules{RPCModule{"test", "1.0"}};
4444
}
45-
45+
virtual std::string test_getLogHash(std::string const& param1) override;
4646
virtual bool test_setChainParams(const Json::Value &param1) override;
4747
virtual bool test_mineBlocks(int _number) override;
4848
virtual bool test_modifyTimestamp(int _timestamp) override;

libweb3jsonrpc/TestFace.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ namespace dev {
1414
public:
1515
TestFace()
1616
{
17+
this->bindAndAddMethod(jsonrpc::Procedure("test_getLogHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_getLogHashI);
1718
this->bindAndAddMethod(jsonrpc::Procedure("test_setChainParams", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &dev::rpc::TestFace::test_setChainParamsI);
1819
this->bindAndAddMethod(jsonrpc::Procedure("test_mineBlocks", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_mineBlocksI);
1920
this->bindAndAddMethod(jsonrpc::Procedure("test_modifyTimestamp", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_modifyTimestampI);
2021
this->bindAndAddMethod(jsonrpc::Procedure("test_addBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_addBlockI);
2122
this->bindAndAddMethod(jsonrpc::Procedure("test_rewindToBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_rewindToBlockI);
2223
}
23-
24+
inline virtual void test_getLogHashI(const Json::Value& request, Json::Value& response)
25+
{
26+
response = this->test_getLogHash(request[0u].asString());
27+
}
2428
inline virtual void test_setChainParamsI(const Json::Value &request, Json::Value &response)
2529
{
2630
response = this->test_setChainParams(request[0u]);
@@ -41,6 +45,7 @@ namespace dev {
4145
{
4246
response = this->test_rewindToBlock(request[0u].asInt());
4347
}
48+
virtual std::string test_getLogHash(const std::string& param1) = 0;
4449
virtual bool test_setChainParams(const Json::Value& param1) = 0;
4550
virtual bool test_mineBlocks(int param1) = 0;
4651
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)