diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index ca2fbd239..8f159b29d 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -867,32 +867,9 @@ void Block::commitToSeal( RLPStream unclesData; unsigned unclesCount = 0; - if ( m_previousBlock.number() != 0 ) { - // Find great-uncles (or second-cousins or whatever they are) - children of - // great-grandparents, great-great-grandparents... that were not already uncles in previous - // generations. - LOG( m_loggerDetailed ) << cc::debug( "Checking " ) << m_previousBlock.hash() - << cc::debug( ", parent = " ) << m_previousBlock.parentHash(); - h256Hash excluded = _bc.allKinFrom( m_currentBlock.parentHash(), 6 ); - auto p = m_previousBlock.parentHash(); - for ( unsigned gen = 0; gen < 6 && p != _bc.genesisHash() && unclesCount < 2; - ++gen, p = _bc.details( p ).parent ) { - auto us = _bc.details( p ).children; - assert( us.size() >= 1 ); // must be at least 1 child of our grandparent - it's our own - // parent! - for ( auto const& u : us ) - if ( !excluded.count( u ) ) // ignore any uncles/mainline blocks that we know - // about. - { - uncleBlockHeaders.push_back( _bc.info( u ) ); - unclesData.appendRaw( _bc.headerData( u ) ); - ++unclesCount; - if ( unclesCount == 2 ) - break; - excluded.insert( u ); - } - } - } + + // here was code to handle 6 generations of uncles + // it was wtiting its results in two variables above BytesMap transactionsMap; BytesMap receiptsMap; diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 6a90597ed..3f71957a5 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -173,9 +173,9 @@ Json::Value toJson( dev::eth::LocalisedTransactionReceipt const& _t ) { res["to"] = toJS( _t.to() ); res["transactionHash"] = toJS( _t.hash() ); - res["transactionIndex"] = _t.transactionIndex(); + res["transactionIndex"] = toJS( _t.transactionIndex() ); res["blockHash"] = toJS( _t.blockHash() ); - res["blockNumber"] = _t.blockNumber(); + res["blockNumber"] = toJS( _t.blockNumber() ); res["cumulativeGasUsed"] = toJS( _t.cumulativeGasUsed() ); res["gasUsed"] = toJS( _t.gasUsed() ); // @@ -259,11 +259,11 @@ Json::Value toJson( dev::eth::LocalisedLogEntry const& _e ) { res["polarity"] = _e.polarity == BlockPolarity::Live ? true : false; if ( _e.mined ) { res["type"] = "mined"; - res["blockNumber"] = _e.blockNumber; + res["blockNumber"] = toJS( _e.blockNumber ); res["blockHash"] = toJS( _e.blockHash ); - res["logIndex"] = _e.logIndex; + res["logIndex"] = toJS( _e.logIndex ); res["transactionHash"] = toJS( _e.transactionHash ); - res["transactionIndex"] = _e.transactionIndex; + res["transactionIndex"] = toJS( _e.transactionIndex ); } else { res["type"] = "pending"; res["blockNumber"] = Json::Value( Json::nullValue ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index 7edea74e7..c3f3b3b0e 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -279,7 +279,7 @@ Json::Value WebThreeStubClient::eth_getBlockTransactionCountByHash( const std::s Json::Value p; p.append( param1 ); Json::Value result = this->CallMethod( "eth_getBlockTransactionCountByHash", p ); - if ( result.isObject() ) + if ( result.isString() ) return result; else throw jsonrpc::JsonRpcException( @@ -290,7 +290,7 @@ Json::Value WebThreeStubClient::eth_getBlockTransactionCountByNumber( const std: Json::Value p; p.append( param1 ); Json::Value result = this->CallMethod( "eth_getBlockTransactionCountByNumber", p ); - if ( result.isObject() ) + if ( result.isString() ) return result; else throw jsonrpc::JsonRpcException( @@ -301,7 +301,7 @@ Json::Value WebThreeStubClient::eth_getUncleCountByBlockHash( const std::string& Json::Value p; p.append( param1 ); Json::Value result = this->CallMethod( "eth_getUncleCountByBlockHash", p ); - if ( result.isObject() ) + if ( result.isString() ) return result; else throw jsonrpc::JsonRpcException( @@ -312,7 +312,7 @@ Json::Value WebThreeStubClient::eth_getUncleCountByBlockNumber( const std::strin Json::Value p; p.append( param1 ); Json::Value result = this->CallMethod( "eth_getUncleCountByBlockNumber", p ); - if ( result.isObject() ) + if ( result.isString() ) return result; else throw jsonrpc::JsonRpcException( diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index d8733898d..3704156d4 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -687,6 +687,18 @@ contract Logger{ Json::Value deployReceipt = fixture.rpcClient->eth_getTransactionReceipt( deployHash ); string contractAddress = deployReceipt["contractAddress"].asString(); + Json::Value filterObj; + filterObj["address"] = contractAddress; + filterObj["fromBlock"] = "0x1"; + string filterId = fixture.rpcClient->eth_newFilter( filterObj ); + + Json::Value res = fixture.rpcClient->eth_getFilterLogs(filterId); + BOOST_REQUIRE(res.isArray()); + BOOST_REQUIRE_EQUAL(res.size(), 0); + res = fixture.rpcClient->eth_getFilterChanges(filterId); + BOOST_REQUIRE(res.isArray()); + BOOST_REQUIRE_EQUAL(res.size(), 0); + // need blockNumber==256 afterwards for(int i=0; i<255; ++i){ Json::Value t; @@ -717,6 +729,100 @@ contract Logger{ BOOST_REQUIRE_EQUAL(block, i+2); }// for + string nonexisting = "0x20"; string nonexisting_hash = logs[0x20-1]["blockHash"].asString(); + + // add 256 more blocks + string lastHash; + for(int i=0; i<256; ++i){ + Json::Value t; + t["from"] = toJS( fixture.coinbase.address() ); + t["value"] = jsToDecimal( "0" ); + t["to"] = contractAddress; + t["gas"] = "99000"; + + lastHash = fixture.rpcClient->eth_sendTransaction( t ); + BOOST_REQUIRE( !lastHash.empty() ); + + dev::eth::mineTransaction( *( fixture.client ), 1 ); + } + BOOST_REQUIRE_EQUAL(fixture.client->number(), 512); + + // ask for logs + t["toBlock"] = 512; + logs = fixture.rpcClient->eth_getLogs(t); + BOOST_REQUIRE(logs.isArray()); + BOOST_REQUIRE_EQUAL(logs.size(), 256+64); + + // and filter + res = fixture.rpcClient->eth_getFilterChanges(filterId); + BOOST_REQUIRE_EQUAL(res.size(), (256+255)*2); // HACK!! in prod there should be *1! (no pending!) + res = fixture.rpcClient->eth_getFilterLogs(filterId); + BOOST_REQUIRE_EQUAL(res.size(), 256+64); + + ///////////////// OTHER CALLS ////////////////// + string existing = "0x1ff"; string existing_hash = logs[256+64-1-1]["blockHash"].asString(); + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockByNumber(existing, true)); + BOOST_REQUIRE_EQUAL(res["number"], existing); + BOOST_REQUIRE(res["transactions"].isArray() && res["transactions"].size() == 1); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockByNumber(nonexisting, true), jsonrpc::JsonRpcException); + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockByHash(existing_hash, false)); + BOOST_REQUIRE_EQUAL(res["number"], existing); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockByHash(nonexisting_hash, true), jsonrpc::JsonRpcException); + + // + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockTransactionCountByNumber(existing)); + BOOST_REQUIRE_EQUAL(res.asString(), "0x1"); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockTransactionCountByNumber(nonexisting), jsonrpc::JsonRpcException); + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockTransactionCountByHash(existing_hash)); + BOOST_REQUIRE_EQUAL(res.asString(), "0x1"); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockTransactionCountByHash(nonexisting_hash), jsonrpc::JsonRpcException); + + // + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getUncleCountByBlockNumber(existing)); + BOOST_REQUIRE_EQUAL(res.asString(), "0x0"); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleCountByBlockNumber(nonexisting), jsonrpc::JsonRpcException); + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getUncleCountByBlockHash(existing_hash)); + BOOST_REQUIRE_EQUAL(res.asString(), "0x0"); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleCountByBlockHash(nonexisting_hash), jsonrpc::JsonRpcException); + + // + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(existing, "0x0")); + BOOST_REQUIRE_EQUAL(res["blockNumber"], existing); + BOOST_REQUIRE_EQUAL(res["blockHash"], existing_hash); + BOOST_REQUIRE_EQUAL(res["to"], contractAddress); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(nonexisting, "0x0"), jsonrpc::JsonRpcException); + + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(existing_hash, "0x0")); + BOOST_REQUIRE_EQUAL(res["blockNumber"], existing); + BOOST_REQUIRE_EQUAL(res["blockHash"], existing_hash); + BOOST_REQUIRE_EQUAL(res["to"], contractAddress); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(nonexisting_hash, "0x0"), jsonrpc::JsonRpcException); + + // + + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockNumberAndIndex(existing, "0x0"), jsonrpc::JsonRpcException); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockNumberAndIndex(nonexisting, "0x0"), jsonrpc::JsonRpcException); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockHashAndIndex(existing_hash, "0x0"), jsonrpc::JsonRpcException); + BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockHashAndIndex(nonexisting_hash, "0x0"), jsonrpc::JsonRpcException); + + // + + BOOST_REQUIRE_THROW(res = fixture.rpcClient->eth_getTransactionByHash(deployHash), jsonrpc::JsonRpcException); + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByHash(lastHash)); + BOOST_REQUIRE_EQUAL(res["blockNumber"], "0x200"); + + BOOST_REQUIRE_THROW(res = fixture.rpcClient->eth_getTransactionReceipt(deployHash), jsonrpc::JsonRpcException); + BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionReceipt(lastHash)); + BOOST_REQUIRE_EQUAL(res["transactionHash"], lastHash); + BOOST_REQUIRE_EQUAL(res["blockNumber"], "0x200"); + BOOST_REQUIRE_EQUAL(res["to"], contractAddress); } BOOST_AUTO_TEST_CASE( deploy_contract_from_owner ) {