1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId};

use crate::prelude::{DualTagged, MonoTagged, WalletAddress};

/// Build the recipient address as following:
/// {intermediate_refund_address}|{foward_port}/{forward_channel}:{final_destination_address}
/// See <https://hub.cosmos.network/main/governance/proposals/2021-09-hub-ibc-router/>
pub fn build_forward_address<'a, ChainB, ChainC>(
    intermediate_destination_address: MonoTagged<ChainB, &'a WalletAddress>,
    port: DualTagged<ChainB, ChainC, PortId>,
    channel: &'a ChannelId,
    final_destination_address: MonoTagged<ChainC, &'a WalletAddress>,
) -> WalletAddress {
    let forward_address =
        format!("{intermediate_destination_address}|{port}/{channel}:{final_destination_address}");
    WalletAddress(forward_address)
}

/// Build a forward address with the destination address invalid
pub fn build_invalid_forward_address<'a, ChainB, ChainC>(
    intermediate_destination_address: MonoTagged<ChainB, &'a WalletAddress>,
    port: DualTagged<ChainB, ChainC, PortId>,
    channel: &'a ChannelId,
) -> WalletAddress {
    let forward_address =
        format!("{intermediate_destination_address}|{port}/{channel}:invalid address");
    WalletAddress(forward_address)
}