Skip to content

Commit

Permalink
Merge pull request #93 from scrtlabs/cosmwasm-std-v1.1.11
Browse files Browse the repository at this point in the history
cosmwasm-std v1.1.11
  • Loading branch information
toml01 authored Oct 18, 2023
2 parents 6880cc3 + 1fdd258 commit 9e139be
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 50 deletions.
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "LICENSE"
Expand Down Expand Up @@ -36,15 +36,15 @@ utils = ["secret-toolkit-utils"]
viewing-key = ["secret-toolkit-viewing-key"]

[dependencies]
secret-toolkit-crypto = { version = "0.9", path = "packages/crypto", optional = true }
secret-toolkit-incubator = { version = "0.9", path = "packages/incubator", optional = true }
secret-toolkit-permit = { version = "0.9", path = "packages/permit", optional = true }
secret-toolkit-serialization = { version = "0.9", path = "packages/serialization", optional = true }
secret-toolkit-snip20 = { version = "0.9", path = "packages/snip20", optional = true }
secret-toolkit-snip721 = { version = "0.9", path = "packages/snip721", optional = true }
secret-toolkit-storage = { version = "0.9", path = "packages/storage", optional = true }
secret-toolkit-utils = { version = "0.9", path = "packages/utils", optional = true }
secret-toolkit-viewing-key = { version = "0.9", path = "packages/viewing_key", optional = true }
secret-toolkit-crypto = { version = "0.10.0", path = "packages/crypto", optional = true }
secret-toolkit-incubator = { version = "0.10.0", path = "packages/incubator", optional = true }
secret-toolkit-permit = { version = "0.10.0", path = "packages/permit", optional = true }
secret-toolkit-serialization = { version = "0.10.0", path = "packages/serialization", optional = true }
secret-toolkit-snip20 = { version = "0.10.0", path = "packages/snip20", optional = true }
secret-toolkit-snip721 = { version = "0.10.0", path = "packages/snip721", optional = true }
secret-toolkit-storage = { version = "0.10.0", path = "packages/storage", optional = true }
secret-toolkit-utils = { version = "0.10.0", path = "packages/utils", optional = true }
secret-toolkit-viewing-key = { version = "0.10.0", path = "packages/viewing_key", optional = true }


