Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impelement EthGetTransactionByBlockHashAndIndex #5019

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 28 additions & 5 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2035,19 +2035,42 @@ 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;

type Params = (EthHash, EthUint64);
type Ok = Option<ApiEthTx>;

async fn handle(
_ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(_p1, _p2): Self::Params,
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(block_hash, tx_index): Self::Params,
) -> Result<Self::Ok, ServerError> {
// 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))
}
}

Expand Down
Loading