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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::backtrace::Backtrace;
use crate::state::StateTransitionRef;
use crate::storage::MemoryStorage;
use crate::transactor::Transactor;
use fuel_tx::{Checked, ConsensusParameters, Create, Receipt, Script};
#[derive(Default, Debug)]
pub struct MemoryClient {
transactor: Transactor<MemoryStorage, Script>,
}
impl AsRef<MemoryStorage> for MemoryClient {
fn as_ref(&self) -> &MemoryStorage {
self.transactor.as_ref()
}
}
impl AsMut<MemoryStorage> for MemoryClient {
fn as_mut(&mut self) -> &mut MemoryStorage {
self.transactor.as_mut()
}
}
impl MemoryClient {
pub fn new(storage: MemoryStorage, params: ConsensusParameters) -> Self {
Self {
transactor: Transactor::new(storage, params),
}
}
pub fn from_txtor(transactor: Transactor<MemoryStorage, Script>) -> Self {
Self { transactor }
}
pub fn backtrace(&self) -> Option<Backtrace> {
self.transactor.backtrace()
}
pub fn receipts(&self) -> Option<&[Receipt]> {
self.transactor.receipts()
}
pub fn state_transition(&self) -> Option<StateTransitionRef<'_, Script>> {
self.transactor.state_transition()
}
pub fn deploy(&mut self, tx: Checked<Create>) -> Option<Create> {
self.transactor.deploy(tx).ok()
}
pub fn transact(&mut self, tx: Checked<Script>) -> &[Receipt] {
self.transactor.transact(tx);
if let Ok(state) = self.transactor.result() {
if state.should_revert() {
self.transactor.as_mut().revert();
} else {
self.transactor.as_mut().commit();
}
} else {
self.transactor.as_mut().revert();
}
self.transactor.receipts().unwrap_or_default()
}
pub fn persist(&mut self) {
self.as_mut().persist();
}
pub const fn params(&self) -> &ConsensusParameters {
self.transactor.params()
}
pub const fn tx_offset(&self) -> usize {
self.transactor.tx_offset()
}
}
impl From<MemoryStorage> for MemoryClient {
fn from(s: MemoryStorage) -> Self {
Self::new(s, Default::default())
}
}
impl From<MemoryClient> for Transactor<MemoryStorage, Script> {
fn from(client: MemoryClient) -> Self {
client.transactor
}
}