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

Feature: add revert reason to receipt #717

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async fn send_transaction_with_confirmation_<T: Transport>(
.transaction_receipt(hash)
.await?
.expect("receipt can't be null after wait for confirmations; qed");

Ok(receipt)
}

Expand Down Expand Up @@ -163,6 +164,7 @@ mod tests {
logs_bloom: Default::default(),
transaction_type: None,
effective_gas_price: Default::default(),
revert_reason: None,
};

let poll_interval = Duration::from_secs(0);
Expand Down
8 changes: 7 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ pub enum Error {
/// web3 internal error
#[display(fmt = "Internal Web3 error")]
Internal,
/// Transaction reverted
#[display(fmt = "Transaction reverted: {}", _0)]
#[from(ignore)]
Revert(String),
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use self::Error::*;
match *self {
Unreachable | Decoder(_) | InvalidResponse(_) | Transport { .. } | Internal => None,
Unreachable | Decoder(_) | InvalidResponse(_) | Transport { .. } | Internal | Revert(_) => None,
Rpc(ref e) => Some(e),
Io(ref e) => Some(e),
Recovery(ref e) => Some(e),
Expand All @@ -79,6 +83,7 @@ impl Clone for Error {
Io(e) => Io(IoError::from(e.kind())),
Recovery(e) => Recovery(e.clone()),
Internal => Internal,
Revert(s) => Revert(s.clone()),
}
}
}
Expand All @@ -94,6 +99,7 @@ impl PartialEq for Error {
(Rpc(a), Rpc(b)) => a == b,
(Io(a), Io(b)) => a.kind() == b.kind(),
(Recovery(a), Recovery(b)) => a == b,
(Revert(a), Revert(b)) => a == b,
_ => false,
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ pub struct Receipt {
/// Effective gas price
#[serde(rename = "effectiveGasPrice")]
pub effective_gas_price: Option<U256>,
/// Transaction revert reason
#[serde(rename = "revertReason")]
pub revert_reason: Option<String>,
}

impl Receipt {
/// Checks transaction execution reverted
pub fn is_txn_reverted(&self) -> bool {
self.status == Some(0.into())
}
}

/// Raw bytes of a signed, but not yet sent transaction
Expand Down
Loading