1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::call::CallFrame;
use crate::consts::*;
use crate::interpreter::Interpreter;
use fuel_tx::{CheckedTransaction, ScriptExecutionResult};
use fuel_types::{ContractId, Word};
#[derive(Debug)]
pub struct Backtrace {
call_stack: Vec<CallFrame>,
contract: ContractId,
registers: [Word; VM_REGISTER_COUNT],
memory: Vec<u8>,
result: ScriptExecutionResult,
tx: CheckedTransaction,
}
impl Backtrace {
pub fn from_vm_error<S>(vm: &Interpreter<S>, result: ScriptExecutionResult) -> Self {
let call_stack = vm.call_stack().to_owned();
let contract = vm.internal_contract_or_default();
let memory = vm.memory().to_owned();
let tx = vm.checked_transaction().clone();
let mut registers = [0; VM_REGISTER_COUNT];
registers.copy_from_slice(vm.registers());
Self {
call_stack,
contract,
registers,
memory,
result,
tx,
}
}
pub fn call_stack(&self) -> &[CallFrame] {
self.call_stack.as_slice()
}
pub const fn contract(&self) -> &ContractId {
&self.contract
}
pub const fn registers(&self) -> &[Word] {
&self.registers
}
pub fn memory(&self) -> &[u8] {
self.memory.as_slice()
}
pub const fn result(&self) -> &ScriptExecutionResult {
&self.result
}
pub const fn tx(&self) -> &CheckedTransaction {
&self.tx
}
pub fn into_inner(
self,
) -> (
Vec<CallFrame>,
ContractId,
[Word; VM_REGISTER_COUNT],
Vec<u8>,
ScriptExecutionResult,
CheckedTransaction,
) {
let Self {
call_stack,
contract,
registers,
memory,
result,
tx,
} = self;
(call_stack, contract, registers, memory, result, tx)
}
}