Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
closes #9188
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Nov 7, 2018
1 parent 3a6e04b commit 0a22288
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ pub fn cannot_submit_work(err: EthcoreError) -> Error {
}
}

pub fn ancient_block_missing() -> Error {
Error {
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
message: "Ancient block missing".into(),
data: None,
}
}

pub fn not_enough_data() -> Error {
Error {
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
Expand Down
23 changes: 22 additions & 1 deletion rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
}

fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<Transaction>> {
if let Ok(SyncStatus::Info(_)) = self.syncing() {
// alas, we're still syncing!
warn!("Attempted to fetch transaction via hash while sync is in progress");
return Box::new(future::err(errors::ancient_block_missing()))
}

let hash: H256 = hash.into();
let tx = try_bf!(self.transaction(PendingTransactionId::Hash(hash))).or_else(|| {
self.miner.transaction(&hash)
Expand All @@ -661,7 +667,16 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<

fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture<Option<Transaction>> {
let id = PendingTransactionId::Location(PendingOrBlock::Block(BlockId::Hash(hash.into())), index.value());
Box::new(future::done(self.transaction(id)))
Box::new(future::done(self.transaction(id).and_then(|res| {
if res.is_none() {
if let Ok(SyncStatus::Info(_)) = self.syncing() {
// alas, we're still syncing!
warn!("Call made to transaction_by_block_hash_and_index while sync is in progress");
return Err(errors::ancient_block_missing())
}
}
Ok(res)
})))
}

fn transaction_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> BoxFuture<Option<Transaction>> {
Expand All @@ -677,6 +692,12 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
}

fn transaction_receipt(&self, hash: RpcH256) -> BoxFuture<Option<Receipt>> {
if let Ok(SyncStatus::Info(_)) = self.syncing() {
// alas, we're still syncing!
warn!("Attempted to fetch transaction via hash while sync is in progress");
return Box::new(future::err(errors::ancient_block_missing()))
}

let hash: H256 = hash.into();

if self.options.allow_pending_receipt_query {
Expand Down

0 comments on commit 0a22288

Please sign in to comment.