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
use super::*;
impl StorageManager {
/// Query storage with filters
pub fn query(&mut self, query: StorageQuery) -> Result<StorageEntries, RuntimeError> {
let mut results = Vec::new();
if let Some(account_storage) = self.storage.get(&query.account) {
// Collect from committed storage
for (key, value) in &account_storage.storage {
if let Some(ref prefix) = query.key_prefix {
if !key.starts_with(prefix) {
continue;
}
}
results.push((key.clone(), value.clone()));
}
// Include pending changes if requested
if query.include_pending {
for (key, change) in &account_storage.pending_changes {
if let Some(ref prefix) = query.key_prefix {
if !key.starts_with(prefix) {
continue;
}
}
match &change.change_type {
StorageChangeType::Delete => {
results.retain(|(k, _)| k != key);
}
_ => {
if let Some(ref new_value) = change.new_value {
// Remove old entry if exists and add new one
results.retain(|(k, _)| k != key);
results.push((key.clone(), new_value.clone()));
}
}
}
}
}
}
// Apply limit
if let Some(limit) = query.limit {
results.truncate(limit);
}
// Sort by key for consistent results
results.sort_by(|a, b| a.0.cmp(&b.0));
Ok(results)
}
/// Get storage root hash for account (Neo compatibility)
pub fn get_storage_root(&self, account: &str) -> Result<String, RuntimeError> {
if let Some(account_storage) = self.storage.get(account) {
// Calculate Merkle root of storage items
let mut items: Vec<_> = account_storage.storage.iter().collect();
items.sort_by_key(|(k, _)| *k);
let root_hash = self.calculate_merkle_root(&items);
Ok(hex::encode(root_hash))
} else {
Ok(hex::encode(self.empty_root_hash()))
}
}
}