mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: move decode_revert_reason to primitives (#2615)
This commit is contained in:
16
crates/primitives/src/abi.rs
Normal file
16
crates/primitives/src/abi.rs
Normal file
@ -0,0 +1,16 @@
|
||||
//! Eth ABI helpers.
|
||||
use crate::constants::SELECTOR_LEN;
|
||||
|
||||
/// Returns the revert reason from the given output data, if it's an abi encoded String. Returns
|
||||
/// `None` if the output is not long enough to contain a function selector or the content is not a
|
||||
/// valid abi encoded String.
|
||||
///
|
||||
/// **Note:** it's assumed the `out` buffer starts with the call's signature
|
||||
pub fn decode_revert_reason(out: impl AsRef<[u8]>) -> Option<String> {
|
||||
use ethers_core::abi::AbiDecode;
|
||||
let out = out.as_ref();
|
||||
if out.len() < SELECTOR_LEN {
|
||||
return None
|
||||
}
|
||||
String::decode(&out[SELECTOR_LEN..]).ok()
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
//!
|
||||
//! This crate contains Ethereum primitive types and helper functions.
|
||||
|
||||
pub mod abi;
|
||||
mod account;
|
||||
pub mod basefee;
|
||||
mod bits;
|
||||
|
||||
Reference in New Issue
Block a user