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

Add support for eth_getBlockReceipts #15

Merged
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
39 changes: 39 additions & 0 deletions src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ impl<T: Transport> Eth<T> {
CallFuture::new(result)
}

/// Get block receipts
pub fn block_receipts(&self, block: BlockId) -> CallFuture<Option<Vec<TransactionReceipt>>, T::Out> {
let result = match block {
BlockId::Hash(hash) => {
let hash = helpers::serialize(&hash);
self.transport.execute("eth_getBlockReceipts", vec![hash])
}
BlockId::Number(num) => {
let num = helpers::serialize(&num);
self.transport.execute("eth_getBlockReceipts", vec![num])
}
};

CallFuture::new(result)
}

/// Get block details with full transaction objects.
pub fn block_with_txs(&self, block: BlockId) -> CallFuture<Option<Block<Transaction>>, T::Out> {
let include_txs = helpers::serialize(&true);
Expand Down Expand Up @@ -505,6 +521,21 @@ mod tests {
"status": "0x1",
"effectiveGasPrice": "0x100"
}"#;

const EXAMPLE_BLOCK_RECEIPTS: &str = r#"[{
"transactionHash": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238",
"transactionIndex": "0x1",
"from": "0xa7d9ddbe1f17865597fbd27ec712455208b6b76d",
"blockNumber": "0xb",
"blockHash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"cumulativeGasUsed": "0x33bc",
"gasUsed": "0x4dc",
"contractAddress": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"logsBloom": "0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
"logs": [],
"status": "0x1",
"effectiveGasPrice": "0x100"
}]"#;

const EXAMPLE_FEE_HISTORY: &str = r#"{
"baseFeePerGas": [
Expand Down Expand Up @@ -682,6 +713,14 @@ mod tests {
=> Some(::serde_json::from_str::<Block<Transaction>>(EXAMPLE_BLOCK).unwrap())
);

rpc_test! (
Eth:block_receipts, BlockId::Number(100i64.into())
=>
"eth_getBlockReceipts", vec![r#""0x64""#];
::serde_json::from_str(EXAMPLE_BLOCK_RECEIPTS).unwrap()
=> Some(::serde_json::from_str::<Vec<TransactionReceipt>>(EXAMPLE_BLOCK_RECEIPTS).unwrap())
);

rpc_test! (
Eth:block_transaction_count:block_tx_count_by_hash, BlockId::Hash(H256::from_low_u64_be(0x123))
=>
Expand Down
Loading