Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

testclient: setChainParams #177

Merged
merged 2 commits into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions eth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,25 +1222,29 @@ int main(int argc, char** argv)

AddressHash allowedDestinations;

auto authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool {
// "unlockAccount" functionality is done in the AccountHolder.
if (!alwaysConfirm || allowedDestinations.count(_t.to))
return true;
std::function<bool(TransactionSkeleton const&, bool)> authenticator;
if (testingMode)
authenticator = [](TransactionSkeleton const&, bool) -> bool { return true; };
else
authenticator = [&](TransactionSkeleton const& _t, bool isProxy) -> bool {
// "unlockAccount" functionality is done in the AccountHolder.
if (!alwaysConfirm || allowedDestinations.count(_t.to))
return true;

string r = getResponse(_t.userReadable(isProxy,
[&](TransactionSkeleton const& _t) -> pair<bool, string>
{
h256 contractCodeHash = web3.ethereum()->postState().codeHash(_t.to);
if (contractCodeHash == EmptySHA3)
return std::make_pair(false, std::string());
// TODO: actually figure out the natspec. we'll need the natspec database here though.
return std::make_pair(true, std::string());
}, [&](Address const& _a) { return ICAP(_a).encoded() + " (" + _a.abridged() + ")"; }
) + "\nEnter yes/no/always (always to this address): ", {"yes", "n", "N", "no", "NO", "always"});
if (r == "always")
allowedDestinations.insert(_t.to);
return r == "yes" || r == "always";
};
string r = getResponse(_t.userReadable(isProxy,
[&](TransactionSkeleton const& _t) -> pair<bool, string>
{
h256 contractCodeHash = web3.ethereum()->postState().codeHash(_t.to);
if (contractCodeHash == EmptySHA3)
return std::make_pair(false, std::string());
// TODO: actually figure out the natspec. we'll need the natspec database here though.
return std::make_pair(true, std::string());
}, [&](Address const& _a) { return ICAP(_a).encoded() + " (" + _a.abridged() + ")"; }
) + "\nEnter yes/no/always (always to this address): ", {"yes", "n", "N", "no", "NO", "always"});
if (r == "always")
allowedDestinations.insert(_t.to);
return r == "yes" || r == "always";
};

ExitHandler exitHandler;

Expand Down
17 changes: 17 additions & 0 deletions libweb3jsonrpc/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <jsonrpccpp/common/errors.h>
#include <jsonrpccpp/common/exception.h>
#include <libethereum/ClientTest.h>
#include <libethereum/ChainParams.h>

using namespace std;
using namespace dev;
Expand All @@ -32,6 +33,22 @@ using namespace jsonrpc;

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

bool Test::test_setChainParams(Json::Value const& param1)
{
try
{
Json::FastWriter fastWriter;
std::string output = fastWriter.write(param1);
asClientTest(m_eth).setChainParams(output);
}
catch (std::exception const&)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR));
}

return true;
}

bool Test::test_mineBlocks(int _number)
{
try
Expand Down
1 change: 1 addition & 0 deletions libweb3jsonrpc/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Test: public TestFace
return RPCModules{RPCModule{"test", "1.0"}};
}

virtual bool test_setChainParams(const Json::Value &param1) override;
virtual bool test_mineBlocks(int _number) override;
virtual bool test_modifyTimestamp(int _timestamp) override;
virtual bool test_addBlock(std::string const& _rlp) override;
Expand Down
6 changes: 6 additions & 0 deletions libweb3jsonrpc/TestFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ namespace dev {
public:
TestFace()
{
this->bindAndAddMethod(jsonrpc::Procedure("test_setChainParams", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &dev::rpc::TestFace::test_setChainParamsI);
this->bindAndAddMethod(jsonrpc::Procedure("test_mineBlocks", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_mineBlocksI);
this->bindAndAddMethod(jsonrpc::Procedure("test_modifyTimestamp", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_modifyTimestampI);
this->bindAndAddMethod(jsonrpc::Procedure("test_addBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &dev::rpc::TestFace::test_addBlockI);
this->bindAndAddMethod(jsonrpc::Procedure("test_rewindToBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &dev::rpc::TestFace::test_rewindToBlockI);
}

inline virtual void test_setChainParamsI(const Json::Value &request, Json::Value &response)
{
response = this->test_setChainParams(request[0u]);
}
inline virtual void test_mineBlocksI(const Json::Value &request, Json::Value &response)
{
response = this->test_mineBlocks(request[0u].asInt());
Expand All @@ -36,6 +41,7 @@ namespace dev {
{
response = this->test_rewindToBlock(request[0u].asInt());
}
virtual bool test_setChainParams(const Json::Value& param1) = 0;
virtual bool test_mineBlocks(int param1) = 0;
virtual bool test_modifyTimestamp(int param1) = 0;
virtual bool test_addBlock(const std::string& param1) = 0;
Expand Down
1 change: 1 addition & 0 deletions libweb3jsonrpc/test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
{ "name": "test_setChainParams", "params": [{}], "order": [], "returns": false},
{ "name": "test_mineBlocks", "params": [0], "returns": false },
{ "name": "test_modifyTimestamp", "params": [0], "returns": false },
{ "name": "test_addBlock", "params": [""], "returns": false },
Expand Down