Skip to content

Commit b1ae801

Browse files
Feature: add revert reason to receipt (#717)
* added revert reason to receipt * Revert_reason code cleanup * added docs for is_txn_reverted method * removed async from decode_revert_reason * removed revert_reason decoding --------- Co-authored-by: artem.ivanov <[email protected]>
1 parent 135a5b3 commit b1ae801

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/confirm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ async fn send_transaction_with_confirmation_<T: Transport>(
8686
.transaction_receipt(hash)
8787
.await?
8888
.expect("receipt can't be null after wait for confirmations; qed");
89+
8990
Ok(receipt)
9091
}
9192

@@ -163,6 +164,7 @@ mod tests {
163164
logs_bloom: Default::default(),
164165
transaction_type: None,
165166
effective_gas_price: Default::default(),
167+
revert_reason: None,
166168
};
167169

168170
let poll_interval = Duration::from_secs(0);

src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ pub enum Error {
4747
/// web3 internal error
4848
#[display(fmt = "Internal Web3 error")]
4949
Internal,
50+
/// Transaction reverted
51+
#[display(fmt = "Transaction reverted: {}", _0)]
52+
#[from(ignore)]
53+
Revert(String),
5054
}
5155

5256
impl std::error::Error for Error {
5357
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
5458
use self::Error::*;
5559
match *self {
56-
Unreachable | Decoder(_) | InvalidResponse(_) | Transport { .. } | Internal => None,
60+
Unreachable | Decoder(_) | InvalidResponse(_) | Transport { .. } | Internal | Revert(_) => None,
5761
Rpc(ref e) => Some(e),
5862
Io(ref e) => Some(e),
5963
Recovery(ref e) => Some(e),
@@ -79,6 +83,7 @@ impl Clone for Error {
7983
Io(e) => Io(IoError::from(e.kind())),
8084
Recovery(e) => Recovery(e.clone()),
8185
Internal => Internal,
86+
Revert(s) => Revert(s.clone()),
8287
}
8388
}
8489
}
@@ -94,6 +99,7 @@ impl PartialEq for Error {
9499
(Rpc(a), Rpc(b)) => a == b,
95100
(Io(a), Io(b)) => a.kind() == b.kind(),
96101
(Recovery(a), Recovery(b)) => a == b,
102+
(Revert(a), Revert(b)) => a == b,
97103
_ => false,
98104
}
99105
}

src/types/transaction.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ pub struct Receipt {
108108
/// Effective gas price
109109
#[serde(rename = "effectiveGasPrice")]
110110
pub effective_gas_price: Option<U256>,
111+
/// Transaction revert reason
112+
#[serde(rename = "revertReason")]
113+
pub revert_reason: Option<String>,
114+
}
115+
116+
impl Receipt {
117+
/// Checks transaction execution reverted
118+
pub fn is_txn_reverted(&self) -> bool {
119+
self.status == Some(0.into())
120+
}
111121
}
112122

113123
/// Raw bytes of a signed, but not yet sent transaction

0 commit comments

Comments
 (0)