Skip to content

Commit

Permalink
chore: Documentation and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jul 12, 2024
1 parent 4ffbb45 commit 92c7b8c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.73.0
toolchain: 1.74.0
target: wasm32-unknown-unknown
profile: minimal
override: true
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,15 @@ impl CustomQuery for MyMsg {}
#[sv::messages(interface as Interface)]
#[sv::messages(interface as InterfaceWithCustomType: custom(msg, query))]
#[sv::custom(msg=MyMsg, query=MyQuery)]
#[sv::msg_attr(exec, PartialOrd)]
#[sv::override_entry_point(sudo=crate::entry_points::sudo(crate::SudoMsg))]
impl MyContract {
// ...
#[sv::msg(query)]
#[sv::attr(serde(rename(serialize = "CustomQueryMsg")))]
fn query_msg(&self, _ctx: QueryCtx) -> StdResult<Response> {
// ...
}
}
```

Expand All @@ -292,6 +298,10 @@ impl MyContract {
* `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::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 @@ -378,6 +388,31 @@ pub fn evaluate_member(&self, ctx: ExecCtx, ...) -> StdResult<Response> {
}
```


## Executor message builder

Sylvia defines the [`ExecutorBuilder`]() type, which can be accessed through [`Remote::executor`]().
It's generic over the contract type and exposes execute methods from the
contract and every interface implemented on it through an auto-generated `Executor` traits.
Execute messages of other contracts can be built with `Remote` as well by
calling `executor` method. It returns a message builder that implements
auto-generated `Executor` traits of all Sylvia contracts.
Methods defined in the `Executor` traits constructs an execute message,
which variant corresponds to the method name.
The message is then wrapped in the `WasmMsg`, and returned once [`ExecutorBuilder::build()`]
method is called.

```rust
use sylvia::types::Remote;
use other_contract::contract::OtherContract;
use other_contract::contract::sv::Executor;

let some_exec_msg: WasmMsg = Remote::<OtherContract>::new(remote_addr)
.executor()
.some_exec_method()?
.build();
```

## Using unsupported entry points

If there's a need for an entry point that is not implemented in Sylvia, you can implement
Expand Down
80 changes: 0 additions & 80 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ cw-multi-test = "2.1.0"
cw-storage-plus = "2.0.0"
cw-utils = "2.0.0"
cw2 = "2.0.0"
getrandom = "0.2.15"
semver = "1.0.23"
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
thiserror = "1.0.61"
Expand Down
1 change: 0 additions & 1 deletion examples/contracts/cw1-subkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ cw1 = { path = "../../interfaces/cw1" }
whitelist = { path = "../../interfaces/whitelist" }
cw1-whitelist = { path = "../cw1-whitelist", features = ["library"] }
cw2 = { workspace = true }
getrandom = { workspace = true, features = ["js"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
thiserror = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion examples/contracts/cw1-whitelist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ thiserror = { workspace = true }
cw2 = { workspace = true }
cw-multi-test = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
getrandom = { workspace = true, features = ["js"] }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion examples/contracts/cw20-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ cw2 = { workspace = true }
cw20-allowances = { path = "../../interfaces/cw20-allowances" }
cw20-marketing = { path = "../../interfaces/cw20-marketing" }
cw20-minting = { path = "../../interfaces/cw20-minting" }
getrandom = { workspace = true, features = ["js"] }
semver = { workspace = true }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
Expand Down
28 changes: 28 additions & 0 deletions sylvia-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ pub(crate) fn crate_module() -> Path {
/// # fn main() {}
/// ```
///
/// ### `sv::msg_attr(msg_type, {...})`
///
/// This attribute can be used for the whole `trait Interface {}` block and
/// for the following message types: `exec`, `query` and `sudo`.
/// The `{...}` part will be forwarded as an attribute `#[{...}]` to the
/// given message type (enum or struct).
///
/// ### `sv::attr({...})`
///
/// Forwards variant's attribute to the specific enum's field in the
/// generated message type. It can be used along with `sv::msg(...)`
/// and only for message types variants that resolves in an enum field,
/// i.e. `exec`, `query` and `sudo`.
///
#[proc_macro_error]
#[proc_macro_attribute]
pub fn interface(attr: TokenStream, item: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -600,6 +614,20 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
/// # fn main() {}
/// ```
///
/// ### `sv::msg_attr(msg_type, {...})`
///
/// This attribute can be used for the whole `impl Contract {}` block and
/// for every message type: `exec`, `query`, `sudo`, `instantiate`,
/// `migrate` and `reply`. The `{...}` part will be forwarded as an
/// attribute `#[{...}]` to the given message type (enum or struct).
///
/// ### `sv::attr({...})`
///
/// Forwards variant's attribute to the specific enum's field in the
/// generated message type. It can be used along with `sv::msg(...)`
/// and only for message types variants that resolves in an enum field,
/// i.e. `exec`, `query` and `sudo`.
///
///
#[proc_macro_error]
#[proc_macro_attribute]
Expand Down
2 changes: 2 additions & 0 deletions sylvia/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ impl<Contract: ?Sized> ExecutorBuilder<(EmptyExecutorBuilderState, Contract)> {
_state: std::marker::PhantomData,
}
}
}

impl<T, Contract: ?Sized> ExecutorBuilder<(T, Contract)> {
/// Adds the funds to the execution message.
pub fn with_funds(self, funds: Vec<Coin>) -> Self {
Self { funds, ..self }
Expand Down

0 comments on commit 92c7b8c

Please sign in to comment.