Skip to content

Commit d70635d

Browse files
authored
Align examples with cw-storey 0.5 (#252)
2 parents 53d3675 + fd3d5dc commit d70635d

File tree

13 files changed

+118
-117
lines changed

13 files changed

+118
-117
lines changed

docs-test-gen/Cargo.lock

Lines changed: 22 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs-test-gen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sha2 = "0.10.8"
2626
cosmos-sdk-proto = { version = "0.24.0", default-features = false } # Used in IBC code
2727
ibc = "0.54.0" # Used in IBC code
2828
serde = "*"
29-
cw-storey = "*"
3029
schemars = "0.8.21" # Used in entrypoint example
3130
thiserror = "1.0.65"
31+
cw-storey = "*"
3232
storey = "*"

docs-test-gen/templates/ibc-packet.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn doctest() {
3838
{
3939
use cw_storey::{containers::Item, CwStorage};
4040
const CHANNEL: Item<ChannelInfo> = Item::new(0);
41-
CHANNEL.access(&mut CwStorage(&mut deps.storage)).set(&channel_info).unwrap();
41+
CHANNEL.access(&mut deps.storage).set(&channel_info).unwrap();
4242
}
4343

4444

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/ibc/diy-protocol/channel-lifecycle.mdx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const IBC_APP_VERSION: &str = "my-protocol-v1";
117117
<Tabs.Tab>
118118

119119
```rust filename="ibc.rs" template="core"
120-
use cw_storey::{containers::Item, CwStorage};
120+
use cw_storey::containers::Item;
121121

122122
/// enforces ordering and versioning constraints
123123
#[cfg_attr(not(feature = "library"), entry_point)]
@@ -126,14 +126,12 @@ pub fn ibc_channel_open(
126126
env: Env,
127127
msg: IbcChannelOpenMsg,
128128
) -> StdResult<IbcChannelOpenResponse> {
129-
let mut storage = CwStorage(deps.storage);
130-
131129
let channel = msg.channel();
132130

133131
// in this example, we only allow a single channel per contract instance
134132
// you can do more complex checks here
135133
ensure!(
136-
CHANNEL.access(&storage).get()?.is_none(),
134+
CHANNEL.access(&*deps.storage).get()?.is_none(),
137135
StdError::generic_err("channel already exists")
138136
);
139137

@@ -154,7 +152,7 @@ pub fn ibc_channel_open(
154152

155153
// now, we save the channel ID to storage, so we can use it later
156154
// this also prevents any further channel openings
157-
CHANNEL.access(&mut storage).set(&ChannelInfo {
155+
CHANNEL.access(deps.storage).set(&ChannelInfo {
158156
channel_id: channel.endpoint.channel_id.clone(),
159157
finalized: false,
160158
})?;
@@ -362,22 +360,20 @@ const CHANNEL: Item<ChannelInfo> = Item::new("channel");
362360
<Tabs.Tab>
363361

364362
```rust filename="ibc.rs" template="core"
365-
use cw_storey::{containers::Item, CwStorage};
363+
use cw_storey::containers::Item;
366364

367365
#[cfg_attr(not(feature = "library"), entry_point)]
368366
pub fn ibc_channel_connect(
369367
deps: DepsMut,
370368
env: Env,
371369
msg: IbcChannelConnectMsg,
372370
) -> StdResult<IbcBasicResponse> {
373-
let mut storage = CwStorage(deps.storage);
374-
375371
let channel = msg.channel();
376372

377373
// in this example, we only allow a single channel per contract instance
378374
// you can do more complex checks here
379375
let mut channel_info = CHANNEL
380-
.access(&storage)
376+
.access(&*deps.storage)
381377
.get()?
382378
.ok_or_else(|| StdError::generic_err("channel not found"))?;
383379
ensure!(
@@ -391,7 +387,7 @@ pub fn ibc_channel_connect(
391387

392388
// at this point, we are finished setting up the channel and can mark it as finalized
393389
channel_info.finalized = true;
394-
CHANNEL.access(&mut storage).set(&channel_info)?;
390+
CHANNEL.access(deps.storage).set(&channel_info)?;
395391

396392
Ok(IbcBasicResponse::new())
397393
}

src/pages/ibc/diy-protocol/packet-lifecycle.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ Ok(Response::new().add_message(msg))
5656
<Tabs.Tab>
5757

5858
```rust template="ibc-packet"
59-
use cw_storey::{containers::Item, CwStorage};
59+
use cw_storey::containers::Item;
6060

6161
const CHANNEL: Item<ChannelInfo> = Item::new(0);
6262

6363
let channel_id = CHANNEL
64-
.access(&mut CwStorage(deps.storage))
64+
.access(deps.storage)
6565
.get()?
6666
.ok_or_else(|| StdError::generic_err("channel handshake hasn't started yet"))?
6767
.channel_id;
@@ -222,7 +222,6 @@ const ACK_LATER: Map<&(u64, String), String> = Map::new("ack_later");
222222

223223
```rust filename="ibc.rs" template="core"
224224
use cw_storey::containers::{Item, Map};
225-
use cw_storey::CwStorage;
226225

227226
#[cfg_attr(not(feature = "library"), entry_point)]
228227
pub fn ibc_packet_receive(
@@ -233,7 +232,7 @@ pub fn ibc_packet_receive(
233232
// save the data we need for the async acknowledgement in contract state
234233
// note: we are just saving a String here, but you can save any information
235234
// you need for the acknowledgement later
236-
ACK_LATER.access(&mut CwStorage(deps.storage))
235+
ACK_LATER.access(deps.storage)
237236
.entry_mut(&msg.packet.sequence)
238237
.entry_mut(&msg.packet.dest.channel_id)
239238
.set(&"ack str".to_string())?;
@@ -251,7 +250,7 @@ pub fn async_ack(
251250
channel_id: String,
252251
) -> StdResult<Response> {
253252
// load data from contract state
254-
let ack_str = ACK_LATER.access(&CwStorage(deps.storage))
253+
let ack_str = ACK_LATER.access(deps.storage)
255254
.entry(&packet_sequence)
256255
.entry(&channel_id)
257256
.try_get()

src/pages/storey/containers.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ reference to a storage backend.
5353

5454
```rust template="storage"
5555
use cw_storey::containers::Item;
56-
use cw_storey::CwStorage;
5756

5857
let item: Item<u32> = Item::new(0);
5958

60-
item.access(&mut CwStorage(&mut storage))
59+
item.access(&mut storage)
6160
.set(&42)
6261
.unwrap();
6362

6463
assert_eq!(
65-
item.access(&CwStorage(&storage))
64+
item.access(&storage)
6665
.get()
6766
.unwrap(),
6867
Some(42)
@@ -100,18 +99,17 @@ assert_eq!(
10099

101100
```rust template="storage"
102101
use cw_storey::containers::{Map, Item};
103-
use cw_storey::CwStorage;
104102

105103
let map: Map<String, Map<String, Item<u32>>> = Map::new(0);
106104

107-
map.access(&mut CwStorage(&mut storage))
105+
map.access(&mut storage)
108106
.entry_mut("foo")
109107
.entry_mut("bar")
110108
.set(&42)
111109
.unwrap();
112110

113111
assert_eq!(
114-
map.access(&CwStorage(&storage))
112+
map.access(&storage)
115113
.entry("foo")
116114
.entry("bar")
117115
.get()

src/pages/storey/containers/column.mdx

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,39 @@ This change will also break existing contracts that rely on the current `Column`
2424

2525
Let's say you want to store a log of messages. You can do this with a `Column<String>`.
2626

27-
```rust template="storage" showLineNumbers {6,8,10,12}
27+
```rust template="storage" showLineNumbers {5,6,8,10}
2828
use cw_storey::containers::Column;
29-
use cw_storey::CwStorage;
3029

3130
const MESSAGES_IX: u8 = 1;
3231

3332
let messages: Column<String> = Column::new(MESSAGES_IX);
34-
let mut cw_storage = CwStorage(&mut storage);
35-
let mut access = messages.access(&mut cw_storage);
33+
let mut access = messages.access(&mut storage);
3634

3735
access.push(&"Hello, world!".to_string()).unwrap();
3836

39-
assert_eq!(access.get(0).unwrap(), Some("Hello, world!".to_string()));
37+
assert_eq!(access.get(1).unwrap(), Some("Hello, world!".to_string()));
4038
```
4139

42-
- _line 6:_ Here we construct the `Column` facade. The constructor takes a key, which is the prefix
40+
- _line 5:_ Here we construct the `Column` facade. The constructor takes a key, which is the prefix
4341
of the keys in the underlying storage backend.
44-
- _line 8:_ The [`access`] method returns a [`ColumnAccess`] entity, which allows manipulating the
42+
- _line 6:_ The [`access`] method returns a [`ColumnAccess`] entity, which allows manipulating the
4543
column.
46-
- _line 10:_ Here we push a message to the column.
47-
- _line 12:_ We check that the message is stored correctly.
44+
- _line 8:_ Here we push a message to the column.
45+
- _line 10:_ We check that the message is stored correctly.
4846

4947
#### Iterating over the messages
5048

5149
As with [`Map`], we can iterate over all messages.
5250

53-
```rust template="storage" showLineNumbers {4, 17}
51+
```rust template="storage" showLineNumbers {3, 15}
5452
use cw_storey::containers::{Column, Item};
55-
use cw_storey::CwStorage;
5653

5754
use storey::containers::IterableAccessor as _;
5855

5956
const MESSAGES_IX: u8 = 1;
6057

6158
let messages: Column<String> = Column::new(MESSAGES_IX);
62-
let mut cw_storage = CwStorage(&mut storage);
63-
let mut access = messages.access(&mut cw_storage);
59+
let mut access = messages.access(&mut storage);
6460

6561
// populate the column
6662
access.push(&"Hello, world!".to_string()).unwrap();
@@ -70,14 +66,14 @@ access.push(&"Hell is empty and all the devils are here.".to_string()).unwrap();
7066
let messages: Vec<_> = access.pairs().collect::<Result<_, _>>().unwrap();
7167

7268
assert_eq!(messages, vec![
73-
(0, "Hello, world!".to_string()),
74-
(1, "My name is Bob.".to_string()),
75-
(2, "Hell is empty and all the devils are here.".to_string()),
69+
(1, "Hello, world!".to_string()),
70+
(2, "My name is Bob.".to_string()),
71+
(3, "Hell is empty and all the devils are here.".to_string()),
7672
]);
7773
```
7874

79-
- _line 4:_ We import the `IterableAccessor` trait to use iteration methods.
80-
- _line 17:_ The `pairs` method produces an iterator over tuples of `(index, value)`. In this case,
75+
- _line 3:_ We import the `IterableAccessor` trait to use iteration methods.
76+
- _line 15:_ The `pairs` method produces an iterator over tuples of `(index, value)`. In this case,
8177
we collect the iterator into a `Vec` for ease of making our assertion later.
8278

8379
Similarly to [`Map`], you can use the [`keys`], [`values`], and [`pairs`] methods to iterate over
@@ -89,7 +85,7 @@ If you want to perform bounded iteration, it is possible. This time you need the
8985
[`BoundedIterableAccessor`] trait, and the relevant methods are [`bounded_pairs`], [`bounded_keys`],
9086
and [`bounded_values`].
9187

92-
The following example is the same as the previous one except for the bounds found in line 17, and
88+
The following example is the same as the previous one except for the bounds found in line 16, and
9389
the limited results.
9490

9591
<Callout>
@@ -100,28 +96,27 @@ bounds as suits you.
10096

10197
</Callout>
10298

103-
```rust template="storage" showLineNumbers {4, 17}
104-
use cw_storey::containers::{Column, Item};
105-
use cw_storey::CwStorage;
99+
```rust template="storage" showLineNumbers {4, 16}
100+
use std::ops::Bound;
106101

102+
use cw_storey::containers::{Column, Item};
107103
use storey::containers::BoundedIterableAccessor as _;
108104

109105
const MESSAGES_IX: u8 = 1;
110106

111107
let messages: Column<String> = Column::new(MESSAGES_IX);
112-
let mut cw_storage = CwStorage(&mut storage);
113-
let mut access = messages.access(&mut cw_storage);
108+
let mut access = messages.access(&mut storage);
114109

115110
// populate the column
116111
access.push(&"Hello, world!".to_string()).unwrap();
117112
access.push(&"My name is Bob.".to_string()).unwrap();
118113
access.push(&"Hell is empty and all the devils are here.".to_string()).unwrap();
119114

120-
let messages: Vec<_> = access.bounded_pairs(Some(0), Some(2)).collect::<Result<_, _>>().unwrap();
115+
let messages: Vec<_> = access.bounded_pairs(Bound::Included(1), Bound::Excluded(3)).collect::<Result<_, _>>().unwrap();
121116

122117
assert_eq!(messages, vec![
123-
(0, "Hello, world!".to_string()),
124-
(1, "My name is Bob.".to_string()),
118+
(1, "Hello, world!".to_string()),
119+
(2, "My name is Bob.".to_string()),
125120
]);
126121
```
127122

0 commit comments

Comments
 (0)