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
use alloc::string::String;
use alloc::vec::Vec;
use miden_client::Word as NativeWord;
use miden_client::rpc::domain::storage_map::StorageMapInfo as NativeStorageMapInfo;
use wasm_bindgen::prelude::*;
use super::word::Word;
/// Information about storage map updates for an account, as returned by the
/// `syncStorageMaps` RPC endpoint.
///
/// Contains the list of storage map updates within the requested block range,
/// along with the chain tip and last processed block number.
#[wasm_bindgen(js_name = "StorageMapInfo")]
pub struct StorageMapInfo {
chain_tip: u32,
block_number: u32,
updates: Vec<StorageMapUpdate>,
}
#[wasm_bindgen(js_class = "StorageMapInfo")]
impl StorageMapInfo {
/// Returns the current chain tip block number.
#[wasm_bindgen(js_name = "chainTip")]
pub fn chain_tip(&self) -> u32 {
self.chain_tip
}
/// Returns the block number of the last check included in this response.
#[wasm_bindgen(js_name = "blockNumber")]
pub fn block_number(&self) -> u32 {
self.block_number
}
/// Returns the list of storage map updates.
pub fn updates(&self) -> Vec<StorageMapUpdate> {
self.updates.clone()
}
}
// STORAGE MAP UPDATE
// ================================================================================================
/// A single storage map update entry, containing the block number, slot name,
/// key, and new value.
#[derive(Clone)]
#[wasm_bindgen(js_name = "StorageMapUpdate")]
pub struct StorageMapUpdate {
block_num: u32,
slot_name: String,
key: Word,
value: Word,
}
#[wasm_bindgen(js_class = "StorageMapUpdate")]
impl StorageMapUpdate {
/// Returns the block number in which this update occurred.
#[wasm_bindgen(js_name = "blockNum")]
pub fn block_num(&self) -> u32 {
self.block_num
}
/// Returns the name of the storage slot that was updated.
#[wasm_bindgen(js_name = "slotName")]
pub fn slot_name(&self) -> String {
self.slot_name.clone()
}
/// Returns the storage map key that was updated.
pub fn key(&self) -> Word {
self.key.clone()
}
/// Returns the new value for this storage map key.
pub fn value(&self) -> Word {
self.value.clone()
}
}
// CONVERSIONS
// ================================================================================================
impl From<NativeStorageMapInfo> for StorageMapInfo {
fn from(native: NativeStorageMapInfo) -> Self {
let updates = native
.updates
.iter()
.map(|u| StorageMapUpdate {
block_num: u.block_num.as_u32(),
slot_name: u.slot_name.to_string(),
key: Word::from(NativeWord::from(u.key)),
value: Word::from(u.value),
})
.collect();
Self {
chain_tip: native.chain_tip.as_u32(),
block_number: native.block_number.as_u32(),
updates,
}
}
}