diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b8f2a7698c..3afd72a366f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ - [#4704](https://github.com/ChainSafe/forest/issues/4704) Add support for the `Filecoin.EthGetTransactionReceiptLimited` RPC method. +- [#4701](https://github.com/ChainSafe/forest/issues/4701) Add support for the + `Filecoin.EthGetTransactionByBlockHashAndIndex` RPC method. + ### Changed ### Removed diff --git a/scripts/tests/api_compare/filter-list b/scripts/tests/api_compare/filter-list index 301ad29e8c4..84b318f69ec 100644 --- a/scripts/tests/api_compare/filter-list +++ b/scripts/tests/api_compare/filter-list @@ -11,8 +11,6 @@ # TODO: https://github.com/ChainSafe/forest/issues/4996 !Filecoin.EthGetTransactionReceipt !Filecoin.EthGetTransactionReceiptLimited -# TODO: https://github.com/ChainSafe/forest/issues/4701 -!Filecoin.EthGetTransactionByBlockHashAndIndex !Filecoin.EthGetTransactionByBlockNumberAndIndex # TODO: https://github.com/ChainSafe/forest/issues/5006 !Filecoin.EthGetBlockReceipts diff --git a/scripts/tests/api_compare/filter-list-offline b/scripts/tests/api_compare/filter-list-offline index 75aa20c4123..27afe718129 100644 --- a/scripts/tests/api_compare/filter-list-offline +++ b/scripts/tests/api_compare/filter-list-offline @@ -41,8 +41,6 @@ # TODO: https://github.com/ChainSafe/forest/issues/4996 !Filecoin.EthGetTransactionReceipt !Filecoin.EthGetTransactionReceiptLimited -# TODO: https://github.com/ChainSafe/forest/issues/4701 -!Filecoin.EthGetTransactionByBlockHashAndIndex !Filecoin.EthGetTransactionByBlockNumberAndIndex # TODO: https://github.com/ChainSafe/forest/issues/5006 !Filecoin.EthGetBlockReceipts diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index e5d490fb69b..2095c83cf96 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -2035,7 +2035,7 @@ pub enum EthGetTransactionByBlockHashAndIndex {} impl RpcMethod<2> for EthGetTransactionByBlockHashAndIndex { const NAME: &'static str = "Filecoin.EthGetTransactionByBlockHashAndIndex"; const NAME_ALIAS: Option<&'static str> = Some("eth_getTransactionByBlockHashAndIndex"); - const PARAM_NAMES: [&'static str; 2] = ["p1", "p2"]; + const PARAM_NAMES: [&'static str; 2] = ["block_hash", "tx_index"]; const API_PATHS: ApiPaths = ApiPaths::V1; const PERMISSION: Permission = Permission::Read; @@ -2043,11 +2043,34 @@ impl RpcMethod<2> for EthGetTransactionByBlockHashAndIndex { type Ok = Option; async fn handle( - _ctx: Ctx, - (_p1, _p2): Self::Params, + ctx: Ctx, + (block_hash, tx_index): Self::Params, ) -> Result { - // Lotus doesn't support this method (v1.29.0), so do we. - Err(ServerError::unsupported_method()) + let ts = get_tipset_from_hash(ctx.chain_store(), &block_hash)?; + + let messages = ctx.chain_store().messages_for_tipset(&ts)?; + + let EthUint64(index) = tx_index; + let msg = messages.get(index as usize).with_context(|| { + format!( + "index {} out of range: tipset contains {} messages", + index, + messages.len() + ) + })?; + + let state = StateTree::new_from_root(ctx.store_owned(), ts.parent_state())?; + + let tx = new_eth_tx( + &ctx, + &state, + ts.epoch(), + &ts.key().cid()?, + &msg.cid(), + index, + )?; + + Ok(Some(tx)) } }