Browse Source

common changes

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
1b21fa4d6c
  1. 27
      libethrpc/EthStubServer.cpp
  2. 9
      test/jsonrpc.cpp

27
libethrpc/EthStubServer.cpp

@ -79,6 +79,20 @@ static Json::Value toJson(const dev::eth::PastMessages& pms)
return res; return res;
} }
static Json::Value toJson(const dev::eth::Transaction& t)
{
Json::Value res;
res["hash"] = toJS(t.sha3());
res["input"] = jsFromBinary(t.data);
res["to"] = toJS(t.receiveAddress);
res["from"] = toJS(t.sender());
res["gas"] = (int)t.gas;
res["gasPrice"] = toJS(t.gasPrice);
res["nonce"] = toJS(t.nonce);
res["value"] = toJS(t.value);
return res;
}
EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3): EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3):
AbstractEthStubServer(_conn), AbstractEthStubServer(_conn),
m_web3(_web3) m_web3(_web3)
@ -380,18 +394,7 @@ Json::Value EthStubServer::transaction(const int &i, const string &numberOrHash)
} }
auto n = jsToU256(numberOrHash); auto n = jsToU256(numberOrHash);
auto h = n < client()->number() ? client()->hashFromNumber((unsigned)n) : jsToFixed<32>(numberOrHash); auto h = n < client()->number() ? client()->hashFromNumber((unsigned)n) : jsToFixed<32>(numberOrHash);
dev::eth::Transaction t = client()->transaction(h, i); return toJson(client()->transaction(h, i));
Json::Value res;
res["hash"] = boost::lexical_cast<string>(t.sha3());
res["input"] = jsFromBinary(t.data);
res["to"] = boost::lexical_cast<string>(t.receiveAddress);
res["from"] = boost::lexical_cast<string>(t.sender());
res["gas"] = (int)t.gas;
res["gasPrice"] = boost::lexical_cast<string>(t.gasPrice);
res["nonce"] = boost::lexical_cast<string>(t.nonce);
res["value"] = boost::lexical_cast<string>(t.value);
return res;
} }
Json::Value EthStubServer::uncle(const int &i, const string &numberOrHash) Json::Value EthStubServer::uncle(const int &i, const string &numberOrHash)

9
test/jsonrpc.cpp

@ -1,6 +1,6 @@
//#if ETH_JSONRPC && 1 #if ETH_JSONRPC && 1
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
@ -286,8 +286,13 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
dev::eth::mine(*(web3.ethereum()), 1); dev::eth::mine(*(web3.ethereum()), 1);
auto balance2 = web3.ethereum()->balanceAt(receiver.address()); auto balance2 = web3.ethereum()->balanceAt(receiver.address());
auto number = web3.ethereum()->number();
BOOST_REQUIRE(balance2 > 0); BOOST_REQUIRE(balance2 > 0);
BOOST_CHECK_EQUAL(txAmount, balance2); BOOST_CHECK_EQUAL(txAmount, balance2);
// auto ax = jsToFixed(number);
// Json::Value p = jsonrpcClient->transaction(0, jsToFixed(number));
// TODO, check transactions
} }
BOOST_AUTO_TEST_CASE(jsonrpc_transaction) BOOST_AUTO_TEST_CASE(jsonrpc_transaction)
@ -310,7 +315,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_watch)
} }
//#endif #endif

Loading…
Cancel
Save