Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/consensus-836-more-catchup-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev authored Jun 11, 2024
2 parents a89f6d0 + a09a4d2 commit e321dfb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
9 changes: 4 additions & 5 deletions libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ Json::Value Eth::eth_createAccessList(
return result;
}

Json::Value Eth::eth_feeHistory( const std::string& _blockCount, const std::string& _newestBlock,
Json::Value Eth::eth_feeHistory( dev::u256 _blockCount, const std::string& _newestBlock,
const Json::Value& _rewardPercentiles ) {
try {
if ( !_rewardPercentiles.isArray() )
Expand All @@ -974,8 +974,7 @@ Json::Value Eth::eth_feeHistory( const std::string& _blockCount, const std::stri
}
}

auto blockCount = jsToU256( _blockCount );
if ( blockCount > MAX_BLOCK_RANGE )
if ( _blockCount > MAX_BLOCK_RANGE )
throw std::runtime_error( "Max block range reached. Please try smaller blockCount." );

auto newestBlock = jsToBlockNumber( _newestBlock );
Expand All @@ -984,10 +983,10 @@ Json::Value Eth::eth_feeHistory( const std::string& _blockCount, const std::stri

auto result = Json::Value( Json::objectValue );
dev::u256 oldestBlock;
if ( blockCount > newestBlock )
if ( _blockCount > newestBlock )
oldestBlock = 1;
else
oldestBlock = dev::u256( newestBlock ) - blockCount + 1;
oldestBlock = dev::u256( newestBlock ) - _blockCount + 1;
result["oldestBlock"] = toJS( oldestBlock );

result["baseFeePerGas"] = Json::Value( Json::arrayValue );
Expand Down
2 changes: 1 addition & 1 deletion libweb3jsonrpc/Eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class Eth : public dev::rpc::EthFace, public skutils::json_config_file_accessor
virtual Json::Value eth_createAccessList(
const Json::Value& param1, const std::string& param2 ) override;
virtual Json::Value eth_feeHistory(
const std::string& param1, const std::string& param2, const Json::Value& param3 ) override;
dev::u256 param1, const std::string& param2, const Json::Value& param3 ) override;
virtual std::string eth_maxPriorityFeePerGas() override;

void setTransactionDefaults( eth::TransactionSkeleton& _t );
Expand Down
14 changes: 9 additions & 5 deletions libweb3jsonrpc/EthFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ModularServer.h"

#include <libdevcore/CommonJS.h>
#include <libethereum/TransactionReceipt.h>
#include <libweb3jsonrpc/JsonHelper.h>

Expand Down Expand Up @@ -222,8 +223,7 @@ class EthFace : public ServerInterface< EthFace > {
jsonrpc::JSON_OBJECT, "param2", jsonrpc::JSON_STRING, NULL ),
&dev::rpc::EthFace::eth_createAccessListI );
this->bindAndAddMethod( jsonrpc::Procedure( "eth_feeHistory", jsonrpc::PARAMS_BY_POSITION,
jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_STRING, "param2",
jsonrpc::JSON_STRING, "param3", jsonrpc::JSON_ARRAY, NULL ),
jsonrpc::JSON_OBJECT, NULL ),
&dev::rpc::EthFace::eth_feeHistoryI );
this->bindAndAddMethod( jsonrpc::Procedure( "eth_maxPriorityFeePerGas",
jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ),
Expand Down Expand Up @@ -449,8 +449,12 @@ class EthFace : public ServerInterface< EthFace > {
if ( !request.isArray() || request.size() != 3 )
BOOST_THROW_EXCEPTION(
jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) );
response =
this->eth_feeHistory( request[0u].asString(), request[1u].asString(), request[2u] );
if ( !request[0u].isString() && !request[0u].isUInt() )
BOOST_THROW_EXCEPTION(
jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) );
auto blockCount = request[0u].isString() ? dev::jsToU256( request[0u].asString() ) :
dev::u256( request[0u].asUInt() );
response = this->eth_feeHistory( blockCount, request[1u].asString(), request[2u] );
}
inline virtual void eth_maxPriorityFeePerGasI(
const Json::Value& request, Json::Value& response ) {
Expand Down Expand Up @@ -525,7 +529,7 @@ class EthFace : public ServerInterface< EthFace > {
virtual Json::Value eth_createAccessList(
const Json::Value& param1, const std::string& param2 ) = 0;
virtual Json::Value eth_feeHistory(
const std::string& param1, const std::string& param2, const Json::Value& param3 ) = 0;
dev::u256 param1, const std::string& param2, const Json::Value& param3 ) = 0;
virtual std::string eth_maxPriorityFeePerGas() = 0;
};

Expand Down
7 changes: 5 additions & 2 deletions test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,12 @@ Json::Value WebThreeStubClient::eth_createAccessList( const Json::Value& param1,
jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() );
}

Json::Value WebThreeStubClient::eth_feeHistory( const std::string& param1, const std::string& param2, const Json::Value& param3 ) {
Json::Value WebThreeStubClient::eth_feeHistory( const Json::Value& param1, const std::string& param2, const Json::Value& param3 ) {
Json::Value p;
p.append( param1 );
if ( param1.isString() )
p.append( param1.asString() );
if ( param1.isUInt() )
p.append( param1.asUInt() );
p.append( param2 );
p.append( param3 );
Json::Value result = this->CallMethod( "eth_feeHistory", p );
Expand Down
4 changes: 3 additions & 1 deletion test/unittests/libweb3jsonrpc/WebThreeStubClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_
#define JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_

#include <any>

#include <jsonrpccpp/client.h>

class WebThreeStubClient : public jsonrpc::Client {
Expand Down Expand Up @@ -98,7 +100,7 @@ class WebThreeStubClient : public jsonrpc::Client {
std::string eth_sendRawTransaction( const std::string& param1 ) noexcept( false );
std::string eth_maxPriorityFeePerGas() noexcept( false );
Json::Value eth_createAccessList( const Json::Value& param1, const std::string& param2 ) noexcept( false );
Json::Value eth_feeHistory( const std::string& param1, const std::string& param2, const Json::Value& param3 ) noexcept( false );
Json::Value eth_feeHistory( const Json::Value& param1, const std::string& param2, const Json::Value& param3 ) noexcept( false );
bool eth_notePassword( const std::string& param1 ) noexcept( false );
bool db_put( const std::string& param1, const std::string& param2,
const std::string& param3 ) noexcept( false );
Expand Down
2 changes: 2 additions & 0 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,8 @@ BOOST_AUTO_TEST_CASE( eip1559RpcMethods ) {
BOOST_REQUIRE_EQUAL( feeHistory["reward"][i][j].asString(), toJS( 0 ) );
}
}

BOOST_REQUIRE_NO_THROW( fixture.rpcClient->eth_feeHistory( blockCnt, "latest", percentiles ) );
}

BOOST_AUTO_TEST_CASE( etherbase_generation2 ) {
Expand Down

0 comments on commit e321dfb

Please sign in to comment.