Skip to content

Commit

Permalink
Update Docs for Daemon Builder and Sender (#483)
Browse files Browse the repository at this point in the history
* Better docs

* Small doc nit

* Deprecate authz and fee_grant directly on Daemon

* Changelog
  • Loading branch information
Kayanski authored Sep 11, 2024
1 parent 5f315a1 commit 59d4b01
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unpublished

- Add methods to set the private key and mnemonic of an existing sender
- Deprecate `authz_granter` and `fee_granter` on `Daemon` struct

### Breaking

Expand Down
1 change: 0 additions & 1 deletion cw-orch-daemon/examples/batch-sender.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ANCHOR: full_counter_example
use counter_contract::{
msg::InstantiateMsg, CounterContract, CounterExecuteMsgFns, CounterQueryMsgFns,
};
Expand Down
26 changes: 26 additions & 0 deletions cw-orch-daemon/examples/hd_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use cosmwasm_std::coins;
use cw_orch::{anyhow, prelude::*};
use cw_orch_daemon::CosmosOptions;

// From https://github.com/CosmosContracts/juno/blob/32568dba828ff7783aea8cb5bb4b8b5832888255/docker/test-user.env#L1
pub const LOCAL_JUNO_SENDER: &str = "juno16g2rahf5846rxzp3fwlswy08fz8ccuwk03k57y";
pub const LOCAL_JUNO_GRANTER: &str = "juno1afhtjur8js4589xymu346ca7a5y5293xpuv6ry";

pub fn main() -> anyhow::Result<()> {
pretty_env_logger::init(); // Used to log contract and chain interactions

let network = networks::LOCAL_JUNO;
// The mnemonic is read from environment variables automatically, no need to specify in this builders
let sender = CosmosOptions::default()
.hd_index(5)
.authz_granter(&Addr::unchecked(LOCAL_JUNO_GRANTER));
let chain = Daemon::builder(network).build_sender(sender)?;

chain.rt_handle.block_on(
chain
.sender()
.bank_send(&Addr::unchecked(LOCAL_JUNO_GRANTER), coins(10000, "ujuno")),
)?;

Ok(())
}
2 changes: 1 addition & 1 deletion cw-orch-daemon/examples/querier-daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn main() -> anyhow::Result<()> {
pretty_env_logger::init(); // Used to log contract and chain interactions

let network = networks::LOCAL_JUNO;
// There is no need to register a mnemonic to use this daemon querier
// QueryOnlyDaemon doesn't need a mnemonic to function
let chain: QueryOnlyDaemon = QueryOnlyDaemon::builder(network).build_sender(())?;

let balances = chain
Expand Down
2 changes: 2 additions & 0 deletions cw-orch-daemon/src/sync/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ impl<Sender: QuerySender> DaemonBase<Sender> {

// Helpers for Daemon with [`Wallet`] sender.
impl Daemon {
#[deprecated = "Use `self.sender_mut().set_authz_granter(granter)` or change the sender builder options instead"]
/// Specifies wether authz should be used with this daemon
pub fn authz_granter(&mut self, granter: &Addr) -> &mut Self {
self.sender_mut().set_authz_granter(granter);
self
}

#[deprecated = "Use `self.sender_mut().set_fee_granter(granter)` or change the sender builder options instead"]
/// Specifies wether feegrant should be used with this daemon
pub fn fee_granter(&mut self, granter: &Addr) -> &mut Self {
self.sender_mut().set_fee_granter(granter);
Expand Down
26 changes: 20 additions & 6 deletions docs/src/integrations/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,28 @@ Here are the available options and fields you can use in the builder object:
- `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>
- `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>
- `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>
- `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>
- `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>
- `fee_granter` (*optional*) allows you to use the fee-grant module. If this field is specified, the sender will try to pay for transactions using the specified `granter`. <a href="https://docs.cosmos.network/v0.46/modules/feegrant/" target="_blank">More info on the fee grant module</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.fee_granter" target="_blank">Documentation Link</a>
- `hd_index` (*optional*) allows to set the index of the HD path for the account associated with the `Daemon` object. <a href="https://hub.cosmos.network/main/resources/hd-wallets.html" target="_blank">More info on the derivation path and index</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/sync/struct.DaemonBuilder.html#method.hd_index" target="_blank">Documentation Link</a>
- `state` (*optional*) is used when you want to specify an existing `DaemonState` object to the new Daemon. This is particularly useful when interacting with multiple chains at the same time.

> **NOTE**: if none of `sender` or `mnemonic` is specified, [env variables](../contracts/env-variable.md) will be used to construct the sender object.
> **NOTE**: if `mnemonic` is not specified, [env variables](../contracts/env-variable.md) will be used to construct the sender object.
Keep in mind that those options can't be changed once the `Daemon` object is built, using the `build` function. It is possible to create a new `DaemonBuilder` structure from a `Daemon` object by using the `rebuild` method and specifying the options that you need to change.
Keep in mind that most of these options can't be changed once the `Daemon` object is built, using the `build` function. It is possible to create a new `DaemonBuilder` structure from a `Daemon` object by using the `rebuild` method and specifying the options that you need to change.

### Properties of the default sender

If you wish to use the default `CosmosSender` provided by default, you can use this simple pattern:

```rust,ignore
let daemon = Daemon::builder(JUNO_1).build()?;
```

You can use the following functions on the `CosmosSender` (obtained via `Daemon::sender_mut()`) object to customize some of its properties:

- `CosmosSender::set_authz_granter` allows you to use the authz module. If this method is used, 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/type.Daemon.html#method.authz_granter" target="_blank">Documentation Link</a>
- `CosmosSender::set_fee_granter` allows you to use the fee-grant module. If this method is used, the sender will try to pay for transactions using the specified `granter`. <a href="https://docs.cosmos.network/v0.46/modules/feegrant/" target="_blank">More info on the fee grant module</a>. <a href="https://docs.rs/cw-orch-daemon/latest/cw_orch_daemon/type.Daemon.html#method.fee_granter" target="_blank">Documentation Link</a>

### Customizing the Sender

If you wish to use the `Daemon` object with a different sender (for instance to batch transactions, or to submit the transaction to a multisig), you can use `DaemonBuilder::build_sender` instead of `DaemonBuilder::build`. This allows you to customize the sender before constructing the Daemon object. You can find an example of such usage in <a target="_blank" href="https://github.com/AbstractSDK/cw-orchestrator/blob/main/cw-orch-daemon/examples/">our official Github repository</a>

## Additional tools

Expand Down

0 comments on commit 59d4b01

Please sign in to comment.