Skip to content

Commit 9acc3c2

Browse files
authored
Provide a StorageVec datastructure (#1995)
Provide a vector like data structure, built on top of Mapping. This allows to retrieve elements from the vector and grow the vector without loading and pushing all elements.
1 parent e84a87c commit 9acc3c2

File tree

10 files changed

+957
-4
lines changed

10 files changed

+957
-4
lines changed

.config/cargo_spellcheck.dic

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,10 @@ payability
121121
unpayable
122122
initializer
123123
WebSocket/S
124+
StorageVec
125+
KiB
126+
GB
127+
BufferTooSmall
128+
KeyNotFound
129+
ink_env
130+
^

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Linter: `no_main` lint - [#2001](https://github.com/paritytech/ink/pull/2001)
1616
- Clean E2E configuration parsing - [#1922](https://github.com/paritytech/ink/pull/1922)
1717
- Make `set_code_hash` generic - [#1906](https://github.com/paritytech/ink/pull/1906)
18+
- Provide a `StorageVec` datastructure built on top of `Lazy` - [#1995](https://github.com/paritytech/ink/pull/1955)
1819

1920
### Changed
2021
- Messages return `TypeSpec` directly - #[1999](https://github.com/paritytech/ink/pull/1999)

crates/ink/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub mod storage {
5757
pub use ink_storage::{
5858
Lazy,
5959
Mapping,
60+
StorageVec,
6061
};
6162
}
6263

crates/storage/src/lazy/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
//! extra care has to be taken when operating directly on them.
2020
2121
mod mapping;
22+
mod vec;
2223

2324
#[doc(inline)]
2425
pub use self::mapping::Mapping;
26+
pub use self::vec::StorageVec;
2527

2628
use crate::traits::{
2729
AutoKey,
@@ -159,15 +161,15 @@ where
159161
let key_size = <Key as Storable>::encoded_size(&KeyType::KEY);
160162

161163
if key_size >= ink_env::BUFFER_SIZE {
162-
return Some(Err(ink_env::Error::BufferTooSmall))
164+
return Some(Err(ink_env::Error::BufferTooSmall));
163165
}
164166

165167
let value_size: usize = ink_env::contains_contract_storage(&KeyType::KEY)?
166168
.try_into()
167169
.expect("targets of less than 32bit pointer size are not supported; qed");
168170

169171
if key_size.saturating_add(value_size) > ink_env::BUFFER_SIZE {
170-
return Some(Err(ink_env::Error::BufferTooSmall))
172+
return Some(Err(ink_env::Error::BufferTooSmall));
171173
}
172174

173175
self.get().map(Ok)
@@ -191,7 +193,7 @@ where
191193
let value_size = <V as Storable>::encoded_size(value);
192194

193195
if key_size.saturating_add(value_size) > ink_env::BUFFER_SIZE {
194-
return Err(ink_env::Error::BufferTooSmall)
196+
return Err(ink_env::Error::BufferTooSmall);
195197
};
196198

197199
self.set(value);

0 commit comments

Comments
 (0)