-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
5 changed files
with
96 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"getting-started": "Getting started", | ||
"generate-contract": "Generate contract", | ||
"contract-structure": "Contract structure", | ||
"interoperability": "Interoperability" | ||
"getting-started": "Getting started", | ||
"generate-contract": "Generate contract", | ||
"contract-structure": "Contract structure", | ||
"interoperability": "Interoperability", | ||
"ibc": "Ibc" | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
tags: ["sylvia", "basics"] | ||
tags: ["sylvia"] | ||
--- | ||
|
||
# Contract structure | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
tags: ["sylvia", "basics"] | ||
tags: ["sylvia"] | ||
--- | ||
|
||
# Generate contract | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
tags: ["sylvia", "basics"] | ||
tags: ["sylvia"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
|
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,88 @@ | ||
--- | ||
tags: ["sylvia", "ibc"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
|
||
# IBC | ||
|
||
Sylvia doesn't generate any [IBC](../../ibc) related code, but you can define | ||
your own [IBC entry points](../../ibc/diy-protocol#Entrypoints) like you would | ||
in the case of a regular CosmWasm contract. | ||
|
||
You can define the logic inside the contract and call the method from the entry | ||
point. | ||
|
||
```rust {14-21, 32, 30} | ||
pub struct IbcContract; | ||
|
||
#[contract] | ||
impl IbcContract { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
|
||
#[sv::msg(instantiate)] | ||
fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
pub fn ibc_channel_open( | ||
&self, | ||
deps: DepsMut, | ||
env: Env, | ||
msg: IbcChannelOpenMsg, | ||
) -> StdResult<IbcChannelOpenResponse> { | ||
// Your logic here | ||
} | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn ibc_channel_open( | ||
deps: DepsMut, | ||
env: Env, | ||
msg: IbcChannelOpenMsg, | ||
) -> StdResult<IbcChannelOpenResponse> { | ||
IbcContract::new().ibc_channel_open(deps, env, msg) | ||
} | ||
``` | ||
|
||
You can also define a trait for the IBC methods and implement it for on the | ||
contract. | ||
|
||
```rust {7, 10, 12-13, 21-22} | ||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn ibc_channel_open( | ||
deps: DepsMut, | ||
env: Env, | ||
msg: IbcChannelOpenMsg, | ||
) -> StdResult<IbcChannelOpenResponse> { | ||
IbcContract::new().ibc_channel_open(deps, env, msg) | ||
} | ||
|
||
pub struct IbcContract; | ||
|
||
pub trait Ibc { | ||
fn ibc_channel_open( | ||
&self, | ||
deps: DepsMut, | ||
env: Env, | ||
msg: IbcChannelOpenMsg, | ||
) -> StdResult<IbcChannelOpenResponse>; | ||
} | ||
|
||
impl Ibc for IbcContract { | ||
fn ibc_channel_open( | ||
&self, | ||
deps: DepsMut, | ||
env: Env, | ||
msg: IbcChannelOpenMsg, | ||
) -> StdResult<IbcChannelOpenResponse> { | ||
// Your logic here | ||
} | ||
} | ||
``` | ||
|
||
Remember not to use the interface attribute for this trait. Sylvia does not | ||
handle IBC entry points, and there is no point in generating helpers around | ||
them. |