-
Notifications
You must be signed in to change notification settings - Fork 2.2k
string test_getLogHash(txHash) #4986
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,16 +23,60 @@ | |
#include "Test.h" | ||
#include <jsonrpccpp/common/errors.h> | ||
#include <jsonrpccpp/common/exception.h> | ||
#include <libethereum/ClientTest.h> | ||
#include <libdevcore/CommonJS.h> | ||
#include <libethereum/ChainParams.h> | ||
#include <libethereum/ClientTest.h> | ||
|
||
using namespace std; | ||
using namespace dev; | ||
using namespace dev::eth; | ||
using namespace dev::rpc; | ||
using namespace jsonrpc; | ||
|
||
Test::Test(eth::Client& _eth): m_eth(_eth) {} | ||
|
||
namespace | ||
{ | ||
string logEntriesToLogHash(eth::LogEntries const& _logs) | ||
{ | ||
RLPStream s; | ||
s.appendList(_logs.size()); | ||
for (eth::LogEntry const& l : _logs) | ||
l.streamRLP(s); | ||
return toJS(sha3(s.out())); | ||
} | ||
} | ||
|
||
string Test::test_getLogHash(string const& _txHash) | ||
{ | ||
try | ||
{ | ||
h256 txHash; | ||
try | ||
{ | ||
txHash = h256(_txHash); | ||
} | ||
catch (BadHexCharacter const&) | ||
{ | ||
throw JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was no any sense really in using |
||
} | ||
|
||
if (m_eth.blockChain().isKnownTransaction(txHash)) | ||
{ | ||
LocalisedTransaction t = m_eth.localisedTransaction(txHash); | ||
BlockReceipts const& blockReceipts = m_eth.blockChain().receipts(t.blockHash()); | ||
if (blockReceipts.receipts.size() != 0) | ||
return logEntriesToLogHash(blockReceipts.receipts[t.transactionIndex()].log()); | ||
} | ||
return toJS(dev::EmptyListSHA3); | ||
} | ||
catch (std::exception const& ex) | ||
{ | ||
cwarn << ex.what(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When something goes wrong we don't want to just silently return "internal error", we'd like to have a way to understand what happened, so let's output the error to the log. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _ex ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could still use boost exception for nicer error output like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
throw JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR); | ||
} | ||
} | ||
|
||
bool Test::test_setChainParams(Json::Value const& param1) | ||
{ | ||
try | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not mask all possible errors, but only catch the errors of parsing the hexstring. If at some point (maybe in the future) it start to throw other exceptions, we won't fail with confusing "invalid params" error.