diff --git a/CHANGELOG.md b/CHANGELOG.md index ecdbf257a..5135a2c3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ [Full Changelog](https://github.com/CosmWasm/cw-plus/compare/v0.13.4...HEAD) +**Merged pull requests:** + +- Add ability to unset minter in UpdateMinter message. [\#748](https://github.com/CosmWasm/cw-plus/pull/748) ([ezekiiel](https://github.com/ezekiiel)) + ## [v0.13.4](https://github.com/CosmWasm/cw-plus/tree/v0.13.4) (2022-06-02) [Full Changelog](https://github.com/CosmWasm/cw-plus/compare/v0.13.3...v0.13.4) diff --git a/Cargo.lock b/Cargo.lock index 50cb5c562..011003963 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,12 +406,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-storage-macro" +version = "0.13.4" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus", + "serde", + "syn", +] + [[package]] name = "cw-storage-plus" version = "0.13.4" dependencies = [ "cosmwasm-std", "criterion", + "cw-storage-macro", "rand", "schemars", "serde", @@ -1023,11 +1034,11 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "proc-macro2" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1344,13 +1355,13 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.94" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1411,16 +1422,16 @@ dependencies = [ ] [[package]] -name = "unicode-width" -version = "0.1.9" +name = "unicode-ident" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] -name = "unicode-xid" -version = "0.2.3" +name = "unicode-width" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "version_check" diff --git a/README.md b/README.md index bcb3e607e..c32b553ca 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ many custom contracts. If you don't know what CosmWasm is, please check out [our homepage](https://cosmwasm.com) and [our documentation](https://docs.cosmwasm.com) to get more background. -We are running a [public testnet](https://github.com/CosmWasm/testnets/blob/master/sandynet-1/README.md) +We are running [public testnets](https://github.com/CosmWasm/testnets#running) you can use to test out any contracts. **Warning** None of these contracts have been audited and no liability is @@ -62,7 +62,7 @@ cleaner (before: `expires: {at_height: {height: 12345}}` after The most reusable components are the various cwXYZ specifications under `packages`. Each one defines a standard interface for different domains, e.g. [cw20](./packages/cw20/README.md) for fungible tokens, -[cw721](./packages/cw721/README.md) for non-fungible tokens, +[cw721](https://github.com/CosmWasm/cw-nfts/blob/main/packages/cw721/README.md) for non-fungible tokens, [cw1](./packages/cw1/README.md) for "proxy contracts", etc. The interface comes with a human description in the READMEs, as well as Rust types that can be imported. @@ -160,7 +160,7 @@ and depth of discussion can give an idea how much review was present. After that, fuzzing it (ideally with an intelligent fuzzer that understands the domain) can be valuable. And beyond that formal verification can provide even more assurance -(but is very time consuming and expensive). +(but is very time-consuming and expensive). ### Code Coverage @@ -213,7 +213,7 @@ relevant `Cargo.toml` file for clarity. All *specifications* will always be Apache-2.0. All contracts that are meant to be *building blocks* will also be Apache-2.0. This is along -the lines of Open Zepellin or other public references. +the lines of Open Zeppelin or other public references. Contracts that are "ready to deploy" may be licensed under AGPL 3.0 to encourage anyone using them to contribute back any improvements they diff --git a/contracts/cw20-base/src/contract.rs b/contracts/cw20-base/src/contract.rs index f7bd0e1f4..eeece2818 100644 --- a/contracts/cw20-base/src/contract.rs +++ b/contracts/cw20-base/src/contract.rs @@ -393,7 +393,7 @@ pub fn execute_update_minter( deps: DepsMut, _env: Env, info: MessageInfo, - new_minter: String, + new_minter: Option, ) -> Result { let mut config = TOKEN_INFO .may_load(deps.storage)? @@ -404,18 +404,27 @@ pub fn execute_update_minter( return Err(ContractError::Unauthorized {}); } - let minter = deps.api.addr_validate(&new_minter)?; - let minter_data = MinterData { - minter, - cap: mint.cap, - }; - config.mint = Some(minter_data); + let minter_data = new_minter + .map(|new_minter| deps.api.addr_validate(&new_minter)) + .transpose()? + .map(|minter| MinterData { + minter, + cap: mint.cap, + }); + + config.mint = minter_data; TOKEN_INFO.save(deps.storage, &config)?; Ok(Response::default() .add_attribute("action", "update_minter") - .add_attribute("new_minter", new_minter)) + .add_attribute( + "new_minter", + config + .mint + .map(|m| m.minter.into_string()) + .unwrap_or_else(|| "None".to_string()), + )) } pub fn execute_update_marketing( @@ -932,7 +941,7 @@ mod tests { let new_minter = "new_minter"; let msg = ExecuteMsg::UpdateMinter { - new_minter: new_minter.to_string(), + new_minter: Some(new_minter.to_string()), }; let info = mock_info(&minter, &[]); @@ -961,7 +970,7 @@ mod tests { ); let msg = ExecuteMsg::UpdateMinter { - new_minter: String::from("new_minter"), + new_minter: Some("new_minter".to_string()), }; let info = mock_info("not the minter", &[]); @@ -970,6 +979,43 @@ mod tests { assert_eq!(err, ContractError::Unauthorized {}); } + #[test] + fn unset_minter() { + let mut deps = mock_dependencies(); + let minter = String::from("minter"); + let cap = None; + do_instantiate_with_minter( + deps.as_mut(), + &String::from("genesis"), + Uint128::new(1234), + &minter, + cap, + ); + + let msg = ExecuteMsg::UpdateMinter { new_minter: None }; + + let info = mock_info(&minter, &[]); + let env = mock_env(); + let res = execute(deps.as_mut(), env.clone(), info, msg); + assert!(res.is_ok()); + let query_minter_msg = QueryMsg::Minter {}; + let res = query(deps.as_ref(), env, query_minter_msg); + let mint: Option = from_binary(&res.unwrap()).unwrap(); + + // Check that mint information was removed. + assert_eq!(mint, None); + + // Check that old minter can no longer mint. + let msg = ExecuteMsg::Mint { + recipient: String::from("lucky"), + amount: Uint128::new(222), + }; + let info = mock_info("minter", &[]); + let env = mock_env(); + let err = execute(deps.as_mut(), env, info, msg).unwrap_err(); + assert_eq!(err, ContractError::Unauthorized {}); + } + #[test] fn no_one_mints_if_minter_unset() { let mut deps = mock_dependencies(); diff --git a/packages/controllers/Cargo.toml b/packages/controllers/Cargo.toml index 0b3946cf9..8ae57c609 100644 --- a/packages/controllers/Cargo.toml +++ b/packages/controllers/Cargo.toml @@ -7,7 +7,6 @@ description = "Common controllers we can reuse in many contracts" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/controllers/src/claim.rs b/packages/controllers/src/claim.rs index 60025fce3..01083fecb 100644 --- a/packages/controllers/src/claim.rs +++ b/packages/controllers/src/claim.rs @@ -65,7 +65,7 @@ impl<'a> Claims<'a> { let mut to_send = Uint128::zero(); self.0.update(storage, addr, |claim| -> StdResult<_> { let (_send, waiting): (Vec<_>, _) = - claim.unwrap_or_default().iter().cloned().partition(|c| { + claim.unwrap_or_default().into_iter().partition(|c| { // if mature and we can pay fully, then include in _send if c.release_at.is_expired(block) { if let Some(limit) = cap { diff --git a/packages/cw1/Cargo.toml b/packages/cw1/Cargo.toml index e4506bcc9..7d53ca78b 100644 --- a/packages/cw1/Cargo.toml +++ b/packages/cw1/Cargo.toml @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-1 interface" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [dependencies] cosmwasm-std = { version = "1.0.0" } diff --git a/packages/cw1155/Cargo.toml b/packages/cw1155/Cargo.toml index d49acb9c6..14395ae23 100644 --- a/packages/cw1155/Cargo.toml +++ b/packages/cw1155/Cargo.toml @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-1155 interface" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [dependencies] cw-utils = { path = "../../packages/utils", version = "0.13.4" } diff --git a/packages/cw2/Cargo.toml b/packages/cw2/Cargo.toml index c240df878..955e3f33d 100644 --- a/packages/cw2/Cargo.toml +++ b/packages/cw2/Cargo.toml @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-2 interface" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [dependencies] cosmwasm-std = { version = "1.0.0", default-features = false } diff --git a/packages/cw20/Cargo.toml b/packages/cw20/Cargo.toml index 8a3181632..20bf00178 100644 --- a/packages/cw20/Cargo.toml +++ b/packages/cw20/Cargo.toml @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-20 interface" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [dependencies] cw-utils = { path = "../../packages/utils", version = "0.13.4" } diff --git a/packages/cw20/README.md b/packages/cw20/README.md index 970db35ff..f4705625b 100644 --- a/packages/cw20/README.md +++ b/packages/cw20/README.md @@ -128,6 +128,11 @@ minter address and handle updating the ACL there. this will create `amount` new tokens (updating total supply) and add them to the balance of `recipient`, as long as it does not exceed the cap. +`UpdateMinter { new_minter: Option }` - Callable only by the +current minter. If `new_minter` is `Some(address)` the minter is set +to the specified address, otherwise the minter is removed and no +future minters may be set. + ### Queries `Minter{}` - Returns who and how much can be minted. Return type is @@ -144,6 +149,14 @@ the minter is a smart contract. This should be enabled with all blockchains that have iterator support. It allows us to get lists of results with pagination. +### Queries + +`AllAllowances{owner, start_after, limit}` - Returns the list of all non-expired allowances +by the given owner. `start_after` and `limit` provide pagination. + +`AllAccounts{start_after, limit}` - Returns the list of all accounts that have been created on +the contract (just the addresses). `start_after` and `limit` provide pagination. + ## Marketing This allows us to attach more metadata on the token to help with displaying the token in @@ -173,11 +186,3 @@ account, this will update some marketing-related metadata on the contract. `DownloadLogo{}` - If the token's logo was previously uploaded to the blockchain (see `UploadLogo` message), then it returns the raw data to be displayed in a browser. Return type is `DownloadLogoResponse{ mime_type, data }`. - -### Queries - -`AllAllowances{owner, start_after, limit}` - Returns the list of all non-expired allowances -by the given owner. `start_after` and `limit` provide pagination. - -`AllAccounts{start_after, limit}` - Returns the list of all accounts that have been created on -the contract (just the addresses). `start_after` and `limit` provide pagination. diff --git a/packages/cw20/src/msg.rs b/packages/cw20/src/msg.rs index 4cd6fba63..f2f9708c9 100644 --- a/packages/cw20/src/msg.rs +++ b/packages/cw20/src/msg.rs @@ -55,8 +55,10 @@ pub enum Cw20ExecuteMsg { /// Only with the "mintable" extension. If authorized, creates amount new tokens /// and adds to the recipient balance. Mint { recipient: String, amount: Uint128 }, - /// Only with the "mintable" extension. The current minter may set a new minter. - UpdateMinter { new_minter: String }, + /// Only with the "mintable" extension. The current minter may set + /// a new minter. Setting the minter to None will remove the + /// token's minter forever. + UpdateMinter { new_minter: Option }, /// Only with the "marketing" extension. If authorized, updates marketing metadata. /// Setting None/null for any of these will leave it unchanged. /// Setting Some("") will clear this field on the contract storage diff --git a/packages/cw3/Cargo.toml b/packages/cw3/Cargo.toml index 7e585a17d..df3a42b97 100644 --- a/packages/cw3/Cargo.toml +++ b/packages/cw3/Cargo.toml @@ -7,7 +7,6 @@ description = "CosmWasm-3 Interface: On-Chain MultiSig/Voting contracts" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [dependencies] cw-utils = { path = "../../packages/utils", version = "0.13.4" } diff --git a/packages/cw4/Cargo.toml b/packages/cw4/Cargo.toml index ff6f996fa..800188a14 100644 --- a/packages/cw4/Cargo.toml +++ b/packages/cw4/Cargo.toml @@ -7,7 +7,6 @@ description = "CosmWasm-4 Interface: Groups Members" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [dependencies] cw-storage-plus = { path = "../storage-plus", version = "0.13.4" } diff --git a/packages/multi-test/Cargo.toml b/packages/multi-test/Cargo.toml index 8a059e042..bae48e06b 100644 --- a/packages/multi-test/Cargo.toml +++ b/packages/multi-test/Cargo.toml @@ -7,7 +7,6 @@ description = "Test helpers for multi-contract interactions" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] diff --git a/packages/storage-macro/Cargo.toml b/packages/storage-macro/Cargo.toml new file mode 100644 index 000000000..b29a59f10 --- /dev/null +++ b/packages/storage-macro/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "cw-storage-macro" +version = "0.13.4" +authors = ["yoisha <48324733+y-pakorn@users.noreply.github.com>"] +edition = "2018" +description = "Macro helpers for storage-plus" +license = "Apache-2.0" +repository = "https://github.com/CosmWasm/cw-plus" +homepage = "https://cosmwasm.com" +documentation = "https://docs.cosmwasm.com" + +[lib] +proc-macro = true + +[dependencies] +syn = { version = "1.0.96", features = ["full"] } + +[dev-dependencies] +cw-storage-plus = { version = "0.13.4", path = "../storage-plus" } +cosmwasm-std = { version = "1.0.0", default-features = false } +serde = { version = "1.0.103", default-features = false, features = ["derive"] } diff --git a/packages/storage-macro/NOTICE b/packages/storage-macro/NOTICE new file mode 100644 index 000000000..4ae1ccfe5 --- /dev/null +++ b/packages/storage-macro/NOTICE @@ -0,0 +1,14 @@ +CW-Storage-Macro: Macro helpers for storage-plus +Copyright (C) 2022 Confio GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/storage-macro/README.md b/packages/storage-macro/README.md new file mode 100644 index 000000000..d21d9f571 --- /dev/null +++ b/packages/storage-macro/README.md @@ -0,0 +1,22 @@ +# CW-Storage-Plus: Macro helpers for storage-plus + +Procedural macros helper for interacting with cw-storage-plus and cosmwasm-storage. + +## Current features + +Auto generate an `IndexList` impl for your indexes struct. + +```rust +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +struct TestStruct { + id: u64, + id2: u32, + addr: Addr, +} + +#[index_list(TestStruct)] // <- Add this line right here. +struct TestIndexes<'a> { + id: MultiIndex<'a, u32, TestStruct, u64>, + addr: UniqueIndex<'a, Addr, TestStruct>, +} +``` diff --git a/packages/storage-macro/src/lib.rs b/packages/storage-macro/src/lib.rs new file mode 100644 index 000000000..366723ca5 --- /dev/null +++ b/packages/storage-macro/src/lib.rs @@ -0,0 +1,37 @@ +use proc_macro::TokenStream; +use syn::{ + Ident, + __private::{quote::quote, Span}, + parse_macro_input, ItemStruct, +}; + +#[proc_macro_attribute] +pub fn index_list(attr: TokenStream, item: TokenStream) -> TokenStream { + let input = parse_macro_input!(item as ItemStruct); + + let ty = Ident::new(&attr.to_string(), Span::call_site()); + let struct_ty = input.ident.clone(); + + let names = input + .fields + .clone() + .into_iter() + .map(|e| { + let name = e.ident.unwrap(); + quote! { &self.#name } + }) + .collect::>(); + + let expanded = quote! { + #input + + impl cw_storage_plus::IndexList<#ty> for #struct_ty<'_> { + fn get_indexes(&'_ self) -> Box> + '_> { + let v: Vec<&dyn cw_storage_plus::Index<#ty>> = vec![#(#names),*]; + Box::new(v.into_iter()) + } + } + }; + + TokenStream::from(expanded) +} diff --git a/packages/storage-macro/tests/index_list.rs b/packages/storage-macro/tests/index_list.rs new file mode 100644 index 000000000..57eff5685 --- /dev/null +++ b/packages/storage-macro/tests/index_list.rs @@ -0,0 +1,76 @@ +#[cfg(test)] +mod test { + use cosmwasm_std::{testing::MockStorage, Addr}; + use cw_storage_macro::index_list; + use cw_storage_plus::{IndexedMap, MultiIndex, UniqueIndex}; + use serde::{Deserialize, Serialize}; + + #[test] + fn index_list_compiles() { + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] + struct TestStruct { + id: u64, + id2: u32, + addr: Addr, + } + + #[index_list(TestStruct)] + struct TestIndexes<'a> { + id: MultiIndex<'a, u32, TestStruct, u64>, + addr: UniqueIndex<'a, Addr, TestStruct>, + } + + let _: IndexedMap = IndexedMap::new( + "t", + TestIndexes { + id: MultiIndex::new(|t| t.id2, "t", "t_id2"), + addr: UniqueIndex::new(|t| t.addr.clone(), "t_addr"), + }, + ); + } + + #[test] + fn index_list_works() { + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] + struct TestStruct { + id: u64, + id2: u32, + addr: Addr, + } + + #[index_list(TestStruct)] + struct TestIndexes<'a> { + id: MultiIndex<'a, u32, TestStruct, u64>, + addr: UniqueIndex<'a, Addr, TestStruct>, + } + + let mut storage = MockStorage::new(); + let idm: IndexedMap = IndexedMap::new( + "t", + TestIndexes { + id: MultiIndex::new(|t| t.id2, "t", "t_2"), + addr: UniqueIndex::new(|t| t.addr.clone(), "t_addr"), + }, + ); + + idm.save( + &mut storage, + 0, + &TestStruct { + id: 0, + id2: 100, + addr: Addr::unchecked("1"), + }, + ) + .unwrap(); + + assert_eq!( + idm.load(&storage, 0).unwrap(), + TestStruct { + id: 0, + id2: 100, + addr: Addr::unchecked("1"), + } + ); + } +} diff --git a/packages/storage-plus/Cargo.toml b/packages/storage-plus/Cargo.toml index 33bff7c05..524890ef1 100644 --- a/packages/storage-plus/Cargo.toml +++ b/packages/storage-plus/Cargo.toml @@ -7,11 +7,11 @@ description = "Enhanced storage engines" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" [features] default = ["iterator"] iterator = ["cosmwasm-std/iterator"] +macro = ["cw-storage-macro"] [lib] # See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options @@ -21,6 +21,7 @@ bench = false cosmwasm-std = { version = "1.0.0", default-features = false } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } +cw-storage-macro = { version = "0.13.4", optional = true, path = "../storage-macro" } [dev-dependencies] criterion = { version = "0.3", features = [ "html_reports" ] } diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 55d572958..ca2ba8b78 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -277,8 +277,8 @@ where mod test { use super::*; - use crate::indexes::index_string_tuple; - use crate::{index_tuple, MultiIndex, UniqueIndex}; + use crate::indexes::test::{index_string_tuple, index_tuple}; + use crate::{MultiIndex, UniqueIndex}; use cosmwasm_std::testing::MockStorage; use cosmwasm_std::{MemoryStorage, Order}; use serde::{Deserialize, Serialize}; diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 2b152abb3..89987551e 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -302,8 +302,8 @@ where mod test { use super::*; - use crate::indexes::index_string_tuple; - use crate::{index_tuple, Index, MultiIndex, UniqueIndex}; + use crate::indexes::test::{index_string_tuple, index_tuple}; + use crate::{Index, MultiIndex, UniqueIndex}; use cosmwasm_std::testing::MockStorage; use cosmwasm_std::{MemoryStorage, Order}; use serde::{Deserialize, Serialize}; diff --git a/packages/storage-plus/src/indexes/mod.rs b/packages/storage-plus/src/indexes/mod.rs index ad7e8b46a..e2639ac83 100644 --- a/packages/storage-plus/src/indexes/mod.rs +++ b/packages/storage-plus/src/indexes/mod.rs @@ -11,22 +11,6 @@ use serde::Serialize; use cosmwasm_std::{StdResult, Storage}; -pub fn index_string(data: &str) -> Vec { - data.as_bytes().to_vec() -} - -pub fn index_tuple(name: &str, age: u32) -> (Vec, u32) { - (index_string(name), age) -} - -pub fn index_triple(name: &str, age: u32, pk: Vec) -> (Vec, u32, Vec) { - (index_string(name), age, pk) -} - -pub fn index_string_tuple(data1: &str, data2: &str) -> (Vec, Vec) { - (index_string(data1), index_string(data2)) -} - // Note: we cannot store traits with generic functions inside `Box`, // so I pull S: Storage to a top-level pub trait Index @@ -36,3 +20,19 @@ where fn save(&self, store: &mut dyn Storage, pk: &[u8], data: &T) -> StdResult<()>; fn remove(&self, store: &mut dyn Storage, pk: &[u8], old_data: &T) -> StdResult<()>; } + +#[cfg(test)] +pub mod test { + + pub fn index_string(data: &str) -> Vec { + data.as_bytes().to_vec() + } + + pub fn index_tuple(name: &str, age: u32) -> (Vec, u32) { + (index_string(name), age) + } + + pub fn index_string_tuple(data1: &str, data2: &str) -> (Vec, Vec) { + (index_string(data1), index_string(data2)) + } +} diff --git a/packages/storage-plus/src/lib.rs b/packages/storage-plus/src/lib.rs index 7035d9a25..d6f93efb3 100644 --- a/packages/storage-plus/src/lib.rs +++ b/packages/storage-plus/src/lib.rs @@ -25,11 +25,11 @@ pub use indexed_map::{IndexList, IndexedMap}; #[cfg(feature = "iterator")] pub use indexed_snapshot::IndexedSnapshotMap; #[cfg(feature = "iterator")] +pub use indexes::Index; +#[cfg(feature = "iterator")] pub use indexes::MultiIndex; #[cfg(feature = "iterator")] pub use indexes::UniqueIndex; -#[cfg(feature = "iterator")] -pub use indexes::{index_string, index_string_tuple, index_triple, index_tuple, Index}; pub use int_key::CwIntKey; pub use item::Item; pub use keys::{Key, Prefixer, PrimaryKey}; @@ -40,3 +40,10 @@ pub use path::Path; pub use prefix::{range_with_prefix, Prefix}; #[cfg(feature = "iterator")] pub use snapshot::{SnapshotItem, SnapshotMap, Strategy}; + +#[cfg(all(feature = "iterator", feature = "macro"))] +#[macro_use] +extern crate cw_storage_macro; +#[cfg(all(feature = "iterator", feature = "macro"))] +#[doc(hidden)] +pub use cw_storage_macro::*; diff --git a/packages/utils/Cargo.toml b/packages/utils/Cargo.toml index b31548e02..8817637d6 100644 --- a/packages/utils/Cargo.toml +++ b/packages/utils/Cargo.toml @@ -7,7 +7,6 @@ description = "Common helpers for other cw specs" license = "Apache-2.0" repository = "https://github.com/CosmWasm/cw-plus" homepage = "https://cosmwasm.com" -documentation = "https://docs.cosmwasm.com" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html