Crates.io | cw-ics20-hook |
lib.rs | cw-ics20-hook |
version | 1.0.0 |
source | src |
created_at | 2024-07-11 20:38:03.848874 |
updated_at | 2024-07-11 20:38:03.848874 |
description | Wrapper contract for Kujira's ICS20 cosmwasm hooks |
homepage | |
repository | |
max_upload_size | |
id | 1299993 |
size | 62,126 |
This CosmWasm contract serves as a wrapper around Kujira's ICS20 transfer callbacks. It provides a mechanism to execute callbacks after interchain transfers are completed, either individually or after all transfers in a batch are finished. The contract can handle multiple coin transfers in a single transaction.
AfterAny
: Triggered after each successful transferAfterAll
: Triggered only after all transfers in a batch are successfulUsed to initialize the contract. Currently, it doesn't require any parameters.
pub struct InstantiateMsg {}
The main message for executing actions on the contract.
pub enum ExecuteMsg {
Transfer {
channel_id: String,
to_address: String,
timeout: IbcTimeout,
transfer_callback: CallbackType,
callback: Option<CallbackData>,
},
}
channel_id
: The IBC channel ID for the transferto_address
: The recipient address on the destination chaintimeout
: The timeout for the IBC transfertransfer_callback
: The type of callback to execute (AfterAny or AfterAll) after the transfer(s)callback
: Immediate callback to the sender after the transfer is initiated, containing the internal ID associated with the transferNote: The actual coins to be transferred should be sent along with this message.
Queries available in the contract:
pub enum QueryMsg {
TransferStatus { id: Uint128 },
AllTransfers {
limit: Option<u32>,
start_after: Option<Uint128>,
},
}
TransferStatus
: Query the status of a specific transfer by its IDAllTransfers
: Query the status of all transfers, with optional paginationpub enum CallbackType {
AfterAny(CallbackData),
AfterAll(CallbackData),
}
AfterAny
: Executes the callback after each successful transferAfterAll
: Executes the callback only after all transfers in a batch are successfulpub struct TransferStartedResponse {
pub id: Uint128,
}
This is returned in the data
field in the initial callback after a transfer is initiated.
id
: The internal ID associated with the transferInstantiate the contract on your Cosmos-based blockchain.
To initiate a transfer with a callback:
let msg = ExecuteMsg::Transfer {
channel_id: "channel-0".to_string(),
to_address: "recipient_address".to_string(),
timeout: IbcTimeout::with_timestamp(Timestamp::from_seconds(future_timestamp)),
transfer_callback: CallbackType::AfterAny(CallbackData(Binary::from(b"callback_data"))),
callback: Some(CallbackData(Binary::from(b"initial_callback_data"))),
};
Send this message along with the coins you want to transfer. The contract will initiate an IBC transfer for each coin sent.
The contract will handle the transfer(s) and execute the callback based on the specified type and the result of the transfer(s).
To query the status of a transfer:
let query_msg = QueryMsg::TransferStatus { id: Uint128::new(1) };
To query all transfers:
let query_msg = QueryMsg::AllTransfers { limit: Some(10), start_after: None };
ExecuteMsg::Transfer
is received, the contract processes each coin sent with the message.In case of a transfer error or timeout, the TransferResult
will be set to Error
or Timeout
, respectively. The contract will still execute the callback(s) based on the specified type.
If the sender contract has an error during the callback execution, it will NOT revert the entire transaction, as the IBC acknowledgement will be saved anyway.