@@ -160,7 +160,7 @@ asio::awaitable<void> EthereumRpcApi::handle_eth_syncing(const nlohmann::json& r
160160asio::awaitable<void > EthereumRpcApi::handle_eth_get_block_by_hash (const nlohmann::json& request, nlohmann::json& reply) {
161161 auto params = request[" params" ];
162162 if (params.size () != 2 ) {
163- auto error_msg = " invalid eth_getLogs params: " + params.dump ();
163+ auto error_msg = " invalid eth_getBlockByHash params: " + params.dump ();
164164 SILKRPC_ERROR << error_msg << " \n " ;
165165 reply = make_json_error (request[" id" ], 100 , error_msg);
166166 co_return ;
@@ -192,11 +192,44 @@ asio::awaitable<void> EthereumRpcApi::handle_eth_get_block_by_hash(const nlohman
192192 co_return ;
193193}
194194
195+ // https://eth.wiki/json-rpc/API#eth_getblocktransactioncountbyhash
196+ asio::awaitable<void > EthereumRpcApi::handle_eth_get_block_transaction_count_by_hash (const nlohmann::json& request, nlohmann::json& reply) {
197+ auto params = request[" params" ];
198+ if (params.size () != 1 ) {
199+ auto error_msg = " invalid eth_getBlockTransactionCountByHash params: " + params.dump ();
200+ SILKRPC_ERROR << error_msg << " \n " ;
201+ reply = make_json_error (request[" id" ], 100 , error_msg);
202+ co_return ;
203+ }
204+ auto block_hash = params[0 ].get <evmc::bytes32>();
205+ SILKRPC_DEBUG << " block_hash: " << block_hash << " \n " ;
206+
207+ auto tx = co_await database_->begin ();
208+
209+ try {
210+ ethdb::kv::TransactionDatabase tx_database{*tx};
211+
212+ const auto block_with_hash = co_await core::rawdb::read_block_by_hash (tx_database, block_hash);
213+ const auto tx_count = block_with_hash.block .transactions .size ();
214+
215+ reply = make_json_content (request[" id" ], " 0x" + to_hex_no_leading_zeros (tx_count));
216+ } catch (const std::exception& e) {
217+ SILKRPC_ERROR << " exception: " << e.what () << " \n " ;
218+ reply = make_json_error (request[" id" ], 100 , e.what ());
219+ } catch (...) {
220+ SILKRPC_ERROR << " unexpected exception\n " ;
221+ reply = make_json_error (request[" id" ], 100 , " unexpected exception" );
222+ }
223+
224+ co_await tx->close (); // RAII not (yet) available with coroutines
225+ co_return ;
226+ }
227+
195228// https://eth.wiki/json-rpc/API#eth_getblockbynumber
196229asio::awaitable<void > EthereumRpcApi::handle_eth_get_block_by_number (const nlohmann::json& request, nlohmann::json& reply) {
197230 auto params = request[" params" ];
198231 if (params.size () != 2 ) {
199- auto error_msg = " invalid eth_getLogs params: " + params.dump ();
232+ auto error_msg = " invalid getBlockByNumber params: " + params.dump ();
200233 SILKRPC_ERROR << error_msg << " \n " ;
201234 reply = make_json_error (request[" id" ], 100 , error_msg);
202235 co_return ;
0 commit comments