Skip to content

Commit 73d3cf9

Browse files
anistarkKayanskiCyberHoward
authored
Removed feature interface from docs (#346)
* removed feature interface from docs * readded removed code * Quick start * Added entry points * Scripting fix * Added wams compilation help, last feature remove, remove runtime handle * Update the diff and versions where this is available * Update docs/src/contracts/wasm-compilation.md Co-authored-by: CyberHoward <[email protected]> * Nits --------- Co-authored-by: Kayanski <[email protected]> Co-authored-by: Kayanski <[email protected]> Co-authored-by: CyberHoward <[email protected]>
1 parent b8ceade commit 73d3cf9

File tree

14 files changed

+90
-106
lines changed

14 files changed

+90
-106
lines changed

contracts/counter/src/interface.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
66

77
pub const CONTRACT_ID: &str = "counter_contract";
88

9+
// ANCHOR: interface_macro
910
#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg, id = CONTRACT_ID)]
1011
pub struct CounterContract;
12+
// ANCHOR_END: interface_macro
1113

14+
// ANCHOR: uploadable_impl
1215
impl<Chain: CwEnv> Uploadable for CounterContract<Chain> {
1316
/// Return the path to the wasm file corresponding to the contract
1417
fn wasm(&self) -> WasmPath {
@@ -28,6 +31,7 @@ impl<Chain: CwEnv> Uploadable for CounterContract<Chain> {
2831
)
2932
}
3033
}
34+
// ANCHOR_END: uploadable_impl
3135
// ANCHOR_END: custom_interface
3236

3337
use cw_orch::anyhow::Result;

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Environment Vars](./contracts/env-variable.md)
1313
- [Scripting](./contracts/scripting.md)
1414
- [Integration Tests](./contracts/integration-tests.md)
15+
- [Wasm Compilation](./contracts/wasm-compilation.md)
1516

1617
- [Project Setup](./setup/index.md)
1718
- [Single Contract](./setup/single-contract.md)

