You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/storage/Readme.md
+17-24Lines changed: 17 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Secret Contract Development Toolkit - Storage Tools
2
2
3
-
⚠️ This package is a sub-package of the `secret-toolkit` package. Please see its crate page for more context. You need Rust 1.61+ to compile this package.
3
+
⚠️ This package is a sub-package of the `secret-toolkit` package. Please see its crate page for more context. You need Rust 1.63+ to compile this package.
4
4
5
5
This package contains many tools related to storage access patterns. This readme file assumes basic familiarity with basic cosmwasm storage, [click here to learn about this](https://docs.scrt.network/secret-network-documentation/development/secret-contracts/storage).
6
6
@@ -28,7 +28,7 @@ This is the simplest storage object in this toolkit. It based on the similarly n
28
28
29
29
#### **Initialize**
30
30
31
-
This object is meant to be initialized as a constant in `state.rs`. However, it would also work perfectly fine if it was initialized during run time with a variable key (in this case though, you'd have to remind it what type of object is stored and its serde). Import it using the following lines:
31
+
This object is meant to be initialized as a static constant in `state.rs`. However, it would also work perfectly fine if it was initialized during run time with a variable key (in this case though, you'd have to remind it what type of object is stored and its serde). Import it using the following lines:
32
32
33
33
```rust
34
34
usesecret_toolkit_storage::{Item}
@@ -37,7 +37,7 @@ use secret_toolkit_storage::{Item}
> ❗ Initializing the object as const instead of static will also work but be less efficient since the variable won't be able to cache length data.
109
+
108
110
Often times we need these storage objects to be associated to a user address or some other key that is variable. In this case, you need not initialize a completely new AppendStore inside `contract.rs`. Instead, you can create a new AppendStore by adding a suffix to an already existing AppendStore. This has the benefit of preventing you from having to rewrite the signature of the AppendStore. For example
> ❗ When using any iterators in any of the storage objects, the following will result in a compiling error.
137
-
138
-
```rust
139
-
letiterator=COUNT_STORE.iter(&deps.storage)?;
140
-
```
141
-
142
-
However, the follwoing will not result in an error:
143
-
144
-
```rust
145
-
letappend_store=COUNT_STORE
146
-
letiterator=append_store.iter(&deps.storage)?;
147
-
```
148
-
149
138
### **DequeStore**
150
139
151
140
This is a storage wrapper based on AppendStore that replicates a double ended list. This storage object allows the user to efficiently pop/push items to either end of the list.
152
141
153
142
#### **Init**
154
143
155
-
To import and intialize this storage object as a constant in `state.rs`, do the following:
144
+
To import and intialize this storage object as a static constant in `state.rs`, do the following:
> ❗ Initializing the object as const instead of static will also work but be less efficient since the variable won't be able to cache length data.
155
+
165
156
#### **Read/Write**
166
157
167
158
The main user facing methods to read/write to DequeStore are `pop_back`, `pop_front`, `push_back`, `push_front`, `get_len`, `get_off`, `set_at` (which replaces data at a position within the length bound), `clear` (which deletes all data in the storage), `remove` (which removes an item in an arbitrary position, this is very inefficient). An extensive list of examples of these being used can be found inside the unit tests of DequeStore found in `deque_store.rs`.
@@ -179,17 +170,19 @@ be returned in each page.
179
170
180
171
#### **Init**
181
172
182
-
To import and intialize this storage object as a constant in `state.rs`, do the following:
173
+
To import and intialize this storage object as a static constant in `state.rs`, do the following:
> ❗ Initializing the object as const instead of static will also work but be less efficient since the variable won't be able to cache length data.
185
+
193
186
You can use Json serde algorithm by changing the signature to `Keymap<HumanAddr, Uint128, Json>`, similar to all the other storage objects above. However, keep in mind that the Serde algorthm is used to serde both the stored object (`Uint128`) AND the key (`HumanAddr`).
194
187
195
188
If you need to associate a keymap to a user address (or any other variable), then you can also do this using the `.add_suffix` method.
0 commit comments