Skip to content

Commit 0e3c9fb

Browse files
feat: split ibc and xcall (#358)
* feat: split ibc * feat: split xcall * fix: split tests * fix: fix build and fmt * fix: sequence no from connection * fix: fix reply form host * fix: remove fee handler * fix: storage keys * fix: xcall forward * fix: cleanup --------- Co-authored-by: sabinchitrakar <immortal.infidel@gmail.com>
1 parent b77cc06 commit 0e3c9fb

File tree

110 files changed

+10308
-1311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+10308
-1311
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ members = [
77
"libraries/rust/common",
88
"contracts/cosmwasm-vm/cw-mock-dapp",
99
"contracts/cosmwasm-vm/cw-mock-ibc-core",
10+
"contracts/cosmwasm-vm/cw-xcall-ibc-connection",
11+
"contracts/cosmwasm-vm/cw-xcall-app",
1012
]
1113

1214
[workspace.package]

contracts/cosmwasm-vm/cw-common/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ hex = { version = "0.4.3", default-features = false}
2121
common = { path="../../../libraries/rust/common" }
2222
ibc-proto = { version = "0.26.0", default-features = false, features = ["parity-scale-codec", "borsh"] }
2323
prost = { version = "0.11.8", default-features = false,features=["prost-derive"]}
24+
2425
[dev-dependencies]
2526
getrandom = {version = "0.2.9", default-features = false, features = ["custom"]}
2627
test-utils={path="../../../libraries/rust/test-utils"}
28+

contracts/cosmwasm-vm/cw-common/src/client_response.rs

+5
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,8 @@ pub struct LightClientResponse {
312312
pub message_info: MessageInfo,
313313
pub ibc_endpoint: CwEndPoint,
314314
}
315+
316+
#[cw_serde]
317+
pub struct XcallPacketAck {
318+
pub acknowledgement: Vec<u8>,
319+
}

contracts/cosmwasm-vm/cw-common/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub mod hex_string;
99
pub mod ibc_types;
1010
pub mod raw_types;
1111
pub mod types;
12+
pub mod xcall_app_msg;
13+
pub mod xcall_connection_msg;
1214
pub mod xcall_msg;
1315
use cosmwasm_std::{from_binary, from_slice, Binary, StdError};
1416
use serde::de::DeserializeOwned;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use cosmwasm_schema::cw_serde;
2+
use cosmwasm_std::{
3+
Binary, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg,
4+
IbcPacketReceiveMsg, IbcPacketTimeoutMsg,
5+
};
6+
7+
#[cw_serde]
8+
pub enum ExecuteMsg {
9+
SetAdmin {
10+
address: String,
11+
},
12+
SetProtocol {
13+
value: u128,
14+
},
15+
SetProtocolFeeHandler {
16+
address: String,
17+
},
18+
SendCallMessage {
19+
to: String,
20+
data: Vec<u8>,
21+
rollback: Option<Vec<u8>>,
22+
},
23+
ReceiveCallMessage {
24+
data: Vec<u8>,
25+
},
26+
27+
ExecuteCall {
28+
request_id: u128,
29+
},
30+
31+
ExecuteRollback {
32+
sequence_no: u128,
33+
},
34+
UpdateAdmin {
35+
address: String,
36+
},
37+
RemoveAdmin {},
38+
SetTimeoutHeight {
39+
height: u64,
40+
},
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use cosmwasm_schema::cw_serde;
2+
use cosmwasm_std::{
3+
IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg,
4+
IbcPacketReceiveMsg, IbcPacketTimeoutMsg,
5+
};
6+
7+
#[cw_serde]
8+
pub enum ExecuteMsg {
9+
SetAdmin {
10+
address: String,
11+
},
12+
SetXCallHost {
13+
address: String,
14+
},
15+
MessageFromXCall {
16+
data: Vec<u8>,
17+
},
18+
SetIbcConfig {
19+
ibc_config: Vec<u8>,
20+
},
21+
UpdateAdmin {
22+
address: String,
23+
},
24+
RemoveAdmin {},
25+
SetTimeoutHeight {
26+
height: u64,
27+
},
28+
29+
#[cfg(not(feature = "native_ibc"))]
30+
IbcChannelOpen {
31+
msg: IbcChannelOpenMsg,
32+
},
33+
34+
#[cfg(not(feature = "native_ibc"))]
35+
IbcChannelConnect {
36+
msg: IbcChannelConnectMsg,
37+
},
38+
#[cfg(not(feature = "native_ibc"))]
39+
IbcChannelClose {
40+
msg: IbcChannelCloseMsg,
41+
},
42+
#[cfg(not(feature = "native_ibc"))]
43+
IbcPacketReceive {
44+
msg: IbcPacketReceiveMsg,
45+
},
46+
#[cfg(not(feature = "native_ibc"))]
47+
IbcPacketAck {
48+
msg: IbcPacketAckMsg,
49+
},
50+
#[cfg(not(feature = "native_ibc"))]
51+
IbcPacketTimeout {
52+
msg: IbcPacketTimeoutMsg,
53+
},
54+
}

contracts/cosmwasm-vm/cw-ibc-core/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::*;
22
/// The `CwIbcCoreContext` struct represents the core context of a Cosmos SDK contract for
33
/// inter-blockchain communication.
4-
///
4+
///
55
/// Properties:
6-
///
6+
///
77
/// * `block_height`: A storage item representing the current block height.
88
/// * `cw_ibc_store`: `cw_ibc_store` is an instance of the `CwIbcStore` struct, which is used to manage
99
/// the storage of the contract. It likely contains methods for reading and writing data to the

contracts/cosmwasm-vm/cw-ibc-core/src/contract.rs

+48-48
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ const CONTRACT_NAME: &str = "crates.io:cw-ibc-core";
1212
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
1313

1414
impl<'a> CwIbcCoreContext<'a> {
15-
/// The `instantiate` function initializes the contract and sets default values for channel, client,
16-
/// and connection counters, as well as setting the contract owner.
17-
///
18-
/// Arguments:
19-
///
20-
/// * `deps`: A mutable reference to the dependencies of the contract, which includes access to the
21-
/// storage, API, and other contracts.
22-
/// * `_env`: _env is an object that represents the current blockchain environment, including
23-
/// information such as the block height, time, and chain ID. It is passed as a parameter to the
24-
/// instantiate function in the CosmWasm smart contract framework.
25-
/// * `info`: MessageInfo is a struct that contains information about the message being executed,
26-
/// such as the sender address, the amount of tokens sent with the message, and the message ID. It is
27-
/// passed as a parameter to the instantiate function in order to set the owner of the contract.
28-
/// * `_msg`: The `_msg` parameter is of type `InstantiateMsg` and represents the message sent by the
29-
/// user to instantiate the contract. It contains any custom data or parameters required for the
30-
/// contract initialization.
31-
///
32-
/// Returns:
33-
///
34-
/// A `Result<Response, ContractError>` is being returned. The `Response` contains an attribute
35-
/// "method" with the value "instantiate". If there are no errors, the `Result` will be `Ok`,
36-
/// otherwise it will be `Err(ContractError::Std)`.
15+
/// The `instantiate` function initializes the contract and sets default values for channel, client,
16+
/// and connection counters, as well as setting the contract owner.
17+
///
18+
/// Arguments:
19+
///
20+
/// * `deps`: A mutable reference to the dependencies of the contract, which includes access to the
21+
/// storage, API, and other contracts.
22+
/// * `_env`: _env is an object that represents the current blockchain environment, including
23+
/// information such as the block height, time, and chain ID. It is passed as a parameter to the
24+
/// instantiate function in the CosmWasm smart contract framework.
25+
/// * `info`: MessageInfo is a struct that contains information about the message being executed,
26+
/// such as the sender address, the amount of tokens sent with the message, and the message ID. It is
27+
/// passed as a parameter to the instantiate function in order to set the owner of the contract.
28+
/// * `_msg`: The `_msg` parameter is of type `InstantiateMsg` and represents the message sent by the
29+
/// user to instantiate the contract. It contains any custom data or parameters required for the
30+
/// contract initialization.
31+
///
32+
/// Returns:
33+
///
34+
/// A `Result<Response, ContractError>` is being returned. The `Response` contains an attribute
35+
/// "method" with the value "instantiate". If there are no errors, the `Result` will be `Ok`,
36+
/// otherwise it will be `Err(ContractError::Std)`.
3737
pub fn instantiate(
3838
&self,
3939
deps: DepsMut,
@@ -53,9 +53,9 @@ impl<'a> CwIbcCoreContext<'a> {
5353
}
5454

5555
/// This function handles the execution of various IBC-related messages in a contract.
56-
///
56+
///
5757
/// Arguments:
58-
///
58+
///
5959
/// * `deps`: `deps` is a `DepsMut` object, which provides access to the contract's dependencies
6060
/// such as storage, querier, and API interfaces. It is used to interact with the blockchain and
6161
/// other contracts.
@@ -68,9 +68,9 @@ impl<'a> CwIbcCoreContext<'a> {
6868
/// * `msg`: The `msg` parameter in the `execute` function is of type `CoreExecuteMsg` and
6969
/// represents the message that the contract should execute. The function matches the type of the
7070
/// message and calls the appropriate function to handle it.
71-
///
71+
///
7272
/// Returns:
73-
///
73+
///
7474
/// a `Result<Response, ContractError>` where `Response` is a struct representing the response to a
7575
/// contract execution and `ContractError` is an enum representing possible errors that can occur
7676
/// during contract execution.
@@ -269,19 +269,19 @@ impl<'a> CwIbcCoreContext<'a> {
269269

270270
/// This function handles different types of replies based on their ID and executes the
271271
/// corresponding function.
272-
///
272+
///
273273
/// Arguments:
274-
///
274+
///
275275
/// * `deps`: `deps` is a mutable reference to the dependencies of the contract, which includes
276276
/// access to the storage, API, and other modules. It is of type `DepsMut`.
277277
/// * `_env`: _env is an object of type `Env` which represents the environment in which the contract
278278
/// is executing. It contains information such as the current block height, the current time, and
279279
/// the address of the contract.
280280
/// * `message`: The `message` parameter is of type `Reply` and contains information about the reply
281281
/// being processed, including the ID of the reply and any associated data.
282-
///
282+
///
283283
/// Returns:
284-
///
284+
///
285285
/// a `Result<Response, ContractError>` where `Response` and `ContractError` are defined types.
286286
pub fn reply(
287287
&self,
@@ -343,16 +343,16 @@ impl<'a> CwIbcCoreContext<'a> {
343343
}
344344

345345
/// This function calculates the fee for a given expected gas amount and gas price.
346-
///
346+
///
347347
/// Arguments:
348-
///
348+
///
349349
/// * `expected_gas`: `expected_gas` is an input parameter of type `u64` which represents the
350350
/// expected amount of gas required to execute a transaction on the blockchain. Gas is a unit of
351351
/// measurement for the computational effort required to execute a transaction or contract on the
352352
/// Ethereum network. The higher the gas limit, the more
353-
///
353+
///
354354
/// Returns:
355-
///
355+
///
356356
/// The function `calculate_fee` returns a `u128` value, which represents the calculated fee based
357357
/// on the expected gas and the gas price.
358358
pub fn calculate_fee(&self, expected_gas: u64) -> u128 {
@@ -362,9 +362,9 @@ impl<'a> CwIbcCoreContext<'a> {
362362
}
363363

364364
/// This function calculates the gas price in Rust programming language.
365-
///
365+
///
366366
/// Returns:
367-
///
367+
///
368368
/// an unsigned 128-bit integer, which represents the gas price calculated based on the default gas
369369
/// numerator and gas adjustment numerator values.
370370
pub fn gas_price(&self) -> u128 {
@@ -376,16 +376,16 @@ impl<'a> CwIbcCoreContext<'a> {
376376
}
377377
/// The function updates the balance of each coin in a vector by subtracting a fee and returns the
378378
/// updated vector.
379-
///
379+
///
380380
/// Arguments:
381-
///
381+
///
382382
/// * `coins`: A vector of `Coin` structs representing the current balance of the user. Each `Coin`
383383
/// struct contains an amount and a denomination.
384384
/// * `fee`: The `fee` parameter is an unsigned 128-bit integer representing the amount of fee to be
385385
/// deducted from each coin's balance.
386-
///
386+
///
387387
/// Returns:
388-
///
388+
///
389389
/// a `Result` type with a vector of `Coin` objects as the successful result or a `ContractError` if
390390
/// there is an insufficient balance.
391391
pub fn update_fee(&self, coins: Vec<Coin>, fee: u128) -> Result<Vec<Coin>, ContractError> {
@@ -407,13 +407,13 @@ impl<'a> CwIbcCoreContext<'a> {
407407

408408
/// This function converts a hexadecimal string to a Rust type that implements the Message trait and
409409
/// can be converted to another type using the TryFrom trait.
410-
///
410+
///
411411
/// Arguments:
412-
///
412+
///
413413
/// * `hex_str`: A hexadecimal string that represents the serialized bytes of a protobuf message.
414-
///
414+
///
415415
/// Returns:
416-
///
416+
///
417417
/// a `Result` with a generic type `T` which is the converted message from the raw bytes provided in
418418
/// the `HexString`. If the conversion is successful, it returns an `Ok` variant with the converted
419419
/// message. If there is an error during the conversion, it returns an `Err` variant with a
@@ -443,13 +443,13 @@ impl<'a> CwIbcCoreContext<'a> {
443443

444444
/// The function converts a hexadecimal string to a Signer object and returns an error if the
445445
/// conversion fails.
446-
///
446+
///
447447
/// Arguments:
448-
///
448+
///
449449
/// * `str`: A hexadecimal string representing a signer address.
450-
///
450+
///
451451
/// Returns:
452-
///
452+
///
453453
/// This function returns a `Result` containing either a `Signer` or a `ContractError`.
454454
pub fn to_signer(str: &HexString) -> Result<Signer, ContractError> {
455455
let bytes = str.to_bytes().map_err(|e| ContractError::IbcDecodeError {

contracts/cosmwasm-vm/cw-ibc-core/src/helpers.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ pub struct CwTemplateContract(pub Addr);
1010

1111
impl CwTemplateContract {
1212
/// The function returns a clone of the address stored in a struct.
13-
///
13+
///
1414
/// Returns:
15-
///
15+
///
1616
/// The `addr` function returns a clone of the `Addr` object stored in the first field of `self`.
1717
pub fn addr(&self) -> Addr {
1818
self.0.clone()
1919
}
2020

2121
/// This function takes a message, converts it to binary, and returns a CosmosMsg to execute the
2222
/// message on a contract.
23-
///
23+
///
2424
/// Arguments:
25-
///
25+
///
2626
/// * `msg`: The `msg` parameter is a generic type that implements the `Into` trait for the
2727
/// `cw_common::core_msg::ExecuteMsg` type. It represents the message that will be sent to the
2828
/// contract when the `call` function is executed. The `Into` trait allows for the message to
29-
///
29+
///
3030
/// Returns:
31-
///
31+
///
3232
/// a `StdResult` which can either be `Ok` with a `CosmosMsg` or `Err` with an error message.
3333
pub fn call<T: Into<cw_common::core_msg::ExecuteMsg>>(&self, msg: T) -> StdResult<CosmosMsg> {
3434
let msg = to_binary(&msg.into())?;

0 commit comments

Comments
 (0)