-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
568e6e4
commit 7da67d7
Showing
8 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Attributes forwarding | ||
|
||
This feature allows ^sylvia users to forward any attribute to every message | ||
type using `#[sv::msg_attr(msg_type, ...)]` attribute. For the messages | ||
that resolves to enum types it is possible to forward attributes per | ||
enum field by using `#[sv::attr(...)]` - this works for `exec`, `query` | ||
and `sudo` methods. | ||
|
||
## Example | ||
|
||
```rust,noplayground | ||
use cosmwasm_std::{Response, StdResult}; | ||
use sylvia::types::{InstantiateCtx, ExecCtx}; | ||
use sylvia::{contract, entry_points}; | ||
pub mod interface { | ||
use cosmwasm_std::{Response, StdResult, StdError}; | ||
use sylvia::types::QueryCtx; | ||
use sylvia::interface; | ||
#[interface] | ||
#[sv::msg_attr(query, derive(PartialOrd))] | ||
pub trait Interface { | ||
type Error: From<StdError>; | ||
#[sv::msg(query)] | ||
#[sv::attr(serde(rename(serialize = "QuErY")))] | ||
fn interface_query_msg(&self, _ctx: QueryCtx) -> StdResult<Response>; | ||
} | ||
} | ||
pub struct CounterContract; | ||
#[entry_points] | ||
#[contract] | ||
#[sv::msg_attr(exec, derive(PartialOrd))] | ||
impl CounterContract { | ||
pub const fn new() -> Self { | ||
Self | ||
} | ||
#[sv::msg(instantiate)] | ||
pub fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::default()) | ||
} | ||
#[sv::msg(exec)] | ||
#[sv::attr(serde(rename(serialize = "EXEC_METHOD")))] | ||
pub fn exec_method(&self, _ctx: ExecCtx) -> StdResult<Response> { | ||
Ok(Response::default()) | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Sudo entry point | ||
|
||
Sylvia supports a `sudo` type entry point both in interfaces and in | ||
contracts. Those methods can be used as a part of the network's | ||
governance procedures. More informations can be found in official | ||
CosmWasm documentation. From ^sylvia user point of view there's no | ||
much difference between `sudo` and `exec` methods. | ||
|
||
## Example | ||
|
||
```rust,noplayground | ||
use cosmwasm_std::{Response, StdResult}; | ||
use sylvia::types::{InstantiateCtx, SudoCtx}; | ||
use sylvia::{contract, entry_points}; | ||
pub mod interface { | ||
use cosmwasm_std::{Response, StdResult, StdError}; | ||
use sylvia::types::{SudoCtx}; | ||
use sylvia::interface; | ||
#[interface] | ||
pub trait Interface { | ||
type Error: From<StdError>; | ||
#[sv::msg(sudo)] | ||
fn interface_sudo_msg(&self, _ctx: SudoCtx) -> StdResult<Response>; | ||
} | ||
} | ||
pub struct CounterContract; | ||
#[entry_points] | ||
#[contract] | ||
#[sv::messages(interface)] | ||
impl CounterContract { | ||
pub const fn new() -> Self { | ||
Self | ||
} | ||
#[sv::msg(instantiate)] | ||
pub fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::default()) | ||
} | ||
#[sv::msg(sudo)] | ||
pub fn sudo_method(&self, _ctx: SudoCtx) -> StdResult<Response> { | ||
Ok(Response::default()) | ||
} | ||
} | ||
impl interface::Interface for CounterContract { | ||
fn interface_sudo_msg(&self, _ctx: SudoCtx) -> StdResult<Response> { | ||
Ok(Response::default()) | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters