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

Fix Eth::uncle #406

Merged
merged 2 commits into from
Dec 9, 2020
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
26 changes: 23 additions & 3 deletions src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::api::Namespace;
use crate::helpers::{self, CallFuture};
use crate::types::{
Address, Block, BlockId, BlockNumber, Bytes, CallRequest, Filter, Index, Log, SyncState, Transaction,
Address, Block, BlockHeader, BlockId, BlockNumber, Bytes, CallRequest, Filter, Index, Log, SyncState, Transaction,
TransactionId, TransactionReceipt, TransactionRequest, Work, H256, H520, H64, U256, U64,
};
use crate::Transport;
Expand Down Expand Up @@ -219,8 +219,20 @@ impl<T: Transport> Eth<T> {
CallFuture::new(self.transport.execute("eth_getTransactionReceipt", vec![hash]))
}

/// Get uncle header by block ID and uncle index.
///
/// This method is meant for TurboGeth compatiblity,
/// which is missing transaction hashes in the response.
pub fn uncle_header(&self, block: BlockId, index: Index) -> CallFuture<Option<BlockHeader>, T::Out> {
self.fetch_uncle(block, index)
}

/// Get uncle by block ID and uncle index -- transactions only has hashes.
pub fn uncle(&self, block: BlockId, index: Index) -> CallFuture<Option<Block<H256>>, T::Out> {
self.fetch_uncle(block, index)
}

fn fetch_uncle<X>(&self, block: BlockId, index: Index) -> CallFuture<Option<X>, T::Out> {
let index = helpers::serialize(&index);

let result = match block {
Expand Down Expand Up @@ -335,8 +347,8 @@ mod tests {
use crate::api::Namespace;
use crate::rpc::Value;
use crate::types::{
Address, Block, BlockId, BlockNumber, Bytes, CallRequest, FilterBuilder, Log, SyncInfo, SyncState, Transaction,
TransactionId, TransactionReceipt, TransactionRequest, Work, H256, H520, H64,
Address, Block, BlockHeader, BlockId, BlockNumber, Bytes, CallRequest, FilterBuilder, Log, SyncInfo, SyncState,
Transaction, TransactionId, TransactionReceipt, TransactionRequest, Work, H256, H520, H64,
};

use super::Eth;
Expand Down Expand Up @@ -659,6 +671,14 @@ mod tests {
=> Some(::serde_json::from_str::<Block<H256>>(EXAMPLE_BLOCK).unwrap())
);

rpc_test! (
Eth:uncle_header:uncle_header_by_hash, BlockId::Hash(H256::from_low_u64_be(0x123)), 5
=>
"eth_getUncleByBlockHashAndIndex", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#, r#""0x5""#];
::serde_json::from_str(EXAMPLE_BLOCK).unwrap()
=> Some(::serde_json::from_str::<BlockHeader>(EXAMPLE_BLOCK).unwrap())
);

rpc_test! (
Eth:uncle:uncle_by_no, BlockNumber::Earliest, 5
=>
Expand Down