Skip to content

Commit

Permalink
Sylvia: Describe IBC support (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia authored Jul 29, 2024
2 parents 159a008 + 11d9608 commit cb40166
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 7 deletions.
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.

0 comments on commit cb40166

Please sign in to comment.