Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sylvia: Describe IBC support #114

Merged
merged 4 commits into from
Jul 29, 2024
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
9 changes: 5 additions & 4 deletions src/pages/sylvia/basics/_meta.json
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"
}
2 changes: 1 addition & 1 deletion src/pages/sylvia/basics/contract-structure.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
tags: ["sylvia", "basics"]
tags: ["sylvia"]
---

# Contract structure
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sylvia/basics/generate-contract.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
tags: ["sylvia", "basics"]
tags: ["sylvia"]
---

# Generate contract
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sylvia/basics/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
tags: ["sylvia", "basics"]
tags: ["sylvia"]
---

import { Callout } from "nextra/components";
Expand Down
88 changes: 88 additions & 0 deletions src/pages/sylvia/basics/ibc.mdx
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.