diff --git a/Cargo.toml b/Cargo.toml index aa73beb..821fada 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ members = [ "template/runtime", "template/node", "cosmwasm/std", - "composable/primitives", "composable/vm", "composable/vm-wasmi", "composable/composable-support", @@ -141,7 +140,6 @@ wasmi = { version = "0.30.0", default-features = false } wasmi-validation = { version = "0.5.0", default-features = false } # Composable -ibc-primitives = { path = "composable/primitives", default-features = false } pallet-cosmwasm = { path = "frame/cosmwasm", default-features = false } cosmwasm-vm = { path = "composable/vm", default-features = false } cosmwasm-vm-wasmi = { path = "composable/vm-wasmi", default-features = false } diff --git a/composable/primitives/Cargo.toml b/composable/primitives/Cargo.toml deleted file mode 100644 index f08d716..0000000 --- a/composable/primitives/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -edition = "2021" -name = "ibc-primitives" -version = "0.1.0" -authors = ["David Salami "] - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -sp-runtime = { workspace = true, default-features = false } -scale-info = { workspace = true, default-features = false } - -ibc = { workspace = true, default-features = false } -codec = { version = "3.2.0", package = "parity-scale-codec", default-features = false } - -[features] -default = ['std'] -std = [ - "sp-runtime/std", - "scale-info/std", - "ibc/std", - "codec/std", -] -mocks = [] -runtime-benchmarks = [] diff --git a/composable/primitives/src/lib.rs b/composable/primitives/src/lib.rs deleted file mode 100644 index 9d396b5..0000000 --- a/composable/primitives/src/lib.rs +++ /dev/null @@ -1,129 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; - -use alloc::{string::String, vec::Vec}; -use codec::{Decode, Encode}; -use ibc::{ - apps::transfer::types::PrefixedCoin, - core::{ - channel::types::{channel::ChannelEnd, packet::Packet}, - client::types::Height, - host::types::identifiers::{ChannelId, PortId}, - }, - primitives::{Signer, Timestamp}, -}; -use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; - -/// Packet timeout, could be an offset, or absolute value. -#[derive(RuntimeDebug, PartialEq, Eq, TypeInfo, Encode, Decode, Clone)] -pub enum Timeout { - Offset { - /// Timestamp at which this packet should timeout in counterparty in seconds - /// relative to the latest time stamp - timestamp: Option, - /// Block height at which this packet should timeout on counterparty - /// relative to the latest height - height: Option, - }, - /// Absolute value - Absolute { - /// Timestamp at which this packet should timeout on the counterparty in nanoseconds - timestamp: Option, - /// Block height at which this packet should timeout on the counterparty - height: Option, - }, -} - -pub enum HandlerMessage { - OpenChannel { - port_id: PortId, - channel_end: ChannelEnd, - }, - CloseChannel { - channel_id: ChannelId, - port_id: PortId, - }, - Transfer { - channel_id: ChannelId, - coin: PrefixedCoin, - timeout: Timeout, - from: AccountId, - to: Signer, - memo: String, - }, - SendPacket { - /// packet data - data: Vec, - /// Packet timeout - timeout: Timeout, - /// port id as utf8 string bytes - port_id: PortId, - /// channel id as utf8 string bytes - channel_id: ChannelId, - }, - WriteAck { - /// Raw acknowledgement bytes - ack: Vec, - /// Packet - packet: Packet, - }, -} - -#[derive(core::fmt::Debug, Clone, PartialEq, Eq)] -/// Error definition for module -pub enum Error { - /// Failed to register a new packet - SendPacketError { msg: Option }, - /// An error involving the connection id - ConnectionIdError { msg: Option }, - /// An error involving the client id - ClientIdError { msg: Option }, - /// An error involving channel or port - ChannelOrPortError { msg: Option }, - /// An error involving Client state - ClientStateError { msg: Option }, - /// An Error Involving the Timestamp and height - TimestampOrHeightNotFound { msg: Option }, - /// Failed to register a token transfer packet - SendTransferError { msg: Option }, - /// Ics20 receive packet processing error - ReceivePacketError { msg: Option }, - /// Write acknowledgement error - WriteAcknowledgementError { msg: Option }, - /// Ics20 packet acknowledgement processing error - AcknowledgementError { msg: Option }, - /// Ics20 packet timeout processing error - TimeoutError { msg: Option }, - /// Failed to bind port - BindPortError { msg: Option }, - /// Failed to initialize a new channel - ChannelInitError { msg: Option }, - /// Failed to close a channel - ChannelCloseError { msg: Option }, - /// Failed to decode a value - DecodingError { msg: Option }, - /// Failed to decode commitment prefix - ErrorDecodingPrefix, - /// Some other error - Other { msg: Option }, -} - -/// Captures the functions modules can use to interact with the ibc pallet -/// Currently allows modules to register packets and create channels -pub trait IbcHandler { - /// Get the latest height and latest timestamp for the client paired to the channel and port - /// combination - fn latest_height_and_timestamp( - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result<(Height, Timestamp), Error>; - /// Handle a message - fn handle_message(msg: HandlerMessage) -> Result<(), Error>; - /// testing related methods - #[cfg(feature = "runtime-benchmarks")] - fn create_client() -> Result; - #[cfg(feature = "runtime-benchmarks")] - fn create_connection(client_id: ClientId, connection_id: ConnectionId) -> Result<(), Error>; -} diff --git a/frame/cosmwasm/Cargo.toml b/frame/cosmwasm/Cargo.toml index 7091d18..bb28c82 100644 --- a/frame/cosmwasm/Cargo.toml +++ b/frame/cosmwasm/Cargo.toml @@ -17,7 +17,6 @@ scale-info = { default-features = false, version = "2.1.1", features = [ hex = { version = "0.4", default-features = false, features = ["alloc"] } hex-literal = { workspace = true } ibc = { workspace = true, default-features = false } -ibc-primitives = { workspace = true, default-features = false, optional = false } libsecp256k1 = { version = "0.7.0", default-features = false } log = { workspace = true, default-features = false } parity-wasm = { version = "0.45.0", default-features = false } @@ -63,7 +62,6 @@ std = [ "scale-info/std", "hex/std", "ibc/std", - "ibc-primitives/std", "libsecp256k1/std", "log/std", "parity-wasm/std", diff --git a/frame/cosmwasm/src/ibc.rs b/frame/cosmwasm/src/ibc.rs index 7ebb6de..7ab2e29 100644 --- a/frame/cosmwasm/src/ibc.rs +++ b/frame/cosmwasm/src/ibc.rs @@ -4,49 +4,6 @@ use crate::{ types::{AccountIdOf, DefaultCosmwasmVM}, Config, Pallet, }; -use cosmwasm_vm::{ - executor::{ - ibc::{ - IbcChannelCloseCall, IbcChannelConnectCall, IbcChannelOpenCall, IbcPacketAckCall, - IbcPacketReceiveCall, IbcPacketTimeoutCall, - }, - AllocateCall, AsFunctionName, CosmwasmCallInput, CosmwasmCallWithoutInfoInput, - DeallocateCall, HasInfo, Unit, - }, - input::Input, - memory::PointerOf, - vm::{VmErrorOf, VmInputOf, VmOutputOf}, -}; -use ibc::{ - core::{ - client::types::Height, - host::types::identifiers::{ChannelId, PortId}, - }, - primitives::Timestamp, -}; -use ibc_primitives::HandlerMessage; - -use crate::types::EntryPoint::{self, *}; - -pub struct ChannelOpenCall; -impl Input for ChannelOpenCall { - type Output = cosmwasm_vm::executor::ibc::IbcChannelOpenResult; -} -impl AsFunctionName for ChannelOpenCall { - const NAME: &'static str = "ibc_channel_open"; -} -impl HasInfo for ChannelOpenCall { - const HAS_INFO: bool = false; -} - -impl cosmwasm_vm::system::EventIsTyped for ChannelOpenCall { - const TYPE: cosmwasm_vm::system::SystemEventType = - cosmwasm_vm::system::SystemEventType::IbcChannelConnect; -} - -impl cosmwasm_vm::system::EventHasCodeId for ChannelOpenCall { - const HAS_CODE_ID: bool = false; -} impl Pallet { /// Check whether a contract export the mandatory IBC functions and is consequently IBC capable. @@ -84,58 +41,3 @@ impl Pallet { format!("wasm.{}", Pallet::::account_to_cosmwasm_addr(address)) } } - -use cosmwasm_vm::system::CosmwasmBaseVM; -pub trait CosmwasmCallVMSingle = CosmwasmBaseVM -where - I: Input + HasInfo, - for<'x> Unit: TryFrom, Error = VmErrorOf>, - for<'x> VmInputOf<'x, Self>: TryFrom>, Error = VmErrorOf> - + TryFrom>, Error = VmErrorOf> - + TryFrom, I>, Error = VmErrorOf> - + TryFrom, I>, Error = VmErrorOf>; - -pub trait AsEntryName { - const ENTRY: EntryPoint; -} - -impl AsEntryName for IbcChannelOpenCall { - const ENTRY: EntryPoint = IbcChannelOpen; -} - -impl AsEntryName for IbcPacketReceiveCall { - const ENTRY: EntryPoint = IbcPacketReceive; -} - -impl AsEntryName for IbcChannelConnectCall { - const ENTRY: EntryPoint = IbcChannelConnect; -} - -impl AsEntryName for IbcChannelCloseCall { - const ENTRY: EntryPoint = IbcChannelClose; -} - -impl AsEntryName for IbcPacketTimeoutCall { - const ENTRY: EntryPoint = IbcPacketTimeout; -} - -impl AsEntryName for IbcPacketAckCall { - const ENTRY: EntryPoint = IbcPacketAck; -} - -pub struct NoRelayer { - _marker: core::marker::PhantomData, -} - -impl ibc_primitives::IbcHandler> for NoRelayer { - fn latest_height_and_timestamp( - _port_id: &PortId, - _channel_id: &ChannelId, - ) -> Result<(Height, Timestamp), ibc_primitives::Error> { - Err(ibc_primitives::Error::Other { msg: Some("not supported".to_string()) }) - } - - fn handle_message(_msg: HandlerMessage>) -> Result<(), ibc_primitives::Error> { - Err(ibc_primitives::Error::Other { msg: Some("not supported".to_string()) }) - } -} diff --git a/frame/cosmwasm/src/lib.rs b/frame/cosmwasm/src/lib.rs index a62f5a2..de78a40 100644 --- a/frame/cosmwasm/src/lib.rs +++ b/frame/cosmwasm/src/lib.rs @@ -51,7 +51,6 @@ pub mod runtimes; pub mod types; pub mod utils; pub mod weights; -pub use crate::ibc::NoRelayer; pub mod entrypoint; const SUBSTRATE_ECDSA_SIGNATURE_LEN: usize = 65;