Skip to content

Commit

Permalink
chore: Update docs after review ; Resolve one TODO in the code related
Browse files Browse the repository at this point in the history
to Executors
  • Loading branch information
kulikthebird committed Jun 26, 2024
1 parent a26a68e commit aa93431
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
54 changes: 42 additions & 12 deletions sylvia/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ pub struct ReadyExecutorBuilderState;
/// should be created using a [Remote] object, obtained through the
/// [Remote::executor] method.
///
/// ExecutorEmptyBuilder implements the
/// Executor traits generated by the contract and interface macros,
/// encompassing all sv::msg(exec) methods of the specified contracts
/// [ExecutorBuilder] implements the
/// Executor traits generated by the `contract` and `interface` macros,
/// encompassing all `sv::msg(exec)` methods of the specified contracts
/// and interfaces.
///
/// ```rust
/// pub mod another_contract {
/// use cosmwasm_std::{Response, StdResult};
/// use sylvia::contract;
/// use sylvia::types::{ExecCtx, InstantiateCtx};
/// # use cosmwasm_std::{Response, StdResult};
/// # use sylvia::contract;
/// # use sylvia::types::{ExecCtx, InstantiateCtx};
///
/// pub struct AnotherContract {}
///
Expand All @@ -197,12 +197,12 @@ pub struct ReadyExecutorBuilderState;
/// }
/// }
///
/// use cosmwasm_std::{coin, Addr, Response, StdResult};
/// use cw_storage_plus::Item;
/// use sylvia::contract;
/// use sylvia::types::{ExecCtx, InstantiateCtx, Remote};
/// use another_contract::AnotherContract;
/// use another_contract::sv::Executor;
/// # use cosmwasm_std::{coin, Addr, Response, StdResult};
/// # use cw_storage_plus::Item;
/// # use sylvia::contract;
/// # use sylvia::types::{ExecCtx, InstantiateCtx, Remote};
/// # use another_contract::AnotherContract;
/// # use another_contract::sv::Executor;
///
/// pub struct Contract<'a> {
/// pub remote_contract: Item<Remote<'a, AnotherContract>>,
Expand Down Expand Up @@ -235,6 +235,36 @@ pub struct ReadyExecutorBuilderState;
///
/// # fn main() {}
/// ```
///
/// It is also possible to call execution methods on other contract's interface:
///
/// ```rust
/// pub mod interface {
/// # use cosmwasm_std::{Response, StdResult, StdError};
/// # use sylvia::interface;
/// # use sylvia::types::ExecCtx;
///
/// #[interface]
/// pub trait Interface {
/// type Error: From<StdError>;
///
/// #[sv::msg(exec)]
/// fn exec_method(&self, ctx: ExecCtx) -> StdResult<Response>;
/// }
/// }
///
/// # use interface::Interface;
/// # use interface::sv::Executor;
/// # use cosmwasm_std::{Addr, Response, StdError, StdResult};
/// # use sylvia::types::Remote;
///
/// fn execute_method(remote_addr: Addr) -> StdResult<Response> {
/// let remote = Remote::<'_, dyn Interface<Error=StdError>>::new(remote_addr);
/// let msg = remote.executor().exec_method()?.build();
/// Ok(Response::new().add_message(msg))
/// }
/// ```
///
pub struct ExecutorBuilder<State: ?Sized> {
contract: String,
funds: Vec<Coin>,
Expand Down
35 changes: 11 additions & 24 deletions sylvia/tests/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ where
}

pub mod manager {
use cosmwasm_std::{to_json_binary, Addr, Response, StdError, StdResult, WasmMsg};
use cosmwasm_std::{Addr, Response, StdError, StdResult};
use cw_storage_plus::Item;
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
use serde::Serialize;
use sylvia::contract;
use sylvia::types::{ExecCtx, InstantiateCtx, InterfaceApi, QueryCtx};
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx};

use crate::counter::sv::{Api as CounterApi, Querier};
use crate::counter::sv::{Executor, Querier};
use crate::{ExampleMsg, ExampleQuery, InterfaceStorage};

pub struct ManagerContract<'a, CounterT> {
Expand Down Expand Up @@ -236,27 +236,14 @@ pub mod manager {
ctx: ExecCtx<ExampleQuery>,
value: CounterT,
) -> Result<Response<ExampleMsg>, StdError> {
// This should be simplified to something like
// ```rust
// let msg = self
// .remote_counter
// .load(ctx.deps.storage)?
// .add(value)
// .with_funds(&[])
// .build();
// ```
// after https://github.com/CosmWasm/sylvia/issues/130
let msg = <CounterApi<_> as InterfaceApi>::Exec::add(value);
let wasm = WasmMsg::Execute {
contract_addr: self
.remote_counter
.load(ctx.deps.storage)?
.interface_remote
.as_ref()
.to_string(),
msg: to_json_binary(&msg)?,
funds: vec![],
};
let wasm = self
.remote_counter
.load(ctx.deps.storage)?
.interface_remote

Check warning on line 242 in sylvia/tests/remote.rs

View check run for this annotation

Codecov / codecov/patch

sylvia/tests/remote.rs#L242

Added line #L242 was not covered by tests
.executor()
.with_funds(vec![])
.add(value)?
.build();
let resp = Response::new().add_message(wasm);
Ok(resp)
}
Expand Down

0 comments on commit aa93431

Please sign in to comment.