This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
on_demand_ext.rs
231 lines (195 loc) · 4.99 KB
/
on_demand_ext.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
use std::collections::BTreeMap;
use sp_runtime::StorageChild;
use sp_state_machine::{Backend, StorageValue, OverlayedChanges, StorageTransactionCache};
use sp_storage::ChildInfo;
use crate::backend::HasherT;
pub struct OnDemandExternalities<H, B>
where
H: HasherT,
H::Out: codec::Codec + Ord,
{
/// The overlay changed storage.
overlay: OverlayedChanges,
storage_transaction_cache: StorageTransactionCache<<B as Backend<H>>::Transaction, H>,
/// Storage backend.
pub backend: B,
/// Extensions.
pub extensions: Extensions,
/// State version to use during tests.
pub state_version: StateVersion,
}
#[derive(Debug)]
pub struct RemoteExternalitiesBackendSimple {
rpc: substrate_rpc_client::WsClient,
top: BTreeMap<Vec<u8>, Vec<u8>>,
children: BTreeMap<Vec<u8>, StorageChild>,
}
impl RemoteExternalitiesBackendSimple {
pub fn new(rpc: substrate_rpc_client::WsClient) -> Self {
Self {
rpc,
top: Default::default(),
children: Default::default(),
}
}
}
impl<H: HasherT> Backend<H> for RemoteExternalitiesBackendSimple {
type Error = &'static str;
type Transaction = sp_trie::MemoryDB<H>;
type TrieBackendStorage = sp_trie::MemoryDB<H>;
fn storage(&self, key: &[u8]) -> Result<Option<StorageValue>, Self::Error> {
todo!();
}
/// Get keyed storage value hash or None if there is nothing associated.
fn storage_hash(&self, key: &[u8]) -> Result<Option<H::Out>, Self::Error> {
todo!();
}
/// Get keyed child storage or None if there is nothing associated.
fn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageValue>, Self::Error> {
todo!("check inner_backend, else call remote");
}
/// Get child keyed storage value hash or None if there is nothing associated.
fn child_storage_hash(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<H::Out>, Self::Error> {
todo!("check inner_backend, else call remote");
}
/// true if a key exists in storage.
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
todo!("check local, else check remote")
}
/// true if a key exists in child storage.
fn exists_child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<bool, Self::Error> {
todo!();
}
fn next_storage_key(&self, key: &[u8]) -> Result<Option<StorageKey>, Self::Error> {
todo!("check local, else check remote")
}
fn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageKey>, Self::Error> {
todo!("check local, else check remote")
}
fn apply_to_key_values_while<F: FnMut(Vec<u8>, Vec<u8>) -> bool>(
&self,
child_info: Option<&ChildInfo>,
prefix: Option<&[u8]>,
start_at: Option<&[u8]>,
f: F,
allow_missing: bool,
) -> Result<bool, Self::Error> {
unimplemented!()
}
fn apply_to_keys_while<F: FnMut(&[u8]) -> bool>(
&self,
child_info: Option<&ChildInfo>,
prefix: Option<&[u8]>,
start_at: Option<&[u8]>,
f: F,
) {
unimplemented!()
}
fn for_keys_with_prefix<F: FnMut(&[u8])>(&self, prefix: &[u8], mut f: F) {
todo!();
}
fn for_key_values_with_prefix<F: FnMut(&[u8], &[u8])>(&self, prefix: &[u8], f: F) {
unimplemented!()
}
fn for_child_keys_with_prefix<F: FnMut(&[u8])>(
&self,
child_info: &ChildInfo,
prefix: &[u8],
f: F,
) {
unimplemented!()
}
fn storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (H::Out, Self::Transaction)
where
H::Out: Ord,
{
todo!();
}
fn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (H::Out, bool, Self::Transaction)
where
H::Out: Ord,
{
todo!();
}
fn pairs(&self) -> Vec<(StorageKey, StorageValue)> {
todo!("oh boy");
}
fn keys(&self, prefix: &[u8]) -> Vec<StorageKey> {
todo!();
}
fn child_keys(&self, child_info: &ChildInfo, prefix: &[u8]) -> Vec<StorageKey> {
todo!();
}
fn full_storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
child_deltas: impl Iterator<
Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>),
>,
state_version: StateVersion,
) -> (H::Out, Self::Transaction)
where
H::Out: Ord + Encode,
{
todo!();
}
fn register_overlay_stats(&self, _stats: &StateMachineStats) {
todo!();
}
fn usage_info(&self) -> UsageInfo {
unimplemented!()
}
fn wipe(&self) -> Result<(), Self::Error> {
unimplemented!()
}
fn commit(
&self,
_: H::Out,
_: Self::Transaction,
_: StorageCollection,
_: ChildStorageCollection,
) -> Result<(), Self::Error> {
unimplemented!()
}
fn read_write_count(&self) -> (u32, u32, u32, u32) {
unimplemented!()
}
fn reset_read_write_count(&self) {
unimplemented!()
}
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
Default::default()
}
fn set_whitelist(&self, _: Vec<TrackedStorageKey>) {}
fn proof_size(&self) -> Option<u32> {
unimplemented!()
}
fn get_read_and_written_keys(&self) -> Vec<(Vec<u8>, u32, u32, bool)> {
unimplemented!()
}
}