MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / parse_from_bytes

Method parse_from_bytes

contract-bindings/src/error_parser.rs:81–194  ·  view source on GitHub ↗
(bytes: &[u8])

Source from the content-addressed store, hash-verified

79
80impl ContractErrorParser {
81 pub fn parse_from_bytes(bytes: &[u8]) -> Result<ParsedError, ParseContractError> {
82 if bytes.len() < SOLIDITY_SELECTOR_BYTE_SIZE {
83 return Err(ParseContractError::ErrorBytesTooShort);
84 }
85
86 let selector = const_hex::encode(&bytes[0..4]);
87
88 // Check for standard Solidity errors first
89 match selector.as_str() {
90 ERROR_STRING_SELECTOR => {
91 // Handle Error(string)
92 if bytes.len() >= 68 {
93 // 4 bytes selector + 32 bytes offset + 32 bytes length
94 let length_start = 36; // 4 + 32
95 let length_end = 68; // 4 + 32 + 32
96
97 if bytes.len() >= length_end {
98 let length_bytes = &bytes[length_start..length_end];
99 let length_u256 = ethers::types::U256::from_big_endian(length_bytes);
100 let length = length_u256.as_u64();
101
102 let message_start = length_end;
103 let message_end = message_start + length as usize;
104
105 if bytes.len() >= message_end {
106 let message_bytes = &bytes[message_start..message_end];
107 if let Ok(message) = String::from_utf8(message_bytes.to_vec()) {
108 return Ok(ParsedError {
109 error_type: ErrorType::StandardRevert,
110 name: "RevertString".to_string(),
111 message: Some(message),
112 parameters: None,
113 });
114 }
115 }
116 }
117 }
118
119 // Fallback if parsing fails
120 Ok(ParsedError {
121 error_type: ErrorType::StandardRevert,
122 name: "RevertString".to_string(),
123 message: None,
124 parameters: None,
125 })
126 }
127 PANIC_SELECTOR => {
128 // Handle Panic(uint256)
129 if bytes.len() >= 36 {
130 // 4 bytes selector + 32 bytes panic code
131 let panic_code_bytes = &bytes[4..36];
132 let panic_code_u256 = ethers::types::U256::from_big_endian(panic_code_bytes);
133 let panic_code = panic_code_u256.as_u64();
134
135 let panic_message = match panic_code {
136 0x00 => "Generic panic",
137 0x01 => "Assertion failed",
138 0x11 => "Arithmetic overflow/underflow",

Callers

nothing calls this directly

Calls 7

as_strMethod · 0.80
to_stringMethod · 0.80
lenMethod · 0.45
getMethod · 0.45
decodeMethod · 0.45
containsMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected