forked from matter-labs/anvil-zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rs
189 lines (174 loc) · 6.34 KB
/
config.rs
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use zksync_web3_decl::error::Web3Error;
use crate::{
fork::ForkSource,
namespaces::{ConfigurationApiNamespaceT, Result},
node::InMemoryNode,
observability::LogLevel,
utils::into_jsrpc_error,
};
use super::{ShowCalls, ShowGasDetails, ShowStorageLogs, ShowVMDetails};
impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> ConfigurationApiNamespaceT
for InMemoryNode<S>
{
fn config_get_show_calls(&self) -> Result<String> {
self.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|reader| reader.show_calls.to_string())
}
fn config_get_current_timestamp(&self) -> Result<u64> {
self.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|reader| reader.current_timestamp)
}
fn config_set_show_calls(&self, value: String) -> Result<String> {
let show_calls = match value.parse::<ShowCalls>() {
Ok(value) => value,
Err(_) => return self.config_get_show_calls(),
};
self.get_inner()
.write()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|mut writer| {
writer.show_calls = show_calls;
writer.show_calls.to_string()
})
}
fn config_set_show_storage_logs(&self, value: String) -> Result<String> {
let show_storage_logs = match value.parse::<ShowStorageLogs>() {
Ok(value) => value,
Err(_) => {
return self
.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|reader| reader.show_storage_logs.to_string())
}
};
self.get_inner()
.write()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|mut writer| {
writer.show_storage_logs = show_storage_logs;
writer.show_storage_logs.to_string()
})
}
fn config_set_show_vm_details(&self, value: String) -> Result<String> {
let show_vm_details = match value.parse::<ShowVMDetails>() {
Ok(value) => value,
Err(_) => {
return self
.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|reader| reader.show_vm_details.to_string())
}
};
self.get_inner()
.write()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|mut writer| {
writer.show_vm_details = show_vm_details;
writer.show_vm_details.to_string()
})
}
fn config_set_show_gas_details(&self, value: String) -> Result<String> {
let show_gas_details = match value.parse::<ShowGasDetails>() {
Ok(value) => value,
Err(_) => {
return self
.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|reader| reader.show_gas_details.to_string())
}
};
self.get_inner()
.write()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|mut writer| {
writer.show_gas_details = show_gas_details;
writer.show_gas_details.to_string()
})
}
fn config_set_resolve_hashes(&self, value: bool) -> Result<bool> {
self.get_inner()
.write()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})
.map(|mut writer| {
writer.resolve_hashes = value;
writer.resolve_hashes
})
}
fn config_set_log_level(&self, level: LogLevel) -> Result<bool> {
if let Some(observability) = &self
.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})?
.observability
{
match observability.set_log_level(level.clone()) {
Ok(_) => tracing::info!("set log level to '{}'", level),
Err(err) => {
tracing::error!("failed setting log level {:?}", err);
return Ok(false);
}
}
}
Ok(true)
}
fn config_set_logging(&self, directive: String) -> Result<bool> {
if let Some(observability) = &self
.get_inner()
.read()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError)
})?
.observability
{
match observability.set_logging(&directive) {
Ok(_) => tracing::info!("set logging to '{}'", directive),
Err(err) => {
tracing::error!("failed setting logging to '{}': {:?}", directive, err);
return Ok(false);
}
}
}
Ok(true)
}
}