Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix separated contract ws docs path #471

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion contracts-ws/contracts/counter/examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub fn main() -> anyhow::Result<()> {
// ANCHOR_END: chain_construction

// ANCHOR: contract_interaction

let counter = CounterContract::new(chain);

// ANCHOR: clean_example
Expand Down
18 changes: 9 additions & 9 deletions docs/src/contracts/entry-points.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Contract execution and querying is so common that we felt the need to improve th
To get started, find the `ExecuteMsg` definition for your contract. In our case it's located in `counter/src/msg.rs`. Then add the following line to your `ExecuteMsg` enum:

```rust,ignore
{{#include ../../../contracts/counter/src/msg.rs:exec_msg}}
{{#include ../../../contracts-ws/contracts/counter/src/msg.rs:exec_msg}}
```

The functions are implemented as a trait named `ExecuteMsgFns` which is implemented on any interface that uses this `ExecuteMsg` as an entrypoint message.
Expand All @@ -17,15 +17,15 @@ Using the trait then becomes as simple as:

```rust,ignore
// in integration_tests.rs
{{#include ../../../contracts/counter/tests/integration_tests.rs:reset}}
{{#include ../../../contracts-ws/contracts/counter/tests/integration_tests.rs:reset}}
```

## Query

Generating query functions is a similar process but has the added advantage of using the `cosmwasm-schema` return tags to detect the query's return type. This allows for type-safe query functions!

```rust,ignore
{{#include ../../../contracts/counter/src/msg.rs:query_msg}}
{{#include ../../../contracts-ws/contracts/counter/src/msg.rs:query_msg}}
```

Keep in mind that you **NEED** to derive the `cosmwasm_schema::QueryResponses` trait on your QueryMsgs for the `QueryFns` macro to compile.
Expand All @@ -34,23 +34,23 @@ Using it is just as simple as the execution functions:

```rust,ignore
// in integration_tests.rs
{{#include ../../../contracts/counter/tests/integration_tests.rs:query}}
{{#include ../../../contracts-ws/contracts/counter/tests/integration_tests.rs:query}}
```

Just like the interface it can be beneficial to re-export the trait in your `lib.rs` or `interface.rs` file.

In the counter contract we re-export in `lib.rs`;

```rust,ignore
{{#include ../../../contracts/counter/src/lib.rs:fn_re_export}}
{{#include ../../../contracts-ws/contracts/counter/src/lib.rs:fn_re_export}}
```

### Async functions

In the case of queries, async functions get generated by the derive macro as well. These have the same arguments and return the same type as their synchronous counterparts, but are asynchronous and are suffixed with `_async`:

```rust,ignore
{{#include ../../../contracts/counter/examples/async.rs:full_async_example}}
{{#include ../../../contracts-ws/contracts/counter/examples/async.rs:full_async_example}}
```

## Additional Remarks on `QueryFns` and `ExecuteFns`
Expand Down Expand Up @@ -148,7 +148,7 @@ In general, every structure that implements the `Into` trait for the contract me

```rust,ignore
pub enum ExecuteMsg<T>{
{{#include ../../../contracts/mock_contract/src/lib.rs:into_example}}
{{#include ../../../contracts-ws/contracts/mock_contract/src/lib.rs:into_example}}
}

// Will produce:
Expand All @@ -160,7 +160,7 @@ fn second_message<T>(&self, t: impl Into<T>, funds: &[Coin]){}
By default the `ExecuteFns` and `QueryFns` derived traits will sort the fields of each enum member. For instance,

```rust,ignore
{{#include ../../../contracts/mock_contract/src/msg_tests.rs:ordered_msg_def}}
{{#include ../../../contracts-ws/contracts/mock_contract/src/msg_tests.rs:ordered_msg_def}}
```

will generate
Expand All @@ -174,7 +174,7 @@ By default the `ExecuteFns` and `QueryFns` derived traits will sort the fields o
You see in this example that the fields of the bar function are sorted lexicographically. We decided to put this behavior as default to prevent potential errors when rearranging the order of enum fields. If you don't want this behavior, you can disable it by using the `disable_fields_sorting` attribute. This is the resulting behavior:

```rust,ignore
{{#include ../../../contracts/mock_contract/src/msg_tests.rs:unordered_msg_def}}
{{#include ../../../contracts-ws/contracts/mock_contract/src/msg_tests.rs:unordered_msg_def}}


pub fn bar(b: u64, a: String) -> ...{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/contracts/integration-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ touch counter/tests/integration_tests.rs
Now we can write our tests. Here's an example of a test that deploys the contract, increments the counter and then resets it.

```rust,ignore
{{#include ../../../contracts/counter/tests/integration_tests.rs:all}}
{{#include ../../../contracts-ws/contracts/counter/tests/integration_tests.rs:all}}
```
8 changes: 4 additions & 4 deletions docs/src/contracts/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Interfaces are virtual wrappers around CosmWasm contracts. They allow you to int
Now that we have our filesystem and crate setup, we are able to create our contract interface using the `cw-orch::interface` macro. It allows you to create an interface for your contract without having to call it at the entry points, as well as the ability to specify the contract's source more easily.

```rust,ignore
{{#include ../../../contracts/counter/src/interface.rs:custom_interface}}
{{#include ../../../contracts-ws/contracts/counter/src/interface.rs:custom_interface}}
```

The use of the `interface` macro even allows you to have generic arguments in the message types. Any generics will be added to the interface under a `PhantomData` attribute.
Expand All @@ -21,7 +21,7 @@ It can be beneficial to re-export the structure in our `lib.rs` file.
In the counter contract we re-export in `lib.rs`;

```rust,ignore
{{#include ../../../contracts/counter/src/lib.rs:interface_reexport}}
{{#include ../../../contracts-ws/contracts/counter/src/lib.rs:interface_reexport}}
```

> **NOTE**: You can see that we have used the `artifacts_dir_from_workspace` macro inside the `wasm` trait function. This macro helps you locate the workspace `artifacts` folder. It actually looks for any directory named `artifacts` from the root of the current crate going up. For instance if the project is located in `/path1/path2/counter`, it will look for the artifacts folder inside the following directories in order and return as soon as it finds such a folder:
Expand All @@ -45,7 +45,7 @@ In the counter contract we re-export in `lib.rs`;
The `interface` macro implements a `new` function on the interface:

```rust,ignore
{{#include ../../../contracts/counter/tests/integration_tests.rs:constructor}}
{{#include ../../../contracts-ws/contracts/counter/tests/integration_tests.rs:constructor}}
```

The constructor takes one argument:
Expand Down Expand Up @@ -80,7 +80,7 @@ The environments that are currently supported are:
Generic functions can be executed over any environment. Setup functions are a good example of this.

```rust,ignore
{{#include ../../../contracts/counter/tests/integration_tests.rs:setup}}
{{#include ../../../contracts-ws/contracts/counter/tests/integration_tests.rs:setup}}
```

### Entry point function generation
Expand Down
4 changes: 2 additions & 2 deletions docs/src/contracts/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ With the setup done, we can start writing our script. Our initial plan is to dep
We start by creating the chain object for specifying we want to interact with a local juno instance:

```rust,ignore
{{#include ../../../contracts/counter/examples/deploy.rs:chain_construction}}
{{#include ../../../contracts-ws/contracts/counter/examples/deploy.rs:chain_construction}}
```

Then we can interact with our contract using that chain

```rust,ignore
{{#include ../../../contracts/counter/examples/deploy.rs:contract_interaction}}
{{#include ../../../contracts-ws/contracts/counter/examples/deploy.rs:contract_interaction}}
```

## Asynchronous Daemon
Expand Down
8 changes: 4 additions & 4 deletions docs/src/contracts/wasm-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ Import cw-orch without a worry, this won't include unnecessary dependencies and
The interface macro itself compiles to Wasm to empty traits. So this macro can be used anywhere in your contract. This **IS** smart-contract safe:

```rust,ignore
{{#include ../../../contracts/counter/src/interface.rs:interface_macro}}
{{#include ../../../contracts-ws/contracts/counter/src/interface.rs:interface_macro}}
```

However, the `Uploadable` traits implementation **IS NOT** safe for smart contracts and needs to import namely `cw-multi-test` elements that we don't remove from WASM compilation. The following code needs to be flagged to not be compiled inside Wasm contracts:

```rust,ignore
#[cfg(not(target_arch = "wasm32"))]
{{#include ../../../contracts/counter/src/interface.rs:uploadable_impl}}
{{#include ../../../contracts-ws/contracts/counter/src/interface.rs:uploadable_impl}}
```

### Entry Points

The entry points are easy to work with as they compile to empty traits inside Wasm. So you can define them, import and export them in your contract without having to care about compilation targets. Furthermore, those traits are optimized out when getting your contract ready to upload on a chain. The syntax use in the 2 following examples is WASM safe:

```rust,ignore
{{#include ../../../contracts/counter/src/msg.rs:exec_msg}}
{{#include ../../../contracts-ws/contracts/counter/src/msg.rs:exec_msg}}
```

```rust,ignore
{{#include ../../../contracts/counter/src/lib.rs:fn_re_export}}
{{#include ../../../contracts-ws/contracts/counter/src/lib.rs:fn_re_export}}
```
2 changes: 1 addition & 1 deletion docs/src/integrations/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,5 @@ For more information and queries, <a href="https://docs.rs/crate/cw-orch/latest/
Here is an example of a script that deploys the counter contract only after a specific block_height.

```rust,ignore
{{#include ../../../contracts/counter/src/interface.rs:daemon}}
{{#include ../../../contracts-ws/contracts/counter/src/interface.rs:daemon}}
```
2 changes: 1 addition & 1 deletion docs/src/setup/single-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Even if you include `cw-orch` in your dependencies here, it won't be included in
Now that we have our dependency set up, we can create the files that will contain our interface. We will create that interface in an `interface.rs` file inside the crate (`counter/src/interface.rs`). Then, we need to include that file inside our project. However, that file will contain multiple `cw-orch` elements that are not exposed when compiling your WASM. In order to prevent errors when compiling for Wasm, we will import our `interface.rs` file and target-flag it like so, in `counter/src/lib.rs`:

```rust,ignore
{{#include ../../../contracts/counter/src/lib.rs:custom_interface}}
{{#include ../../../contracts-ws/contracts/counter/src/lib.rs:custom_interface}}
```

In the next section, we will learn how to define the interface to be able to interact with an actual contract inside this `interface.rs` file.
Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/starship/src/client/faucet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Rust implementation for interacting with a faucet similar to https://github.com/cosmos/cosmjs/tree/main/packages/faucet
//! Rust implementation for interacting with a faucet similar to <https://github.com/cosmos/cosmjs/tree/main/packages/faucet>
use cosmwasm_std::Addr;
use serde::{Deserialize, Serialize};

Expand Down
Loading