Skip to content

Commit a231b5b

Browse files
committed
Implement Storage for PrefixedStorage and ReadonlyPrefixedStorage
1 parent d54e5f0 commit a231b5b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to
1111
- cosmwasm-std: Implement `Sub` and `SubAssign` for `Uint128`
1212
- cosmwasm-std: Implement custom events for contract execution results
1313
- cosmwasm-std: Add `CosmosMsg::Gov` for voting on governance proposals.
14+
- cosmwasm-storage: Implement `Storage` for `PrefixedStorage` and
15+
`ReadonlyPrefixedStorage`. NOTE: Calling `set` or `remove` on
16+
`ReadonlyPrefixedStorage` will panic!
1417

1518
### Removed
1619

packages/storage/src/prefixed_storage.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,25 @@ impl<'a> PrefixedStorage<'a> {
4141
prefix: to_length_prefixed_nested(namespaces),
4242
}
4343
}
44+
}
4445

45-
pub fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
46+
impl<'a> Storage for PrefixedStorage<'a> {
47+
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
4648
get_with_prefix(self.storage, &self.prefix, key)
4749
}
4850

49-
pub fn set(&mut self, key: &[u8], value: &[u8]) {
51+
fn set(&mut self, key: &[u8], value: &[u8]) {
5052
set_with_prefix(self.storage, &self.prefix, key, value);
5153
}
5254

53-
pub fn remove(&mut self, key: &[u8]) {
55+
fn remove(&mut self, key: &[u8]) {
5456
remove_with_prefix(self.storage, &self.prefix, key);
5557
}
5658

5759
#[cfg(feature = "iterator")]
5860
/// range allows iteration over a set of keys, either forwards or backwards
5961
/// uses standard rust range notation, and eg db.range(b"foo"..b"bar") also works reverse
60-
pub fn range<'b>(
62+
fn range<'b>(
6163
&'b self,
6264
start: Option<&[u8]>,
6365
end: Option<&[u8]>,
@@ -88,14 +90,24 @@ impl<'a> ReadonlyPrefixedStorage<'a> {
8890
prefix: to_length_prefixed_nested(namespaces),
8991
}
9092
}
93+
}
9194

92-
pub fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
95+
impl<'a> Storage for ReadonlyPrefixedStorage<'a> {
96+
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
9397
get_with_prefix(self.storage, &self.prefix, key)
9498
}
9599

100+
fn set(&mut self, _key: &[u8], _value: &[u8]) {
101+
unimplemented!();
102+
}
103+
104+
fn remove(&mut self, _key: &[u8]) {
105+
unimplemented!();
106+
}
107+
96108
#[cfg(feature = "iterator")]
97109
/// range allows iteration over a set of keys, either forwards or backwards
98-
pub fn range<'b>(
110+
fn range<'b>(
99111
&'b self,
100112
start: Option<&[u8]>,
101113
end: Option<&[u8]>,

0 commit comments

Comments
 (0)