Skip to content

Commit

Permalink
feat: establish ICS-721 boilerplate, ready for new additions (#1012)
Browse files Browse the repository at this point in the history
* chore: establish ics721 boilerplate, ready for new additions

* nit
  • Loading branch information
Farhad-Shabani authored Dec 20, 2023
1 parent d2a91ea commit c609f7e
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ members = [
"ibc-clients",
"ibc-apps/ics20-transfer/types",
"ibc-apps/ics20-transfer",
"ibc-apps/ics721-nft-transfer/types",
"ibc-apps/ics721-nft-transfer",
"ibc-apps",
"ibc-core/ics24-host/cosmos",
"ibc-data-types",
Expand Down Expand Up @@ -73,6 +75,7 @@ ibc-core-handler = { version = "0.48.1", path = "./ibc-core/ics25-handler",
ibc-core-router = { version = "0.48.1", path = "./ibc-core/ics26-routing", default-features = false }
ibc-client-tendermint = { version = "0.48.1", path = "./ibc-clients/ics07-tendermint", default-features = false }
ibc-app-transfer = { version = "0.48.1", path = "./ibc-apps/ics20-transfer", default-features = false }
ibc-app-nft-transfer = { version = "0.48.1", path = "./ibc-apps/ics721-nft-transfer", default-features = false }

ibc-core-client-context = { version = "0.48.1", path = "./ibc-core/ics02-client/context", default-features = false }
ibc-core-client-types = { version = "0.48.1", path = "./ibc-core/ics02-client/types", default-features = false }
Expand All @@ -85,6 +88,7 @@ ibc-core-handler-types = { version = "0.48.1", path = "./ibc-core/ics25-han
ibc-core-router-types = { version = "0.48.1", path = "./ibc-core/ics26-routing/types", default-features = false }
ibc-client-tendermint-types = { version = "0.48.1", path = "./ibc-clients/ics07-tendermint/types", default-features = false }
ibc-app-transfer-types = { version = "0.48.1", path = "./ibc-apps/ics20-transfer/types", default-features = false }
ibc-app-nft-transfer-types = { version = "0.48.1", path = "./ibc-apps/ics721-nft-transfer/types", default-features = false }

ibc-proto = { version = "0.39.1", default-features = false }

Expand Down
8 changes: 7 additions & 1 deletion ibc-apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ description = """
all-features = true

[dependencies]
ibc-app-transfer = { workspace = true }
ibc-app-transfer = { workspace = true }
ibc-app-nft-transfer = { workspace = true }

[features]
default = ["std"]
std = [
"ibc-app-transfer/std",
"ibc-app-nft-transfer/std",
]
serde = [
"ibc-app-transfer/serde",
"ibc-app-nft-transfer/serde",
]
schema = [
"ibc-app-transfer/schema",
"ibc-app-nft-transfer/schema",
"serde",
"std",
]
borsh = [
"ibc-app-transfer/borsh",
"ibc-app-nft-transfer/borsh",
]
parity-scale-codec = [
"ibc-app-transfer/parity-scale-codec",
"ibc-app-nft-transfer/parity-scale-codec",
]
5 changes: 5 additions & 0 deletions ibc-apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ applications:
- [ibc-app-transfer](./../ibc-apps/ics20-transfer)
- [ibc-app-transfer-types](./../ibc-apps/ics20-transfer/types)

### ICS-721: Non-Fungible Token Transfer Application

- [ibc-app-nft-transfer](./../ibc-apps/ics721-nft-transfer)
- [ibc-app-nft-transfer-types](./../ibc-apps/ics721-nft-transfer/types)

## Contributing

IBC is specified in English in the [cosmos/ibc
Expand Down
53 changes: 53 additions & 0 deletions ibc-apps/ics721-nft-transfer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "ibc-app-nft-transfer"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
keywords = ["cosmos", "ibc", "nft", "transfer", "ics721"]
readme = "./../README.md"
description = """
Maintained by `ibc-rs`, contains the implementation of the ICS-721 Non-Fungible Token Transfer
application logic and re-exports essential data structures and domain types from
`ibc-app-nft-transfer-types` crate.
"""

[package.metadata.docs.rs]
all-features = true

[dependencies]
# external dependencies
serde_json = { workspace = true, optional = true }

# ibc dependencies
ibc-app-nft-transfer-types = { workspace = true }
ibc-core = { workspace = true }

[features]
default = ["std"]
std = [
"ibc-app-nft-transfer-types/std",
"ibc-core/std",
"serde_json/std",
]
serde = [
"ibc-app-nft-transfer-types/serde",
"ibc-core/serde",
"serde_json"
]
schema = [
"ibc-app-nft-transfer-types/schema",
"ibc-core/schema",
"serde",
"std",
]
borsh = [
"ibc-app-nft-transfer-types/borsh",
"ibc-core/borsh",
]
parity-scale-codec = [
"ibc-app-nft-transfer-types/parity-scale-codec",
"ibc-core/parity-scale-codec",
]
8 changes: 8 additions & 0 deletions ibc-apps/ics721-nft-transfer/src/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Defines the required context traits for ICS-721 to interact with host
//! machine.

/// Read-only methods required in NFT transfer validation context.
pub trait NftTransferValidationContext {}

/// Read-write methods required in NFT transfer execution context.
pub trait NftTransferExecutionContext: NftTransferValidationContext {}
2 changes: 2 additions & 0 deletions ibc-apps/ics721-nft-transfer/src/handler/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//! Implements IBC handlers responsible for processing Non-Fungible Token
//! Transfers (ICS-721) messages.
30 changes: 30 additions & 0 deletions ibc-apps/ics721-nft-transfer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Implementation of the IBC [Non-Fungible Token
//! Transfer](https://github.com/cosmos/ibc/blob/main/spec/app/ics-721-nft-transfer/README.md)
//! (ICS-721) application logic.
#![no_std]
#![forbid(unsafe_code)]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types))]
#![deny(
warnings,
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_qualifications,
rust_2018_idioms
)]

#[cfg(any(test, feature = "std"))]
extern crate std;

pub mod context;
pub mod handler;
pub mod module;

/// Re-exports the implementation of the IBC [Non-Fungible Token
/// Transfer](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md)
/// (ICS-721) data structures.
pub mod types {
#[doc(inline)]
pub use ibc_app_nft_transfer_types::*;
}
167 changes: 167 additions & 0 deletions ibc-apps/ics721-nft-transfer/src/module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
//! Provides IBC module callbacks implementation for the ICS-721 transfer.

use ibc_app_nft_transfer_types::error::NftTransferError;
use ibc_core::channel::types::acknowledgement::Acknowledgement;
use ibc_core::channel::types::channel::{Counterparty, Order};
use ibc_core::channel::types::packet::Packet;
use ibc_core::channel::types::Version;
use ibc_core::host::types::identifiers::{ChannelId, ConnectionId, PortId};
use ibc_core::primitives::Signer;
use ibc_core::router::types::module::ModuleExtras;

use crate::context::{NftTransferExecutionContext, NftTransferValidationContext};

pub fn on_chan_open_init_validate(
_ctx: &impl NftTransferValidationContext,
_order: Order,
_connection_hops: &[ConnectionId],
_port_id: &PortId,
_channel_id: &ChannelId,
_counterparty: &Counterparty,
_version: &Version,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_init_execute(
_ctx: &mut impl NftTransferExecutionContext,
_order: Order,
_connection_hops: &[ConnectionId],
_port_id: &PortId,
_channel_id: &ChannelId,
_counterparty: &Counterparty,
_version: &Version,
) -> Result<(ModuleExtras, Version), NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_try_validate(
_ctx: &impl NftTransferValidationContext,
_order: Order,
_connection_hops: &[ConnectionId],
_port_id: &PortId,
_channel_id: &ChannelId,
_counterparty: &Counterparty,
_counterparty_version: &Version,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_try_execute(
_ctx: &mut impl NftTransferExecutionContext,
_order: Order,
_connection_hops: &[ConnectionId],
_port_id: &PortId,
_channel_id: &ChannelId,
_counterparty: &Counterparty,
_counterparty_version: &Version,
) -> Result<(ModuleExtras, Version), NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_ack_validate(
_ctx: &impl NftTransferExecutionContext,
_port_id: &PortId,
_channel_id: &ChannelId,
_counterparty_version: &Version,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_ack_execute(
_ctx: &mut impl NftTransferExecutionContext,
_port_id: &PortId,
_channel_id: &ChannelId,
_counterparty_version: &Version,
) -> Result<ModuleExtras, NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_confirm_validate(
_ctx: &impl NftTransferValidationContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_chan_open_confirm_execute(
_ctx: &mut impl NftTransferExecutionContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<ModuleExtras, NftTransferError> {
unimplemented!()
}

pub fn on_chan_close_init_validate(
_ctx: &impl NftTransferValidationContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_chan_close_init_execute(
_ctx: &mut impl NftTransferExecutionContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<ModuleExtras, NftTransferError> {
unimplemented!()
}

pub fn on_chan_close_confirm_validate(
_ctx: &impl NftTransferValidationContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_chan_close_confirm_execute(
_ctx: &mut impl NftTransferExecutionContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<ModuleExtras, NftTransferError> {
unimplemented!()
}

pub fn on_recv_packet_execute(
_ctx_b: &mut impl NftTransferExecutionContext,
_packet: &Packet,
) -> (ModuleExtras, Acknowledgement) {
unimplemented!()
}

pub fn on_acknowledgement_packet_validate<Ctx>(
_ctx: &impl NftTransferValidationContext,
_packet: &Packet,
_acknowledgement: &Acknowledgement,
_relayer: &Signer,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_acknowledgement_packet_execute(
_ctx: &mut impl NftTransferExecutionContext,
_packet: &Packet,
_acknowledgement: &Acknowledgement,
_relayer: &Signer,
) -> (ModuleExtras, Result<(), NftTransferError>) {
unimplemented!()
}

pub fn on_timeout_packet_validate(
_ctx: &impl NftTransferValidationContext,
_packet: &Packet,
_relayer: &Signer,
) -> Result<(), NftTransferError> {
unimplemented!()
}

pub fn on_timeout_packet_execute(
_ctx: &mut impl NftTransferExecutionContext,
_packet: &Packet,
_relayer: &Signer,
) -> (ModuleExtras, Result<(), NftTransferError>) {
unimplemented!()
}
Loading

0 comments on commit c609f7e

Please sign in to comment.