@@ -476,12 +476,34 @@ asio::awaitable<void> EthereumRpcApi::handle_eth_get_transaction_by_block_hash_a
476476
477477// https://eth.wiki/json-rpc/API#eth_gettransactionbyblocknumberandindex
478478asio::awaitable<void > EthereumRpcApi::handle_eth_get_transaction_by_block_number_and_index (const nlohmann::json& request, nlohmann::json& reply) {
479+ auto params = request[" params" ];
480+ if (params.size () != 2 ) {
481+ auto error_msg = " invalid eth_getTransactionByBlockNumberAndIndex params: " + params.dump ();
482+ SILKRPC_ERROR << error_msg << " \n " ;
483+ reply = make_json_error (request[" id" ], 100 , error_msg);
484+ co_return ;
485+ }
486+ const auto block_id = params[0 ].get <std::string>();
487+ const auto index = params[1 ].get <std::string>();
488+ SILKRPC_DEBUG << " block_id: " << block_id << " index: " << index << " \n " ;
489+
479490 auto tx = co_await database_->begin ();
480491
481492 try {
482493 ethdb::TransactionDatabase tx_database{*tx};
483494
484- reply = make_json_content (request[" id" ], " 0x" + to_hex_no_leading_zeros (0 ));
495+ const auto block_number = co_await core::get_block_number (block_id, tx_database);
496+ const auto block_with_number = co_await core::rawdb::read_block_by_number (tx_database, block_number);
497+ const auto transactions = block_with_number.block .transactions ;
498+
499+ auto idx = std::stoul (index, 0 , 16 );
500+ if (idx >= transactions.size ()) {
501+ auto error_msg = " invalid eth_getTransactionByBlockNumberAndIndex index: " + index;
502+ SILKRPC_ERROR << error_msg << " \n " ;
503+ reply = make_json_error (request[" id" ], 100 , error_msg);
504+ co_return ;
505+ }
506+ reply = make_json_content (request[" id" ], transactions[idx]);
485507 } catch (const std::exception& e) {
486508 SILKRPC_ERROR << " exception: " << e.what () << " \n " ;
487509 reply = make_json_error (request[" id" ], 100 , e.what ());
0 commit comments