[workspace]
Expand All @@ -57,7 +57,7 @@ members = ["packages/*"]
[workspace.dependencies]
schemars = { version = "0.8.11" }
serde = { version = "1.0" }
cosmwasm-std = { package = "secret-cosmwasm-std", version = "1.1.10", features = [
cosmwasm-std = { package = "secret-cosmwasm-std", version = "1.1.11", features = [
"random",
] }
cosmwasm-storage = { package = "secret-cosmwasm-storage", version = "1.1.10" }
cosmwasm-storage = { package = "secret-cosmwasm-storage", version = "1.1.11" }
19 changes: 19 additions & 0 deletions Releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

## Unreleased

## v0.10.0

### Features

- Bumped `cosmwasm-std` version to `v1.1.11` ([#93]).

### Breaking

- Added optional `admin` field to `utils::InitCallback::to_cosmos_msg` ([#93]).

### Bug fixes

- Only padding encrypted attributes in `utils::pad_handle_result` ([#92]).
- Support `backtraces` feature for `KeyMap` and `KeySet` ([#90]).

[#90]: https://github.com/scrtlabs/secret-toolkit/pull/90
[#92]: https://github.com/scrtlabs/secret-toolkit/pull/92
[#93]: https://github.com/scrtlabs/secret-toolkit/pull/93

## v0.9.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-crypto"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Add the following to your `cargo.toml` file:

```toml
[dependencies]
secret-toolkit = { version = "0.9.0", features = ["crypto"] }
secret-toolkit-crypto = { version = "0.9.0", features = ["hash", "rand", "ecc-secp256k1"] }
secret-toolkit = { version = "0.10.0", features = ["crypto"] }
secret-toolkit-crypto = { version = "0.10.0", features = ["hash", "rand", "ecc-secp256k1"] }
```

## Example usage
Expand Down
4 changes: 2 additions & 2 deletions packages/incubator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-incubator"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand All @@ -16,7 +16,7 @@ all-features = true
[dependencies]
serde = { workspace = true, optional = true }
cosmwasm-std = { workspace = true, optional = true }
secret-toolkit-serialization = { version = "0.9", path = "../serialization", optional = true }
secret-toolkit-serialization = { version = "0.10.0", path = "../serialization", optional = true }

[features]
generational-store = ["secret-toolkit-serialization", "serde", "cosmwasm-std"]
Expand Down
4 changes: 2 additions & 2 deletions packages/permit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-permit"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand All @@ -20,6 +20,6 @@ ripemd = { version = "0.1.3", default-features = false }
schemars = { workspace = true }
bech32 = "0.9.1"
remain = "0.2.8"
secret-toolkit-crypto = { version = "0.9.0", path = "../crypto", features = [
secret-toolkit-crypto = { version = "0.10.0", path = "../crypto", features = [
"hash",
] }
2 changes: 1 addition & 1 deletion packages/serialization/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-serialization"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand Down
4 changes: 2 additions & 2 deletions packages/snip20/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-snip20"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand All @@ -17,4 +17,4 @@ all-features = true
serde = { workspace = true }
schemars = { workspace = true }
cosmwasm-std = { workspace = true }
secret-toolkit-utils = { version = "0.9", path = "../utils" }
secret-toolkit-utils = { version = "0.10.0", path = "../utils" }
4 changes: 2 additions & 2 deletions packages/snip721/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-snip721"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand All @@ -17,4 +17,4 @@ all-features = true
serde = { workspace = true }
schemars = { workspace = true }
cosmwasm-std = { workspace = true }
secret-toolkit-utils = { version = "0.9", path = "../utils" }
secret-toolkit-utils = { version = "0.10.0", path = "../utils" }
4 changes: 2 additions & 2 deletions packages/storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-storage"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand All @@ -17,4 +17,4 @@ all-features = true
serde = { workspace = true }
cosmwasm-std = { workspace = true }
cosmwasm-storage = { workspace = true }
secret-toolkit-serialization = { version = "0.9", path = "../serialization" }
secret-toolkit-serialization = { version = "0.10.0", path = "../serialization" }
2 changes: 1 addition & 1 deletion packages/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-utils"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["SCRT Labs <[email protected]>"]
license-file = "../../LICENSE"
Expand Down
37 changes: 19 additions & 18 deletions packages/utils/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ elsewhere. There isn't an overarching theme for the items in this package.

## Calls module

This module contains traits used to call another contract. Do not forget to add the `use` statement for the traits you want.
This module contains traits used to call another contract. Do not forget to add the `use` statement for the traits you want.

```ignore
use secret_toolkit::utils::{InitCallback, HandleCallback};
Expand All @@ -23,7 +23,7 @@ Also, don't forget to add the toolkit dependency to your Cargo.toml

### Instantiating another contract

If you want to instantiate another contract, you should first copy/paste the InitMsg of that contract. For example, if you wanted to create an instance of the counter contract at <https://github.com/enigmampc/secret-template>
If you want to instantiate another contract, you should first copy/paste the InitMsg of that contract. For example, if you wanted to create an instance of the counter contract at <https://github.com/enigmampc/secret-template>

```rust
# use secret_toolkit_utils::InitCallback;
Expand All @@ -40,7 +40,7 @@ impl InitCallback for CounterInitMsg {
}
```

You would copy/paste its InitMsg, and rename it so that it does not conflict with the InitMsg you have defined for your own contract. Then you would implement the `InitCallback` trait as above, setting the BLOCK_SIZE constant to the size of the blocks you want your instantiation message padded to.
You would copy/paste its InitMsg, and rename it so that it does not conflict with the InitMsg you have defined for your own contract. Then you would implement the `InitCallback` trait as above, setting the BLOCK_SIZE constant to the size of the blocks you want your instantiation message padded to.

```rust
# use secret_toolkit_utils::InitCallback;
Expand All @@ -60,10 +60,11 @@ You would copy/paste its InitMsg, and rename it so that it does not conflict wit
# let response: StdResult<Response>;
#
let counter_init_msg = CounterInitMsg {
count: 100
count: 100
};

let cosmos_msg = counter_init_msg.to_cosmos_msg(
None,
"new_contract_label".to_string(),
123,
"CODE_HASH_OF_CONTRACT_YOU_WANT_TO_INSTANTIATE".to_string(),
Expand All @@ -74,11 +75,11 @@ response = Ok(Response::new().add_message(cosmos_msg));
# Ok::<(), StdError>(())
```

Next, in the init or handle function that will instantiate the other contract, you will create an instance of the CounterInitMsg, call its `to_cosmos_msg`, and place the resulting CosmosMsg in the `messages` Vec of the InitResponse or HandleResponse that your function is returning. In this example, we are pretending that the code id of the counter contract is 123. Also, in this example, you are not sending any SCRT with the InitMsg, but if you needed to send 1 SCRT, you would replace the None in the `to_cosmos_msg` call with `Some(Uint128(1000000))`. The amount sent is in uscrt. Any CosmosMsg placed in the `messages` Vec will be executed after your contract has finished its own processing.
Next, in the init or handle function that will instantiate the other contract, you will create an instance of the CounterInitMsg, call its `to_cosmos_msg`, and place the resulting CosmosMsg in the `messages` Vec of the InitResponse or HandleResponse that your function is returning. In this example, we are pretending that the code id of the counter contract is 123. Also, in this example, you are not sending any SCRT with the InitMsg, but if you needed to send 1 SCRT, you would replace the None in the `to_cosmos_msg` call with `Some(Uint128(1000000))`. The amount sent is in uscrt. Any CosmosMsg placed in the `messages` Vec will be executed after your contract has finished its own processing.

### Calling a handle function of another contract

You should first copy/paste the specific HandleMsg(s) you want to call. For example, if you wanted to reset the counter you instantiated above
You should first copy/paste the specific HandleMsg(s) you want to call. For example, if you wanted to reset the counter you instantiated above

```rust
# use secret_toolkit_utils::HandleCallback;
Expand All @@ -95,7 +96,7 @@ impl HandleCallback for CounterHandleMsg {
}
```

You would copy/paste the Reset variant of its HandleMsg enum, and rename the enum so that it does not conflict with the HandleMsg enum you have defined for your own contract. Then you would implement the `HandleCallback` trait as above, setting the BLOCK_SIZE constant to the size of the blocks you want your Reset message padded to. If you need to call multiple different Handle messages, even if they are to different contracts, you can include all the Handle messages as variants in the same enum (you can not have two variants with the same name within the same enum, though).
You would copy/paste the Reset variant of its HandleMsg enum, and rename the enum so that it does not conflict with the HandleMsg enum you have defined for your own contract. Then you would implement the `HandleCallback` trait as above, setting the BLOCK_SIZE constant to the size of the blocks you want your Reset message padded to. If you need to call multiple different Handle messages, even if they are to different contracts, you can include all the Handle messages as variants in the same enum (you can not have two variants with the same name within the same enum, though).

```rust
# use secret_toolkit_utils::HandleCallback;
Expand All @@ -107,7 +108,7 @@ You would copy/paste the Reset variant of its HandleMsg enum, and rename the enu
# pub enum CounterHandleMsg {
# Reset { count: i32 },
# }
#
#
# impl HandleCallback for CounterHandleMsg {
# const BLOCK_SIZE: usize = 256;
# }
Expand All @@ -128,11 +129,11 @@ response = Ok(Response::new().add_message(cosmos_msg));
# Ok::<(), StdError>(())
```

Next, in the init or handle function that will call the other contract, you will create an instance of the CounterHandleMsg::Reset variant, call its `to_cosmos_msg`, and place the resulting CosmosMsg in the `messages` Vec of the InitResponse or HandleResponse that your function is returning. In this example, you are not sending any SCRT with the Reset message, but if you needed to send 1 SCRT, you would replace the None in the `to_cosmos_msg` call with `Some(Uint128(1000000))`. The amount sent is in uscrt. Any CosmosMsg placed in the `messages` Vec will be executed after your contract has finished its own processing.
Next, in the init or handle function that will call the other contract, you will create an instance of the CounterHandleMsg::Reset variant, call its `to_cosmos_msg`, and place the resulting CosmosMsg in the `messages` Vec of the InitResponse or HandleResponse that your function is returning. In this example, you are not sending any SCRT with the Reset message, but if you needed to send 1 SCRT, you would replace the None in the `to_cosmos_msg` call with `Some(Uint128(1000000))`. The amount sent is in uscrt. Any CosmosMsg placed in the `messages` Vec will be executed after your contract has finished its own processing.

### Querying another contract

You should first copy/paste the specific QueryMsg(s) you want to call. For example, if you wanted to get the count of the counter you instantiated above
You should first copy/paste the specific QueryMsg(s) you want to call. For example, if you wanted to get the count of the counter you instantiated above

```rust
# use secret_toolkit_utils::Query;
Expand All @@ -150,7 +151,7 @@ impl Query for CounterQueryMsg {
}
```

You would copy/paste the GetCount variant of its QueryMsg enum, and rename the enum so that it does not conflict with the QueryMsg enum you have defined for your own contract. Then you would implement the `Query` trait as above, setting the BLOCK_SIZE constant to the size of the blocks you want your query message padded to. If you need to perform multiple different queries, even if they are to different contracts, you can include all the Query messages as variants in the same enum (you can not have two variants with the same name within the same enum, though).
You would copy/paste the GetCount variant of its QueryMsg enum, and rename the enum so that it does not conflict with the QueryMsg enum you have defined for your own contract. Then you would implement the `Query` trait as above, setting the BLOCK_SIZE constant to the size of the blocks you want your query message padded to. If you need to perform multiple different queries, even if they are to different contracts, you can include all the Query messages as variants in the same enum (you can not have two variants with the same name within the same enum, though).

```rust
# use secret_toolkit_utils::Query;
Expand All @@ -163,9 +164,9 @@ pub struct CountResponse {
}
```

Next, you will copy/paste the response of the query. If the other contract defines its response to the query with a struct, you are good to go.
Next, you will copy/paste the response of the query. If the other contract defines its response to the query with a struct, you are good to go.

If, however, the other contract returns an enum variant, one approach is to copy the fields of the variant and place them in a struct. Because an enum variant gets serialized with the name of the variant, you will then also want to create a wrapper struct whose only field has the name of the variant, and whose type is the struct you defined with the variant's fields. For example, if you wanted to do a token_info query of the [SNIP20 reference implementation](https://github.com/enigmampc/snip20-reference-impl), I would recommend using the SNIP20 toolkit function, but just for the sake of example, let's say you forgot that toolkit existed.
If, however, the other contract returns an enum variant, one approach is to copy the fields of the variant and place them in a struct. Because an enum variant gets serialized with the name of the variant, you will then also want to create a wrapper struct whose only field has the name of the variant, and whose type is the struct you defined with the variant's fields. For example, if you wanted to do a token_info query of the [SNIP20 reference implementation](https://github.com/enigmampc/snip20-reference-impl), I would recommend using the SNIP20 toolkit function, but just for the sake of example, let's say you forgot that toolkit existed.

```rust
# use secret_toolkit_utils::Query;
Expand All @@ -187,7 +188,7 @@ pub struct TokenInfoResponse {
}
```

You would copy the QueryAnswer::TokenInfo enum variant and create a TokenInfo struct with those fields. You should make all those fields public if you need to access them. Then you would create the TokenInfoResponse wrapper struct, which has only one field whose name is the name of the QueryAnswer variant in snake case (token_info). As a reminder, you only need to do this to properly deserialize the response if it was defined as an enum in the other contract.
You would copy the QueryAnswer::TokenInfo enum variant and create a TokenInfo struct with those fields. You should make all those fields public if you need to access them. Then you would create the TokenInfoResponse wrapper struct, which has only one field whose name is the name of the QueryAnswer variant in snake case (token_info). As a reminder, you only need to do this to properly deserialize the response if it was defined as an enum in the other contract.

Now to perform the query

Expand All @@ -202,7 +203,7 @@ Now to perform the query
# pub enum CounterQueryMsg {
# GetCount {},
# }
#
#
# impl Query for CounterQueryMsg {
# const BLOCK_SIZE: usize = 256;
# }
Expand All @@ -228,7 +229,7 @@ let count_response: StdResult<CountResponse> = get_count.query(
# Ok::<(), StdError>(())
```

You create an instance of the CounterQueryMsg::GetCount variant, and call its `query` function, returning its value to a variable of the response type. If you were doing a token_info query, you would write `let token_info_resp: TokenInfoResponse = ...`. You MUST use explicit type annotation here.
You create an instance of the CounterQueryMsg::GetCount variant, and call its `query` function, returning its value to a variable of the response type. If you were doing a token_info query, you would write `let token_info_resp: TokenInfoResponse = ...`. You MUST use explicit type annotation here.

## Feature Toggle

Expand Down Expand Up @@ -274,7 +275,7 @@ pub fn instantiate(
],
vec![info.sender], // Can put more than one pauser
)?;

Ok(Response::new())
}
```
Expand Down Expand Up @@ -327,7 +328,7 @@ fn redeem(
amount: Option<u128>,
) -> StdResult<Response> {
FeatureToggle::require_not_paused(deps.as_ref().storage, vec![Features::Redeem])?;

// Continue with function's operation
Ok(Response::new())
}
Expand Down
Loading

0 comments on commit 9e139be

Please sign in to comment.