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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*!
   Methods for performing IBC token transfer on a chain.
*/

use crate::chain::exec::simple_exec;
use crate::error::Error;

pub fn local_transfer_token(
    chain_id: &str,
    command_path: &str,
    home_path: &str,
    rpc_listen_address: &str,
    sender: &str,
    recipient: &str,
    token: &str,
) -> Result<(), Error> {
    simple_exec(
        chain_id,
        command_path,
        &[
            "--node",
            rpc_listen_address,
            "tx",
            "bank",
            "send",
            sender,
            recipient,
            token,
            "--chain-id",
            chain_id,
            "--home",
            home_path,
            "--keyring-backend",
            "test",
            "--yes",
        ],
    )?;

    Ok(())
}

pub fn transfer_from_chain(
    chain_id: &str,
    command_path: &str,
    home_path: &str,
    rpc_listen_address: &str,
    sender: &str,
    src_port: &str,
    src_channel: &str,
    recipient: &str,
    token: &str,
    fees: &str,
    timeout_height: &str,
) -> Result<(), Error> {
    simple_exec(
        chain_id,
        command_path,
        &[
            "--node",
            rpc_listen_address,
            "tx",
            "ibc-transfer",
            "transfer",
            src_port,
            src_channel,
            recipient,
            token,
            "--from",
            sender,
            "--chain-id",
            chain_id,
            "--home",
            home_path,
            "--keyring-backend",
            "test",
            "--fees",
            fees,
            "--timeout-height",
            timeout_height,
            "--yes",
        ],
    )?;

    Ok(())
}