-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic transfer with pay packet is working
- Loading branch information
1 parent
9bbc35a
commit 099d9fa
Showing
14 changed files
with
254 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod msgs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod pay_packet; | ||
|
||
pub use pay_packet::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use ibc_proto::ibc::applications::fee::v1::MsgPayPacketFee; | ||
|
||
use crate::prelude::*; | ||
use crate::tx_msg::Msg; | ||
|
||
pub const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer"; | ||
|
||
pub enum Error {} | ||
|
||
impl Msg for MsgPayPacketFee { | ||
type ValidationError = Error; | ||
type Raw = MsgPayPacketFee; | ||
|
||
fn route(&self) -> String { | ||
crate::keys::ROUTER_KEY.to_string() | ||
} | ||
|
||
fn type_url(&self) -> String { | ||
TYPE_URL.to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//! Various packet encoding semantics which underpin the various types of transactions. | ||
pub mod ics20_fungible_token_transfer; | ||
pub mod ics29_fee; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,4 @@ sha2 = "0.10.2" | |
crossbeam-channel = "0.5.4" | ||
semver = "1.0.7" | ||
flex-error = "0.4.4" | ||
prost = { version = "0.10" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use ibc_proto::cosmos::base::v1beta1::Coin; | ||
use ibc_proto::google::protobuf::Any; | ||
use ibc_proto::ibc::applications::fee::v1::{Fee, MsgPayPacketFee}; | ||
use ibc_relayer::chain::cosmos::types::config::TxConfig; | ||
use prost::{EncodeError, Message}; | ||
|
||
use crate::error::{handle_generic_error, Error}; | ||
use crate::ibc::denom::Denom; | ||
use crate::relayer::transfer::build_transfer_message; | ||
use crate::relayer::tx::simple_send_tx; | ||
use crate::types::id::{TaggedChannelIdRef, TaggedPortIdRef}; | ||
use crate::types::tagged::MonoTagged; | ||
use crate::types::wallet::TaggedWallet; | ||
use crate::types::wallet::{Wallet, WalletAddress}; | ||
|
||
fn encode_message<M: Message>(message: &M) -> Result<Vec<u8>, EncodeError> { | ||
let mut buf = Vec::new(); | ||
Message::encode(message, &mut buf)?; | ||
Ok(buf) | ||
} | ||
|
||
pub fn build_pay_packet_message<Chain, Counterparty>( | ||
port_id: &TaggedPortIdRef<Chain, Counterparty>, | ||
channel_id: &TaggedChannelIdRef<Chain, Counterparty>, | ||
payer: &MonoTagged<Chain, &WalletAddress>, | ||
denom: &MonoTagged<Chain, &Denom>, | ||
receive_fee: u64, | ||
ack_fee: u64, | ||
timeout_fee: u64, | ||
) -> Result<Any, Error> { | ||
const TYPE_URL: &str = "/ibc.applications.fee.v1.MsgPayPacketFee"; | ||
|
||
let denom_str = denom.value().to_string(); | ||
|
||
let fee = Fee { | ||
recv_fee: vec![Coin { | ||
denom: denom_str.clone(), | ||
amount: receive_fee.to_string(), | ||
}], | ||
ack_fee: vec![Coin { | ||
denom: denom_str.clone(), | ||
amount: ack_fee.to_string(), | ||
}], | ||
timeout_fee: vec![Coin { | ||
denom: denom_str, | ||
amount: timeout_fee.to_string(), | ||
}], | ||
}; | ||
|
||
let message = MsgPayPacketFee { | ||
fee: Some(fee), | ||
source_port_id: port_id.value().to_string(), | ||
source_channel_id: channel_id.value().to_string(), | ||
signer: payer.value().0.clone(), | ||
relayers: Vec::new(), | ||
}; | ||
|
||
let encoded = encode_message(&message).map_err(handle_generic_error)?; | ||
|
||
Ok(Any { | ||
type_url: TYPE_URL.to_string(), | ||
value: encoded, | ||
}) | ||
} | ||
|
||
pub async fn ibc_token_transfer_with_fee<SrcChain, DstChain>( | ||
tx_config: &MonoTagged<SrcChain, &TxConfig>, | ||
port_id: &TaggedPortIdRef<'_, SrcChain, DstChain>, | ||
channel_id: &TaggedChannelIdRef<'_, SrcChain, DstChain>, | ||
sender: &MonoTagged<SrcChain, &Wallet>, | ||
recipient: &MonoTagged<DstChain, &WalletAddress>, | ||
denom: &MonoTagged<SrcChain, &Denom>, | ||
send_amount: u64, | ||
receive_fee: u64, | ||
ack_fee: u64, | ||
timeout_fee: u64, | ||
) -> Result<(), Error> { | ||
let transfer_message = | ||
build_transfer_message(port_id, channel_id, sender, recipient, denom, send_amount)?; | ||
|
||
let pay_message = build_pay_packet_message( | ||
port_id, | ||
channel_id, | ||
&sender.address(), | ||
denom, | ||
receive_fee, | ||
ack_fee, | ||
timeout_fee, | ||
)?; | ||
|
||
let messages = vec![transfer_message, pay_message]; | ||
|
||
simple_send_tx(tx_config.value(), &sender.value().key, messages).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters