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
use crate::{
client_proxy::ClientProxy,
commands::{blocking_cmd, report_error, Command},
};
pub struct TransferCommand {}
impl Command for TransferCommand {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["transfer", "transferb", "t", "tb"]
}
fn get_params_help(&self) -> &'static str {
"\n\t<sender_account_address>|<sender_account_ref_id> \
<receiver_account_address>|<receiver_account_ref_id> <number_of_coins> <currency_code> \
[gas_unit_price_in_micro_diems (default=0)] [max_gas_amount_in_micro_diems (default 400_000)] \
Suffix 'b' is for blocking. "
}
fn get_description(&self) -> &'static str {
"Transfer coins from one account to another."
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() < 5 || params.len() > 7 {
println!("Invalid number of arguments for transfer");
println!(
"{} {}",
self.get_aliases().join(" | "),
self.get_params_help()
);
return;
}
println!(">> Transferring");
let is_blocking = blocking_cmd(params[0]);
match client.transfer_coins(params, is_blocking) {
Ok(index_and_seq) => {
if is_blocking {
println!("Finished transaction!");
} else {
println!("Transaction submitted to validator");
}
println!(
"To query for transaction status, run: query txn_acc_seq {} {} \
<fetch_events=true|false>",
index_and_seq.account_index, index_and_seq.sequence_number
);
}
Err(e) => report_error("Failed to perform transaction", e),
}
}
}