Skip to main content

neo_devpack_solidity/runtime/runtime_parts/runtime_impl/
execution_result.rs

1use super::*;
2
3impl ExecutionResult {
4    /// Check if execution was successful
5    pub fn is_success(&self) -> bool {
6        self.success && self.exception.is_none()
7    }
8
9    /// Get gas efficiency (percentage of gas limit used)
10    pub fn gas_efficiency(&self) -> f64 {
11        if self.gas_limit == 0 {
12            0.0
13        } else {
14            (self.gas_used as f64) / (self.gas_limit as f64)
15        }
16    }
17
18    /// Get remaining gas
19    pub fn gas_remaining(&self) -> u64 {
20        self.gas_limit.saturating_sub(self.gas_used)
21    }
22
23    /// Check if execution ran out of gas
24    pub fn out_of_gas(&self) -> bool {
25        matches!(
26            self.exception,
27            Some(RuntimeException {
28                exception_type: ExceptionType::OutOfGas,
29                ..
30            })
31        )
32    }
33
34    /// Get return data as string (if valid UTF-8)
35    pub fn return_string(&self) -> Option<String> {
36        String::from_utf8(self.return_data.clone()).ok()
37    }
38
39    /// Get return data as hex string
40    pub fn return_hex(&self) -> String {
41        hex::encode(&self.return_data)
42    }
43
44    /// Check if there were any state changes
45    pub fn has_state_changes(&self) -> bool {
46        !self.state_changes.is_empty()
47    }
48
49    /// Get the number of logs emitted
50    pub fn log_count(&self) -> usize {
51        self.logs.len()
52    }
53}