diff --git a/src/confirm.rs b/src/confirm.rs index 900110cb..f84941de 100644 --- a/src/confirm.rs +++ b/src/confirm.rs @@ -86,6 +86,7 @@ async fn send_transaction_with_confirmation_( .transaction_receipt(hash) .await? .expect("receipt can't be null after wait for confirmations; qed"); + Ok(receipt) } @@ -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); diff --git a/src/error.rs b/src/error.rs index d858d688..24f0776b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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), @@ -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()), } } } @@ -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, } } diff --git a/src/types/transaction.rs b/src/types/transaction.rs index 017fd23a..3e4bf8d8 100644 --- a/src/types/transaction.rs +++ b/src/types/transaction.rs @@ -108,6 +108,16 @@ pub struct Receipt { /// Effective gas price #[serde(rename = "effectiveGasPrice")] pub effective_gas_price: Option, + /// Transaction revert reason + #[serde(rename = "revertReason")] + pub revert_reason: Option, +} + +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