ibc_relayer_types/applications/ics29_fee/msgs/
pay_packet.rs

1use ibc_proto::google::protobuf::Any;
2use ibc_proto::ibc::applications::fee::v1::{Fee as ProtoFee, MsgPayPacketFee};
3
4use crate::applications::ics29_fee::error::Error;
5use crate::applications::transfer::coin::RawCoin;
6use crate::core::ics24_host::identifier::{ChannelId, PortId};
7
8use crate::signer::Signer;
9use crate::tx_msg::encode_message;
10
11const TYPE_URL: &str = "/ibc.applications.fee.v1.MsgPayPacketFee";
12
13pub fn build_pay_packet_message(
14    port_id: &PortId,
15    channel_id: &ChannelId,
16    payer: &Signer,
17    recv_fee: Vec<RawCoin>,
18    ack_fee: Vec<RawCoin>,
19    timeout_fee: Vec<RawCoin>,
20) -> Result<Any, Error> {
21    let fee = ProtoFee {
22        recv_fee: recv_fee.into_iter().map(Into::into).collect(),
23        ack_fee: ack_fee.into_iter().map(Into::into).collect(),
24        timeout_fee: timeout_fee.into_iter().map(Into::into).collect(),
25    };
26
27    let message = MsgPayPacketFee {
28        fee: Some(fee),
29        source_port_id: port_id.to_string(),
30        source_channel_id: channel_id.to_string(),
31        signer: payer.to_string(),
32        relayers: Vec::new(),
33    };
34
35    let encoded = encode_message(&message).map_err(Error::encode)?;
36
37    Ok(Any {
38        type_url: TYPE_URL.to_string(),
39        value: encoded,
40    })
41}