Skip to content
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
40 changes: 17 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ In Sylvia, we define our contracts as structures:
```rust
use cw_storage_plus::Item;
use cosmwasm_schema::cw_serde;
use sylvia::types::QueryCtx;
use sylvia::ctx::QueryCtx;
use sylvia::cw_std::ensure;


Expand All @@ -59,7 +59,7 @@ struct MyContract<'a> {

/// Response type returned by the
/// query method.
///
///
#[cw_serde]
pub struct CounterResp {
pub counter: u64,
Expand Down Expand Up @@ -165,7 +165,6 @@ result type has to implement `Into<ContractError>`, where `ContractError` is a c
error type - it will all be commonized in the generated dispatching function (so
entry points have to return `ContractError` as its error variant).


## Interfaces

One of the fundamental ideas of the Sylvia framework is the interface, allowing the
Expand All @@ -175,7 +174,7 @@ grouping of messages into their semantical groups. Let's define a Sylvia interfa
pub mod group {
use super::*;
use sylvia::interface;
use sylvia::types::ExecCtx;
use sylvia::ctx::{ExecCtx, QueryCtx};
use sylvia::cw_std::StdError;

#[cw_serde]
Expand Down Expand Up @@ -285,23 +284,22 @@ impl MyContract {
}
```

* `sv::error` is used by both `contract` and `entry_point` macros. It is necessary in case a custom
error is being used by your contract. If omitted generated code will use `StdError`.

* `sv::messages` is the attribute for the `contract` macro. Its purpose is to inform Sylvia
about interfaces implemented for the contract. If the implemented interface does not use a
default `Empty` message response for query and/or exec then the `: custom(query)`,
`: custom(msg)` or `: custom(msg, query)` should be indicated.
- `sv::error` is used by both `contract` and `entry_point` macros. It is necessary in case a custom
error is being used by your contract. If omitted generated code will use `StdError`.

* `sv::override_entry_point` - refer to the `Overriding entry points` section.
- `sv::messages` is the attribute for the `contract` macro. Its purpose is to inform Sylvia
about interfaces implemented for the contract. If the implemented interface does not use a
default `Empty` message response for query and/or exec then the `: custom(query)`,
`: custom(msg)` or `: custom(msg, query)` should be indicated.

* `sv::custom` allows to define CustomMsg and CustomQuery for the contract. By default generated code
will return `Response<Empty>` and will use `Deps<Empty>` and `DepsMut<Empty>`.
- `sv::override_entry_point` - refer to the `Overriding entry points` section.

* `sv::msg_attr` forwards any attribute to the message's type.
- `sv::custom` allows to define CustomMsg and CustomQuery for the contract. By default generated code
will return `Response<Empty>` and will use `Deps<Empty>` and `DepsMut<Empty>`.

* `sv::attr` forwards any attribute to the enum's variant.
- `sv::msg_attr` forwards any attribute to the message's type.

- `sv::attr` forwards any attribute to the enum's variant.

## Usage in external crates

Expand Down Expand Up @@ -352,10 +350,9 @@ with `ExecMsg/QueryMsg` - the former is generated only for contract, not for int
and is not meant to be used to send messages to the contract - their purpose is for proper
messages dispatching only, and should not be used besides the entry points.


## Query helpers

