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
use crate::predicate::RuntimePredicate;
use fuel_asm::Word;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Context {
Predicate {
program: RuntimePredicate,
},
Script {
block_height: u32,
},
Call {
block_height: u32,
},
NotInitialized,
}
impl Default for Context {
fn default() -> Self {
Self::NotInitialized
}
}
impl Context {
pub const fn is_predicate(&self) -> bool {
matches!(self, Self::Predicate { .. })
}
pub const fn is_external(&self) -> bool {
matches!(self, Self::Predicate { .. } | Self::Script { .. })
}
pub const fn predicate(&self) -> Option<&RuntimePredicate> {
match self {
Context::Predicate { program } => Some(program),
_ => None,
}
}
pub const fn block_height(&self) -> Option<u32> {
match self {
Context::Script { block_height } | Context::Call { block_height } => Some(*block_height),
_ => None,
}
}
pub fn update_from_frame_pointer(&mut self, fp: Word) {
match self {
Context::Script { block_height } if fp != 0 => {
*self = Self::Call {
block_height: *block_height,
}
}
Context::Call { block_height } if fp == 0 => {
*self = Self::Script {
block_height: *block_height,
}
}
_ => (),
}
}
}