docs/src/contracts/entry-points.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ To get started, find the `ExecuteMsg` definition for your contract. In our case
1111
{{#include ../../../contracts/counter/src/msg.rs:exec_msg}}
1212
```
1313

14-
Again we feature flag the function generation to prevent cw-orchestrator entering as a dependency when building your contract.
15-
1614
The functions are implemented as a trait named `ExecuteMsgFns` which is implemented on any interface that uses this `ExecuteMsg` as an entrypoint message.
1715

1816
Using the trait then becomes as simple as:
@@ -30,6 +28,8 @@ Generating query functions is a similar process but has the added advantage of u
3028
{{#include ../../../contracts/counter/src/msg.rs:query_msg}}
3129
```
3230

31+
Keep in mind that you **NEED** to derive the `cosmwasm_schema::QueryResponses` trait on your QueryMsgs for the `QueryFns` macro to compile.
32+
3333
Using it is just as simple as the execution functions:
3434

3535
```rust,ignore

docs/src/contracts/env-variable.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can provide mnemonics directly to the `Daemon` using the following environme
2121
Optional, accepted values: Path to a valid file
2222
Default value: `~./cw-orchestrator/state.json`
2323

24-
This environment variable indicates the location of the state file that `cw-orch` will use to save on-chain state (addresses and code ids). Here is the behavior of this env variable :
24+
This environment variable indicates the location of the state file that `cw-orch` will use to save on-chain state (addresses and code ids). Here is the behavior of this env variable:
2525

2626
- `folder/file.json` will resolve to `~/.cw-orchestrator/folder/file.json`
2727
- `./folder/file.json` will resolve `$pwd/folder/file.json`
@@ -33,7 +33,7 @@ This environment variable indicates the location of the state file that `cw-orch
3333
Optional, accepted values: Path to a valid directory
3434

3535
Path where the wasms will be fetched. This is used by `ArtifactsDir::env()` inside the code.
36-
This is used in case you are using different tools than what is produced by <a href="https://github.com/CosmWasm/rust-optimizer" target="_blank">rust-optimizer</a>. Prefer using the following macro if you are using `wasm`s produced by `rust-optimizer` :
36+
This is used in case you are using different tools than what is produced by <a href="https://github.com/CosmWasm/rust-optimizer" target="_blank">rust-optimizer</a>. Prefer using the following macro if you are using `wasm`s produced by `rust-optimizer`:
3737

3838
```rust,ignore
3939
artifacts_dir_from_workspace!()
@@ -85,7 +85,7 @@ Defaults to `false`
8585

8686
Some actions require user-intervention. If set to true, this disables those interventions. Useful when working in scripts that can't handle user-intervention.
8787

88-
Supported actions :
88+
Supported actions:
8989

9090
- Balance checks. When set to `true`, if the gas token balance is too low to submit a transaction, it will error. See [Disable balance assertion](#cw_orch_disable_wallet_balance_assertion).
9191
- Deployment checks. When set to `true`, if no deployment file is detected when deploying a structure using the `Deploy::multi_deploy` function, it will deploy to all provided chains without asking for approval.
@@ -94,18 +94,18 @@ Supported actions :
9494

9595
### RUST_LOG
9696

97-
Optional, accepted values : `debug`, `error`, `info`, `warn`, `trace`
97+
Optional, accepted values: `debug`, `error`, `info`, `warn`, `trace`
9898

9999
`RUST_LOG` defines the Log level for the application. This is actually a `Rust` flag that we use inside `cw-orch`. If working with this environment variable, don't forget to also initialize a logger at the beginning of you application to be able to see the output. You can work with <a href="https://crates.io/crates/pretty_env_logger/" target="_blank">pretty_env_logger</a> for instance.
100100

101101
### CW_ORCH_SERIALIZE_JSON
102102

103-
Optional, accepted values : `false`, `true`
103+
Optional, accepted values: `false`, `true`
104104

105105
If equals to `true`, in the output logs, cw-orch will serialize the contract messages (instantiate, execute, query,... ) as JSON. This replaces the standard Rust Debug formatting and allows for easy copying and sharing of the executed messages.
106106

107107
### CW_ORCH_DISABLE_LOGS_ACTIVATION_MESSAGE
108108

109-
Optional, accepted values : `false`, `true`
109+
Optional, accepted values: `false`, `true`
110110

111111
By default if the logs are not enabled, `cw-orch` wil print a warning message to invite users to activate the logging capabilities of cw-orch. if equals to `true`, this env variable disables the warning message.

docs/src/contracts/interfaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Interfaces are virtual wrappers around CosmWasm contracts. They allow you to int
44

55
> **Reminder**: You can find the code for this example in the <a href="https://github.com/AbstractSDK/cw-orchestrator/tree/main/contracts/counter" target="_blank">cw-orch counter-contract folder</a>.
66
>
7-
> If you are a fast or visual learner, you can find a <a href="https://github.com/AbstractSDK/cw-orch-counter-example/compare/e0a54b074ca1a894bb6e58276944cf2013d152f2..64623d2141c04e4ba42dc6f9ef1a1daccc932d4a" target="_blank">**Before**-**After**</a> view of the `cw-orch` integration process in the sample contract.
7+
> If you are a fast or visual learner, you can find a <a href="https://github.com/AbstractSDK/cw-orch-counter-example/compare/e0a54b074ca1a894bb6e58276944cf2013d152f2..17f505758734fd3cfe3b4f7cede341376c930e98" target="_blank">**Before**-**After**</a> view of the `cw-orch` integration process in the sample contract.
88
99
## Creating an Interface
1010

docs/src/contracts/scripting.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Writing and Executing Scripts
22

3-
Now that we have the interface written for our contract, we can start writing scripts to deploy and interact with it on a real blockchain. We'll do this by adding a `examples` folder in <a href="https://abstract.money" target="_blank">Abstract</a>[the counter contract](https://github.com/AbstractSDK/cw-orchestrator/tree/main/contracts/counter) and add our deploy script there. We only provide an overview of how scripting can be done here. Find our more about how to make your scripting dreams come true on the [Daemon page](../integrations/daemon.md).
3+
Now that we have the interface written for our contract, we can start writing scripts to deploy and interact with it on a real blockchain. We'll do this by adding a `examples` folder in <a href="https://github.com/AbstractSDK/cw-orchestrator/tree/main/contracts/counter" target="_blank">the counter contract</a> and add our deploy script there. We only provide an overview of how scripting can be done here. Find our more about how to make your scripting dreams come true on the [Daemon page](../integrations/daemon.md).
44

55
## Setup
66

@@ -11,14 +11,13 @@ mkdir counter/examples
1111
touch counter/examples/deploy.rs
1212
```
1313

14-
Then we want to add the required dependencies to the `dev-dependencies` section of our `Cargo.toml` file. We'll need `dotenv` to load our environment variables and `pretty_env_logger` to log to stdout. We're using `examples` instead of `bin` because setting a feature on an optional dependency is not supported.
14+
Then we want to add the required dependencies to the `dev-dependencies` section of our `Cargo.toml` file. We'll need `dotenv` to load our environment variables and `pretty_env_logger` to log to stdout.
1515

1616
```toml
1717
[dev-dependencies]
1818
# Deps for deployment
1919
dotenv = { version = "0.15.0" } # Enables loading of .env files
2020
pretty_env_logger = { version = "0.5.0" } # Enables logging to stdout and prettifies it
21-
counter-contract = { path = ".", features = ["interface"] } # Allows to activate the `interface` feature for examples and tests
2221
```
2322

2423
Now we're ready to start writing our script.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Wasm Compilation
2+
3+
`cw-orch` was designed to help you test, deply, script and maintaint your application. None of its features include in-contract operations. cw-orch interfaces, macros and helpers can't be used inside a wasm smart contract.
4+
5+
In case you use one of the cw-orch features inside you smart-contract, the compilation will send an error anyway, so that we are **SURE** you are not using un-intended features inside your contract.
6+
7+
## Importing cw-orch
8+
9+
Importing `cw-orch` as a dependency in your smart contract is not a problem. We have built this library such that every feature that cw-orch imports, uses or exports is not included when compiled for Wasm. This means that you are safe to use any cw-orch feature when developing your application, creating interfaces, exporting features, because none of it will land in your contract.
10+
11+
In order to make sure you don't encounter wasm compilation errors, you should follow the guidelines outlined in the next section.
12+
13+
## Guidelines
14+
15+
### Imports
16+
17+
Import cw-orch without a worry, this won't include unnecessary dependencies and bloat your smart-contract. Be careful of the features you import `cw-orch` with because they might increase your compile time (especially `daemon` and `osmosis-test-tube`).
18+
19+
### Interface
20+
21+
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:
22+
23+
```rust,ignore
24+
{{#include ../../../contracts/counter/src/interface.rs:interface_macro}}
25+
```
26+
27+
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:
28+
29+
```rust,ignore
30+
#[cfg(not(target_arch = "wasm32"))]
31+
{{#include ../../../contracts/counter/src/interface.rs:uploadable_impl}}
32+
```
33+
34+
### Entry Points
35+
36+
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:
37+
38+
```rust,ignore
39+
{{#include ../../../contracts/counter/src/msg.rs:exec_msg}}
40+
```
41+
42+
```rust,ignore
43+
{{#include ../../../contracts/counter/src/lib.rs:fn_re_export}}
44+
```

docs/src/integrations/daemon.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Quick Start
66

7-
Interacting with the `daemon` is really straightforward. How to creating a daemon instance is shown below:
7+
Interacting with the `daemon` is really straightforward. Creating a daemon instance is shown below:
88

99
```rust,ignore
1010
use cw_orch::prelude::*;
@@ -15,31 +15,11 @@ Interacting with the `daemon` is really straightforward. How to creating a daemo
1515
- The `chain` parameter allows you to specify which chain you want to interact with. The chains that are officially supported can be found in the `cw_orch::daemon::networks` module.
1616
You can also add additional chains yourself by simply defining a variable of type <a href="https://docs.rs/cw-orch/latest/cw_orch/daemon/struct.ChainInfo.html" target="_blank">`ChainInfo`</a> and using it in your script. Don't hesitate to open a PR on the <a href="https://github.com/AbstractSDK/cw-orchestrator" target="_blank">cw-orchestrator repo</a>, if you would like us to include a chain by default. The variables needed for creating the variable can be found in the documentation of the chain you want to connect to or in the <a href="https://cosmos.directory" target="_blank">Cosmos Directory</a>.
1717

18-
- The `handle` parameter is a *tokio runtime handle*.
19-
<details>
20-
<summary>If you <strong>don't know</strong> what that means</summary>
21-
22-
23-
You don't need to know all the intricacies of <a href="https://rust-lang.github.io/async-book/" target="_blank">tokio and rust-async</a> to use daemons. If you don't have time to learn more, you can simply use the snippet above and not touch the runtime creation. However for more advanced `daemon` usage and also for your culture, don't hesitate to learn about those wonderful processes and their management.
24-
25-
</details>
26-
27-
<details>
28-
<summary>If you <strong>know</strong> what that means</summary>
29-
30-
This handler is used because all the front-facing daemon methods are synchronous. However everything that's happening in the background is asynchronous. This handle is used exclusively to await asynchronous function:
31-
```rust,ignore
32-
runtime.block_on(...)
33-
34-
```
35-
Because creating runtimes is a costly process, we leave the handler creation and management to the user.
36-
37-
</details>
38-
39-
4018
This simple script actually hides another parameter which is the `LOCAL_MNEMONIC` environment variable. This variable is used when interacting with local chains. See the part dedicated to [Environment Vars](../contracts/env-variable.md) for more details.
4119

4220
> **_NOTE:_** When using `daemon`, you are interacting directly with a live chain. The program won't ask you for your permission at each step of the script. We advise you to test **ALL** your deployments on test chain before deploying to mainnet.
21+
>
22+
> Under the hood, the `DaemonBuilder` struct creates a `tokio::Runtime`. Be careful because this builder is not usable in an `async` function. In such function, you can use <a href="https://docs.rs/cw-orch/latest/cw_orch/daemon/struct.DaemonAsync.html" target="_blank">`DaemonAsync`</a>
4323
4424
## Interacting with contracts
4525

@@ -101,7 +81,7 @@ Here are the available options and fields you can use in the builder object:
10181

10282
- `chain` (*required*) specifies the chain the `daemon` object will interact with. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.chain" target="_blank">Documentation Link</a>
10383
- `deployment_id` (*optional*) is used when loading and saving blockchain state (addresses and code-ids). It is useful when you have multiple instances of the same contract on a single chain. It will allow you to keep those multiple instances in the same state file without overriding state.<a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.deployment_id" target="_blank">Documentation Link</a>
104-
- `handle` (*required*) is the `tokio` runtime handled used to await async functions. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.handle" target="_blank">Documentation Link</a>
84+
- `handle` (*optional*) is the `tokio` runtime handled used to await async functions. `cw-orch` provides a default runtime if not specified. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.handle" target="_blank">Documentation Link</a>
10585
- `mnemonic` (*optional*) is the mnemonic that will be used to create the sender associated with the resulting `Daemon` Object. It is not compatible with the `sender` method. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.mnemonic" target="_blank">Documentation Link</a>
10686
- `sender` (*optional*) is the sender that will be uses with the `resulting` Daemon Object. It is not compatible with the `mnemonic` method. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.mnemonic" target="_blank">Documentation Link</a>
10787
- `authz_granter` (*optional*) allows you to use the authz module. If this field is specified, the sender will send transactions wrapped inside an authz message sent by the specified `granter`. <a href="https://docs.cosmos.network/v0.46/modules/authz/" target="_blank">More info on the authz module</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.authz_granter" target="_blank">Documentation Link</a>

0 commit comments

Comments
 (0)