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: Add EthGetBlockReceipts RPC method #4985

Merged
merged 15 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -64,6 +64,9 @@ for more details.
- [#4706](https://github.com/ChainSafe/forest/issues/4706) Add support for the
`Filecoin.EthSendRawTransaction` RPC method.

- [#4985](https://github.com/ChainSafe/forest/pull/4985) Add support for the
`Filecoin.EthGetTransactionReceipt` RPC method.
virajbhartiya marked this conversation as resolved.
Show resolved Hide resolved

- [#4943](https://github.com/ChainSafe/forest/pull/4943) Add generation of
method aliases for `forest-tool shed openrpc` subcommand and sort all methods
in lexicographic order.
Expand Down
41 changes: 41 additions & 0 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,47 @@ impl RpcMethod<2> for EthGetBlockByNumber {
}
}

pub enum EthGetBlockReceipts {}
impl RpcMethod<1> for EthGetBlockReceipts {
const NAME: &'static str = "Filecoin.EthGetBlockReceipts";
const NAME_ALIAS: Option<&'static str> = Some("eth_getBlockReceipts");
const PARAM_NAMES: [&'static str; 1] = ["block_hash"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

type Params = (EthHash,);
type Ok = Vec<EthTxReceipt>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(block_hash,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = get_tipset_from_hash(ctx.chain_store(), &block_hash)?;

let (_, msgs_and_receipts) = execute_tipset(&ctx, &Arc::new(ts.clone())).await?;

let mut receipts = Vec::with_capacity(msgs_and_receipts.len());

for (i, (msg, receipt)) in msgs_and_receipts.into_iter().enumerate() {
let return_data = receipt.return_data().clone();
virajbhartiya marked this conversation as resolved.
Show resolved Hide resolved
let message_lookup = MessageLookup {
receipt: receipt,
virajbhartiya marked this conversation as resolved.
Show resolved Hide resolved
tipset: ts.key().clone(),
height: ts.epoch(),
message: msg.cid(),
return_dec: return_data.deserialize().unwrap_or(Ipld::Null),
};

let tx = new_eth_tx_from_message_lookup(&ctx, &message_lookup, Some(i as u64))?;

let tx_receipt = new_eth_tx_receipt(&ctx, &tx, &message_lookup).await?;
receipts.push(tx_receipt);
}

Ok(receipts)
}
}

pub enum EthGetBlockTransactionCountByHash {}
impl RpcMethod<1> for EthGetBlockTransactionCountByHash {
const NAME: &'static str = "Filecoin.EthGetBlockTransactionCountByHash";
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::eth::EthGetBalance);
$callback!(crate::rpc::eth::EthGetBlockByHash);
$callback!(crate::rpc::eth::EthGetBlockByNumber);
$callback!(crate::rpc::eth::EthGetBlockReceipts);
$callback!(crate::rpc::eth::EthGetBlockTransactionCountByHash);
$callback!(crate::rpc::eth::EthGetBlockTransactionCountByNumber);
$callback!(crate::rpc::eth::EthGetCode);
Expand Down
1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
))
.unwrap(),
),
RpcTest::identity(EthGetBlockReceipts::request((block_hash.clone(),)).unwrap()),
RpcTest::identity(
EthGetBlockTransactionCountByHash::request((block_hash.clone(),)).unwrap(),
),
Expand Down