diff --git a/docs-test-gen/Cargo.lock b/docs-test-gen/Cargo.lock index 04bd405b..39217022 100644 --- a/docs-test-gen/Cargo.lock +++ b/docs-test-gen/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" @@ -631,9 +631,9 @@ dependencies = [ [[package]] name = "cw-storey" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "913874fdcce32a7ce75de057960300ae19f73190934405ac6641b6a85556f62a" +checksum = "75c95d01bc7739e7e3f2f65fb648b31041039be2ece15cc5df7d81385c1324b8" dependencies = [ "cosmwasm-std", "rmp-serde", @@ -2487,26 +2487,39 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "storey" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89da67409154d8972ff07b90e563ccbfb902e4aff7d6bdc2e5c1471f5baa826a" +checksum = "0d69bfceca30a3167bf143721e652cd07f18b210e1a1957015d63442fcf86c1a" dependencies = [ "storey-encoding", + "storey-macros", "storey-storage", "thiserror 1.0.69", ] [[package]] name = "storey-encoding" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29845670645c9d3aa61a7419080040a5c7c098677c88fb12d7adb88aa8f94ad0" +checksum = "0ae285b61b9c173377d1beabac74f6d81e5dd49392d3f8f242652ad851bfd9fb" + +[[package]] +name = "storey-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5074cbcdcc77c9292212f31782e8dcd484762c20c32e7ab613cc5633473bd0d" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.90", +] [[package]] name = "storey-storage" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6a63ea9638817e9fa2f39d9c957bcdb9f3998b9cd9a8045025d35eefa6eb485" +checksum = "5315a91944be4b81d330bb69ebf992f786d2defeec062586f4266a6325c648fa" [[package]] name = "strsim" diff --git a/docs-test-gen/Cargo.toml b/docs-test-gen/Cargo.toml index 1931e31e..82fa747a 100644 --- a/docs-test-gen/Cargo.toml +++ b/docs-test-gen/Cargo.toml @@ -26,7 +26,7 @@ sha2 = "0.10.8" cosmos-sdk-proto = { version = "0.24.0", default-features = false } # Used in IBC code ibc = "0.54.0" # Used in IBC code serde = "*" -cw-storey = "*" schemars = "0.8.21" # Used in entrypoint example thiserror = "1.0.65" -storey = "*" +cw-storey = "0.5" +storey = "0.4" diff --git a/docs-test-gen/templates/ibc-packet.tpl b/docs-test-gen/templates/ibc-packet.tpl index e1471f48..c6e90181 100644 --- a/docs-test-gen/templates/ibc-packet.tpl +++ b/docs-test-gen/templates/ibc-packet.tpl @@ -38,7 +38,7 @@ fn doctest() { { use cw_storey::{containers::Item, CwStorage}; const CHANNEL: Item = Item::new(0); - CHANNEL.access(&mut CwStorage(&mut deps.storage)).set(&channel_info).unwrap(); + CHANNEL.access(&mut deps.storage).set(&channel_info).unwrap(); } diff --git a/package-lock.json b/package-lock.json index e1a8ea72..6645c8f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8170,6 +8170,21 @@ "type": "github", "url": "https://github.com/sponsors/wooorm" } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.2", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.2.tgz", + "integrity": "sha512-M0tBVNMEBJN2ZNQWlcekMn6pvLria7Sa2Fai5znm7CCJz4pP3lrvlSxhKdkCerk0D9E0bqx5yAo3o2Q7RrD4gA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/src/pages/ibc/diy-protocol/channel-lifecycle.mdx b/src/pages/ibc/diy-protocol/channel-lifecycle.mdx index a4354a68..18230baa 100644 --- a/src/pages/ibc/diy-protocol/channel-lifecycle.mdx +++ b/src/pages/ibc/diy-protocol/channel-lifecycle.mdx @@ -117,7 +117,7 @@ const IBC_APP_VERSION: &str = "my-protocol-v1"; ```rust filename="ibc.rs" template="core" -use cw_storey::{containers::Item, CwStorage}; +use cw_storey::containers::Item; /// enforces ordering and versioning constraints #[cfg_attr(not(feature = "library"), entry_point)] @@ -126,14 +126,12 @@ pub fn ibc_channel_open( env: Env, msg: IbcChannelOpenMsg, ) -> StdResult { - let mut storage = CwStorage(deps.storage); - let channel = msg.channel(); // in this example, we only allow a single channel per contract instance // you can do more complex checks here ensure!( - CHANNEL.access(&storage).get()?.is_none(), + CHANNEL.access(&mut *deps.storage).get()?.is_none(), StdError::generic_err("channel already exists") ); @@ -154,7 +152,7 @@ pub fn ibc_channel_open( // now, we save the channel ID to storage, so we can use it later // this also prevents any further channel openings - CHANNEL.access(&mut storage).set(&ChannelInfo { + CHANNEL.access(deps.storage).set(&ChannelInfo { channel_id: channel.endpoint.channel_id.clone(), finalized: false, })?; @@ -362,7 +360,7 @@ const CHANNEL: Item = Item::new("channel"); ```rust filename="ibc.rs" template="core" -use cw_storey::{containers::Item, CwStorage}; +use cw_storey::containers::Item; #[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_channel_connect( @@ -370,14 +368,12 @@ pub fn ibc_channel_connect( env: Env, msg: IbcChannelConnectMsg, ) -> StdResult { - let mut storage = CwStorage(deps.storage); - let channel = msg.channel(); // in this example, we only allow a single channel per contract instance // you can do more complex checks here let mut channel_info = CHANNEL - .access(&storage) + .access(&mut *deps.storage) .get()? .ok_or_else(|| StdError::generic_err("channel not found"))?; ensure!( @@ -391,7 +387,7 @@ pub fn ibc_channel_connect( // at this point, we are finished setting up the channel and can mark it as finalized channel_info.finalized = true; - CHANNEL.access(&mut storage).set(&channel_info)?; + CHANNEL.access(deps.storage).set(&channel_info)?; Ok(IbcBasicResponse::new()) } diff --git a/src/pages/ibc/diy-protocol/packet-lifecycle.mdx b/src/pages/ibc/diy-protocol/packet-lifecycle.mdx index f22f4111..75c8a273 100644 --- a/src/pages/ibc/diy-protocol/packet-lifecycle.mdx +++ b/src/pages/ibc/diy-protocol/packet-lifecycle.mdx @@ -56,12 +56,12 @@ Ok(Response::new().add_message(msg)) ```rust template="ibc-packet" -use cw_storey::{containers::Item, CwStorage}; +use cw_storey::containers::Item; const CHANNEL: Item = Item::new(0); let channel_id = CHANNEL - .access(&mut CwStorage(deps.storage)) + .access(deps.storage) .get()? .ok_or_else(|| StdError::generic_err("channel handshake hasn't started yet"))? .channel_id; @@ -222,7 +222,6 @@ const ACK_LATER: Map<&(u64, String), String> = Map::new("ack_later"); ```rust filename="ibc.rs" template="core" use cw_storey::containers::{Item, Map}; -use cw_storey::CwStorage; #[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_packet_receive( @@ -233,7 +232,7 @@ pub fn ibc_packet_receive( // save the data we need for the async acknowledgement in contract state // note: we are just saving a String here, but you can save any information // you need for the acknowledgement later - ACK_LATER.access(&mut CwStorage(deps.storage)) + ACK_LATER.access(deps.storage) .entry_mut(&msg.packet.sequence) .entry_mut(&msg.packet.dest.channel_id) .set(&"ack str".to_string())?; @@ -251,7 +250,7 @@ pub fn async_ack( channel_id: String, ) -> StdResult { // load data from contract state - let ack_str = ACK_LATER.access(&CwStorage(deps.storage)) + let ack_str = ACK_LATER.access(deps.storage) .entry(&packet_sequence) .entry(&channel_id) .try_get() diff --git a/src/pages/storey/containers.mdx b/src/pages/storey/containers.mdx index 384a91b8..3c2d38ce 100644 --- a/src/pages/storey/containers.mdx +++ b/src/pages/storey/containers.mdx @@ -53,16 +53,15 @@ reference to a storage backend. ```rust template="storage" use cw_storey::containers::Item; -use cw_storey::CwStorage; let item: Item = Item::new(0); -item.access(&mut CwStorage(&mut storage)) +item.access(&mut storage) .set(&42) .unwrap(); assert_eq!( - item.access(&CwStorage(&storage)) + item.access(&storage) .get() .unwrap(), Some(42) @@ -100,18 +99,17 @@ assert_eq!( ```rust template="storage" use cw_storey::containers::{Map, Item}; -use cw_storey::CwStorage; let map: Map>> = Map::new(0); -map.access(&mut CwStorage(&mut storage)) +map.access(&mut storage) .entry_mut("foo") .entry_mut("bar") .set(&42) .unwrap(); assert_eq!( - map.access(&CwStorage(&storage)) + map.access(&storage) .entry("foo") .entry("bar") .get() diff --git a/src/pages/storey/containers/column.mdx b/src/pages/storey/containers/column.mdx index a6510c97..4c13ab9c 100644 --- a/src/pages/storey/containers/column.mdx +++ b/src/pages/storey/containers/column.mdx @@ -24,43 +24,39 @@ This change will also break existing contracts that rely on the current `Column` Let's say you want to store a log of messages. You can do this with a `Column`. -```rust template="storage" showLineNumbers {6,8,10,12} +```rust template="storage" showLineNumbers {5,6,8,10} use cw_storey::containers::Column; -use cw_storey::CwStorage; const MESSAGES_IX: u8 = 1; let messages: Column = Column::new(MESSAGES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = messages.access(&mut cw_storage); +let mut access = messages.access(&mut storage); access.push(&"Hello, world!".to_string()).unwrap(); -assert_eq!(access.get(0).unwrap(), Some("Hello, world!".to_string())); +assert_eq!(access.get(1).unwrap(), Some("Hello, world!".to_string())); ``` -- _line 6:_ Here we construct the `Column` facade. The constructor takes a key, which is the prefix +- _line 5:_ Here we construct the `Column` facade. The constructor takes a key, which is the prefix of the keys in the underlying storage backend. -- _line 8:_ The [`access`] method returns a [`ColumnAccess`] entity, which allows manipulating the +- _line 6:_ The [`access`] method returns a [`ColumnAccess`] entity, which allows manipulating the column. -- _line 10:_ Here we push a message to the column. -- _line 12:_ We check that the message is stored correctly. +- _line 8:_ Here we push a message to the column. +- _line 10:_ We check that the message is stored correctly. #### Iterating over the messages As with [`Map`], we can iterate over all messages. -```rust template="storage" showLineNumbers {4, 17} +```rust template="storage" showLineNumbers {3, 15} use cw_storey::containers::{Column, Item}; -use cw_storey::CwStorage; use storey::containers::IterableAccessor as _; const MESSAGES_IX: u8 = 1; let messages: Column = Column::new(MESSAGES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = messages.access(&mut cw_storage); +let mut access = messages.access(&mut storage); // populate the column 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(); let messages: Vec<_> = access.pairs().collect::>().unwrap(); assert_eq!(messages, vec![ - (0, "Hello, world!".to_string()), - (1, "My name is Bob.".to_string()), - (2, "Hell is empty and all the devils are here.".to_string()), + (1, "Hello, world!".to_string()), + (2, "My name is Bob.".to_string()), + (3, "Hell is empty and all the devils are here.".to_string()), ]); ``` -- _line 4:_ We import the `IterableAccessor` trait to use iteration methods. -- _line 17:_ The `pairs` method produces an iterator over tuples of `(index, value)`. In this case, +- _line 3:_ We import the `IterableAccessor` trait to use iteration methods. +- _line 15:_ The `pairs` method produces an iterator over tuples of `(index, value)`. In this case, we collect the iterator into a `Vec` for ease of making our assertion later. 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 [`BoundedIterableAccessor`] trait, and the relevant methods are [`bounded_pairs`], [`bounded_keys`], and [`bounded_values`]. -The following example is the same as the previous one except for the bounds found in line 17, and +The following example is the same as the previous one except for the bounds found in line 16, and the limited results. @@ -100,28 +96,27 @@ bounds as suits you. -```rust template="storage" showLineNumbers {4, 17} -use cw_storey::containers::{Column, Item}; -use cw_storey::CwStorage; +```rust template="storage" showLineNumbers {4, 16} +use std::ops::Bound; +use cw_storey::containers::{Column, Item}; use storey::containers::BoundedIterableAccessor as _; const MESSAGES_IX: u8 = 1; let messages: Column = Column::new(MESSAGES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = messages.access(&mut cw_storage); +let mut access = messages.access(&mut storage); // populate the column access.push(&"Hello, world!".to_string()).unwrap(); access.push(&"My name is Bob.".to_string()).unwrap(); access.push(&"Hell is empty and all the devils are here.".to_string()).unwrap(); -let messages: Vec<_> = access.bounded_pairs(Some(0), Some(2)).collect::>().unwrap(); +let messages: Vec<_> = access.bounded_pairs(Bound::Included(1), Bound::Excluded(3)).collect::>().unwrap(); assert_eq!(messages, vec![ - (0, "Hello, world!".to_string()), - (1, "My name is Bob.".to_string()), + (1, "Hello, world!".to_string()), + (2, "My name is Bob.".to_string()), ]); ``` diff --git a/src/pages/storey/containers/item.mdx b/src/pages/storey/containers/item.mdx index 6f04efbf..c96927de 100644 --- a/src/pages/storey/containers/item.mdx +++ b/src/pages/storey/containers/item.mdx @@ -24,26 +24,24 @@ caller can be matched against this address in execution endpoints. Here's how to store and manipulate an admin address, or any other simple data. -```rust template="storage" showLineNumbers {5,9-12,14-16,19} +```rust template="storage" showLineNumbers {5,7-10,12-14,17} use cw_storey::containers::Item; -use cw_storey::CwStorage; const ADMIN_IX: u8 = 0; let admin: Item = Item::new(ADMIN_IX); -let mut cw_storage = CwStorage(&mut storage); assert_eq!( - admin.access(&cw_storage).get().unwrap(), + admin.access(&storage).get().unwrap(), None, ); -admin.access(&mut cw_storage) +admin.access(&mut storage) .set(&String::from("some_address")) .unwrap(); assert_eq!( - admin.access(&cw_storage).get().unwrap(), + admin.access(&storage).get().unwrap(), Some(String::from("some_address")), ); ``` @@ -51,19 +49,18 @@ assert_eq!( - _line 5:_ Here we construct the `Item` facade. The constructor takes a key, which is the key the data will be stored at in the underlying storage backend. See also [_Containers - Namespace_](.#namespace). -- _lines 9-12_: This assertion is just to show you the `Item` is empty (`Option::None`) before it's +- _lines 7-10_: This assertion is just to show you the `Item` is empty (`Option::None`) before it's initialized. -- _lines 14-16_: Here we commit a value to storage. -- _line 19_: Here we retrieve the value from storage. +- _lines 12-14_: Here we commit a value to storage. +- _line 17_: Here we retrieve the value from storage. ### Maintaining a config structure It's also common to save a whole struct in an `Item`, with a variety of data. Often the struct represents a contract's "config". -```rust template="storage" showLineNumbers {6} +```rust template="storage" showLineNumbers {5} use cw_storey::containers::Item; -use cw_storey::CwStorage; const CFG_IX: u8 = 0; @@ -74,8 +71,7 @@ struct Config { } let item: Item = Item::new(CFG_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = item.access(&mut cw_storage); +let mut access = item.access(&mut storage); let cfg = Config { admin: "some_address".to_string(), @@ -95,15 +91,13 @@ using the `cosmwasm_schema::cw_serde` macro we provide. Sometimes you might like to read a value, but expect to receive a default if it's never been initialized. This is a common pattern for counters or other numeric values. -```rust template="storage" showLineNumbers {10} +```rust template="storage" showLineNumbers {8} use cw_storey::containers::Item; -use cw_storey::CwStorage; const COUNTER_IX: u8 = 0; let counter: Item = Item::new(COUNTER_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = counter.access(&mut cw_storage); +let mut access = counter.access(&mut storage); let mut total = access.get().unwrap().unwrap_or(0); diff --git a/src/pages/storey/containers/map.mdx b/src/pages/storey/containers/map.mdx index ec70543e..cfd01eb9 100644 --- a/src/pages/storey/containers/map.mdx +++ b/src/pages/storey/containers/map.mdx @@ -18,15 +18,14 @@ Most commonly, you will use a `Map` to store a list of items. For example, the s Let's say you want to keep track of the balances of each user. You can do this with a `Map>`. -```rust template="storage" showLineNumbers {6,8,10,12,14} +```rust template="storage" showLineNumbers {6,7,9,11,13} use cw_storey::containers::{Item, Map}; use cw_storey::CwStorage; const BALANCES_IX: u8 = 0; let balances: Map> = Map::new(BALANCES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = balances.access(&mut cw_storage); +let mut access = balances.access(&mut storage); assert_eq!(access.entry("alice").get().unwrap(), None); @@ -37,12 +36,12 @@ assert_eq!(access.entry("alice").get().unwrap(), Some(Uint128::new(1000))); - _line 6:_ Here we construct the `Map` facade. The constructor takes a key, which is the prefix of the keys in the underlying storage backend. -- _line 8:_ The [`access`] method returns a [`MapAccess`] entity, which allows manipulating the map. -- _line 10:_ Here we try to access the balance of `alice`. Since she doesn't have one yet, it +- _line 7:_ The [`access`] method returns a [`MapAccess`] entity, which allows manipulating the map. +- _line 9:_ Here we try to access the balance of `alice`. Since she doesn't have one yet, it returns `None`. The [`entry`] method returns an [`ItemAccess`] entity, which allows manipulating the item stored under the key `alice`. -- _line 12:_ Here we set Alice's balance to `1000`. -- _line 14:_ We check that the balance is now `1000`. +- _line 11:_ Here we set Alice's balance to `1000`. +- _line 13:_ We check that the balance is now `1000`. #### Iterating over the balances @@ -63,7 +62,7 @@ Iterating over the balances is pretty straightforward. The [`keys`] method retur the keys, the [`values`] method returns an iterator over the values, and the [`pairs`] method returns an iterator over both. -```rust template="storage" showLineNumbers {4, 17, 19} +```rust template="storage" showLineNumbers {4, 16, 18} use cw_storey::containers::{Item, Map}; use cw_storey::CwStorage; @@ -72,8 +71,7 @@ use storey::containers::IterableAccessor as _; const BALANCES_IX: u8 = 1; let balances: Map> = Map::new(BALANCES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = balances.access(&mut cw_storage); +let mut access = balances.access(&mut storage); access.entry_mut("bob").set(&Uint128::new(500)).unwrap(); access.entry_mut("carol").set(&Uint128::new(1500)).unwrap(); @@ -100,8 +98,8 @@ assert_eq!( ``` - _line 4:_ Here we import the [`IterableAccessor`] trait. This trait provides unbounded iteration. -- _line 17:_ The `pairs` method returns an iterator over the key-value pairs. -- _line 19:_ Notice the key type is `(String, ())`. This is likely to become just `String` in the +- _line 16:_ The `pairs` method returns an iterator over the key-value pairs. +- _line 18:_ Notice the key type is `(String, ())`. This is likely to become just `String` in the future. For now, consider this a quirk of the design. This will make more sense once you get to composite maps. @@ -109,24 +107,23 @@ assert_eq!( Bounded iteration is also supported in many cases. -```rust template="storage" showLineNumbers {17} -use cw_storey::containers::{Item, Map}; -use cw_storey::CwStorage; +```rust template="storage" showLineNumbers {16} +use std::ops::Bound; +use cw_storey::containers::{Item, Map}; use storey::containers::BoundedIterableAccessor as _; const BALANCES_IX: u8 = 1; let balances: Map> = Map::new(BALANCES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = balances.access(&mut cw_storage); +let mut access = balances.access(&mut storage); access.entry_mut("bob").set(&Uint128::new(500)).unwrap(); access.entry_mut("carol").set(&Uint128::new(1500)).unwrap(); access.entry_mut("dave").set(&Uint128::new(2000)).unwrap(); assert_eq!( - access.bounded_pairs(Some("bob"), Some("dave")).collect::, _>>().unwrap(), + access.bounded_pairs(Bound::Included("bob"), Bound::Excluded("dave")).collect::, _>>().unwrap(), vec![(("bob".to_string(), ()), Uint128::new(500)), (("carol".to_string(), ()), Uint128::new(1500))] ); ``` @@ -142,15 +139,14 @@ lower bound and exclusive on the upper bound. In a future release (soon!) this w Alright, let's say this time you'd also like to keep track of the balances of each user, but each can have multiple different tokens. This is where composition comes in. -```rust template="storage" showLineNumbers {6, 10-14} +```rust template="storage" showLineNumbers {6, 9-13} use cw_storey::containers::{Item, Map}; use cw_storey::CwStorage; const BALANCES_IX: u8 = 0; let balances: Map>> = Map::new(BALANCES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = balances.access(&mut cw_storage); +let mut access = balances.access(&mut storage); access.entry_mut("alice").entry_mut("USDT").set(&Uint128::new(1000)).unwrap(); access.entry_mut("alice").entry_mut("OSMO").set(&Uint128::new(2000)).unwrap(); @@ -177,7 +173,7 @@ and the second one accesses a record in the inner map. Let's take a look at what iteration looks like with a composite map. -```rust template="storage" showLineNumbers {18, 27} +```rust template="storage" showLineNumbers {17, 26} use cw_storey::containers::{Item, Map}; use cw_storey::CwStorage; use cosmwasm_std::Order; @@ -187,8 +183,7 @@ use storey::containers::IterableAccessor as _; const BALANCES_IX: u8 = 1; let balances: Map>> = Map::new(BALANCES_IX); -let mut cw_storage = CwStorage(&mut storage); -let mut access = balances.access(&mut cw_storage); +let mut access = balances.access(&mut storage); access.entry_mut("alice").entry_mut("USDT").set(&1000).unwrap(); access.entry_mut("alice").entry_mut("OSMO").set(&2000).unwrap(); @@ -212,8 +207,8 @@ assert_eq!( Here we iterated twice, but each time we got a different view of the data. Each iteration was at a different level. -- _line 18:_ We call `pairs` on the outer map, which gives us all the entries. -- _line 27:_ We call `pairs` on the inner map under the key `alice`, which gives us all of Alice's +- _line 17:_ We call `pairs` on the outer map, which gives us all the entries. +- _line 26:_ We call `pairs` on the inner map under the key `alice`, which gives us all of Alice's balances. We can of course do the same with the `keys` and `values` methods. diff --git a/src/pages/storey/migration-plus.mdx b/src/pages/storey/migration-plus.mdx index 1fb3127c..6e0beb81 100644 --- a/src/pages/storey/migration-plus.mdx +++ b/src/pages/storey/migration-plus.mdx @@ -53,7 +53,6 @@ assert_eq!( ```rust template="storage" use cw_storey::containers::{Item, Map}; -use cw_storey::CwStorage; type Address = String; type Token = String; @@ -61,10 +60,9 @@ type Token = String; const BALANCES_IX: u8 = 1; let balances: Map>> = Map::new(BALANCES_IX); -let mut cw_storage = CwStorage(&mut storage); balances - .access(&mut cw_storage) + .access(&mut storage) .entry_mut("alice") .entry_mut("uusd") .set(&100) @@ -72,7 +70,7 @@ balances assert_eq!( balances - .access(&cw_storage) + .access(&storage) .entry("alice") .entry("uusd") .get() diff --git a/src/pages/sylvia/basics/contract-structure.mdx b/src/pages/sylvia/basics/contract-structure.mdx index 65adf1ca..4a2aec7b 100644 --- a/src/pages/sylvia/basics/contract-structure.mdx +++ b/src/pages/sylvia/basics/contract-structure.mdx @@ -40,7 +40,6 @@ Let's take a look at the behavior implementation. ```rust template="sylvia-empty" use cosmwasm_schema::cw_serde; -use cw_storey::CwStorage; use cw_storey::containers::Item; use sylvia::contract; use sylvia::cw_std::{Response, StdError, StdResult}; @@ -67,15 +66,14 @@ impl CounterContract { #[sv::msg(instantiate)] fn instantiate(&self, ctx: InstantiateCtx) -> StdResult { self.count - .access(&mut CwStorage(ctx.deps.storage)) + .access(ctx.deps.storage) .set(&0)?; Ok(Response::new()) } #[sv::msg(exec)] fn increment(&self, ctx: ExecCtx) -> StdResult { - let mut storage = CwStorage(ctx.deps.storage); - let mut accessor = self.count.access(&mut storage); + let mut accessor = self.count.access(ctx.deps.storage); let count = accessor .get()? .ok_or_else(|| StdError::generic_err("Count not instantiated yet"))?; @@ -88,7 +86,7 @@ impl CounterContract { fn count(&self, ctx: QueryCtx) -> StdResult { let count = self .count - .access(&CwStorage(ctx.deps.storage)) + .access(ctx.deps.storage) .get()? .ok_or_else(|| StdError::generic_err("Count not instantiated yet"))?; Ok(CountResponse { count }) diff --git a/src/pages/sylvia/basics/interoperability.mdx b/src/pages/sylvia/basics/interoperability.mdx index 97648d42..96c145b7 100644 --- a/src/pages/sylvia/basics/interoperability.mdx +++ b/src/pages/sylvia/basics/interoperability.mdx @@ -33,7 +33,7 @@ or fn external_increment(&self, ctx: ExecCtx) -> StdResult { let remote = self .remote - .access(&CwStorage(ctx.deps.storage)) + .access(ctx.deps.storage) .get()? .ok_or_else(|| StdError::generic_err("Remote not instantiated"))?; let msg = WasmMsg::Execute { @@ -96,7 +96,7 @@ impl ReplyContract { #[sv::msg(instantiate)] fn instantiate(&self, ctx: InstantiateCtx, remote_addr: Addr) -> StdResult { self.remote - .access(&mut CwStorage(ctx.deps.storage)) + .access(ctx.deps.storage) .set(&Remote::new(remote_addr))?; Ok(Response::new()) } @@ -105,7 +105,7 @@ impl ReplyContract { fn exec(&self, ctx: ExecCtx) -> StdResult { let sub_msg = self .remote - .access(&mut CwStorage(ctx.deps.storage)) + .access(ctx.deps.storage) .get()? .ok_or_else(|| StdError::generic_err("Remote not instantiated"))? .executor() @@ -194,7 +194,7 @@ method. We can access the fn external_count(&self, ctx: QueryCtx) -> StdResult { let remote = self .remote - .access(&CwStorage(ctx.deps.storage)) + .access(ctx.deps.storage) .get()? .ok_or_else(|| StdError::generic_err("Remote not instantiated"))?;