Skip to content

Commit

Permalink
fix: check mempool when call eth_getTransactionByHash
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticlonghair committed Nov 8, 2023
1 parent 64f07fb commit fb1ad92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 5 additions & 1 deletion core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ where
ctx: Context,
tx_hash: Hash,
) -> ProtocolResult<Option<SignedTransaction>> {
self.storage.get_transaction_by_hash(ctx, &tx_hash).await
if let Some(tx) = self.mempool.get_tx_from_mem(ctx.clone(), &tx_hash) {
Ok(Some(tx))
} else {
self.storage.get_transaction_by_hash(ctx, &tx_hash).await
}
}

async fn get_transactions_by_hashes(
Expand Down
4 changes: 0 additions & 4 deletions core/api/src/jsonrpc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub enum RpcError {
GasLimitIsZero,
#[display(fmt = "Transaction is not signed")]
TransactionIsNotSigned,
#[display(fmt = "Cannot get receipt by hash")]
CannotGetReceiptByHash,
#[display(fmt = "Cannot get latest block")]
CannotGetLatestBlock,
#[display(fmt = "Invalid block hash")]
Expand Down Expand Up @@ -80,7 +78,6 @@ impl RpcError {
RpcError::GasLimitIsTooLarge => -40009,
RpcError::GasLimitIsZero => -40010,
RpcError::TransactionIsNotSigned => -40011,
RpcError::CannotGetReceiptByHash => -40012,
RpcError::CannotGetLatestBlock => -40013,
RpcError::InvalidBlockHash => -40014,
RpcError::InvalidFromBlockNumber(_) => -40015,
Expand Down Expand Up @@ -118,7 +115,6 @@ impl From<RpcError> for ErrorObjectOwned {
RpcError::GasLimitIsTooLarge => ErrorObject::owned(err_code, err, none_data),
RpcError::GasLimitIsZero => ErrorObject::owned(err_code, err, none_data),
RpcError::TransactionIsNotSigned => ErrorObject::owned(err_code, err, none_data),
RpcError::CannotGetReceiptByHash => ErrorObject::owned(err_code, err, none_data),
RpcError::CannotGetLatestBlock => ErrorObject::owned(err_code, err, none_data),
RpcError::InvalidBlockHash => ErrorObject::owned(err_code, err, none_data),
RpcError::InvalidFromBlockNumber(_) => ErrorObject::owned(err_code, err, none_data),
Expand Down
2 changes: 1 addition & 1 deletion core/api/src/jsonrpc/impl/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<Adapter: APIAdapter + 'static> Web3RpcServer for Web3RpcImpl<Adapter> {
{
Ok(Some((stx, receipt).into()))
} else {
Err(RpcError::CannotGetReceiptByHash.into())
Ok(Some(stx.into()))
}
} else {
Ok(None)
Expand Down

0 comments on commit fb1ad92

Please sign in to comment.