To make querying more user-friendly `Sylvia` provides users with `sylvia::types::BoundQuerier` and
To make querying more user-friendly `Sylvia` provides users with `sylvia::types::BoundQuerier` and
`sylvia::types::Remote` helpers. The latter is meant to store the address of some remote contract.
For each query method in the contract, Sylvia will add a method in a generated `sv::Querier` trait.
The `sv::Querier` is then implemented for `sylvia::types::BoundQuerier` so the user can call the method.
Expand Down Expand Up @@ -388,7 +385,6 @@ pub fn evaluate_member(&self, ctx: ExecCtx, ...) -> StdResult<Response> {
}
```


## Executor message builder

Sylvia defines the
Expand Down Expand Up @@ -496,7 +492,7 @@ It is possible to define a custom `exec` message that will dispatch over one gen
by your contract and one defined by you. To use this custom entry point with `contract` macro
you can add the `sv::override_entry_point(...)` attribute.

```rust
```rust
#[contract]
#[sv::override_entry_point(exec=crate::entry_points::execute(crate::exec::CustomExecMsg))]
#[sv::override_entry_point(sudo=crate::entry_points::sudo(crate::SudoMsg))]
Expand Down Expand Up @@ -613,7 +609,6 @@ All the instantiation and execution functions return the
`Result<cw_multi_test::AppResponse, ContractError>` type, where `ContractError`
is an error type of the contract.


## Interface items in multitest

Trait declaring all the interface methods is directly implemented on
Expand Down Expand Up @@ -678,8 +673,8 @@ Generics in a contract might be either used as generic field types or as generic
types in the messages. When Sylvia generates the messages' enums, only generics used in respective methods
will be part of a given generated message type.


Example of usage:

```rust
pub struct GenericContract<
InstantiateParam,
Expand Down Expand Up @@ -766,7 +761,6 @@ where
}
```


## Generating schema

Sylvia is designed to generate all the code that `cosmwasm-schema` relies on - this
Expand Down
127 changes: 0 additions & 127 deletions examples/interfaces/custom-and-generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ pub trait CustomAndGeneric {
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
use sylvia::cw_std::testing::mock_dependencies;
use sylvia::cw_std::{Addr, CosmosMsg, Empty, QuerierWrapper};
use sylvia::types::InterfaceApi;

use crate::sv::Querier;

Expand Down Expand Up @@ -234,130 +232,5 @@ mod tests {
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);

let _ = <dyn super::CustomAndGeneric<
Error = (),
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
RetT = SvCustomMsg,
> as super::sv::InterfaceMessagesApi>::Querier::borrowed(
&contract, &querier_wrapper
);

// Construct messages with InterfaceApi
let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
SvCustomMsg,
> as InterfaceApi>::Query::custom_generic_query_one(
SvCustomMsg {}, SvCustomMsg {}
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
SvCustomMsg,
> as InterfaceApi>::Query::custom_generic_query_two(
SvCustomMsg {}, SvCustomMsg {}
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
SvCustomMsg,
> as InterfaceApi>::Exec::custom_generic_execute_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
SvCustomMsg,
> as InterfaceApi>::Exec::custom_generic_execute_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
SvCustomMsg,
> as InterfaceApi>::Sudo::custom_generic_sudo_one(
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
SvCustomMsg,
> as InterfaceApi>::Sudo::custom_generic_sudo_two(
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);
}
}
109 changes: 0 additions & 109 deletions examples/interfaces/generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ pub trait Generic {
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
use sylvia::cw_std::testing::mock_dependencies;
use sylvia::cw_std::{Addr, CosmosMsg, Empty, QuerierWrapper};
use sylvia::types::InterfaceApi;

use crate::sv::Querier;

Expand Down Expand Up @@ -229,112 +227,5 @@ mod tests {
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);

let _ = <dyn super::Generic<
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
RetT = Empty,
Error = (),
> as super::sv::InterfaceMessagesApi>::Querier::borrowed(
&contract, &querier_wrapper
);

// Construct messages with InterfaceApi
let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
_,
_,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
> as InterfaceApi>::Query::generic_query_one(SvCustomMsg {}, SvCustomMsg {});

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
_,
_,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
> as InterfaceApi>::Query::generic_query_two(SvCustomMsg {}, SvCustomMsg {});

let _ = <super::sv::Api<
_,
_,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::cw_std::Empty,
> as InterfaceApi>::Exec::generic_exec_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);

let _ = <super::sv::Api<
SvCustomMsg,
_,
_,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::cw_std::Empty,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
> as InterfaceApi>::Exec::generic_exec_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
_,
_,
SvCustomMsg,
sylvia::cw_std::Empty,
> as InterfaceApi>::Sudo::generic_sudo_one(
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);

let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::cw_std::Empty,
SvCustomMsg,
SvCustomMsg,
_,
_,
SvCustomMsg,
> as InterfaceApi>::Sudo::generic_sudo_two(
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);
}
}
Loading