casper_client/cli/simple_args/
help.rs

1//! Functions for use in help commands.
2
3use std::convert::TryFrom;
4
5use itertools::Itertools;
6
7use casper_types::{account::AccountHash, AccessRights, AsymmetricType, Key, PublicKey, URef};
8
9use super::{PREFIX_FOR_OPTION, SUPPORTED_TYPES};
10
11/// Returns a list of `CLType`s able to be passed as a string for use as payment code or session
12/// code args.
13pub fn supported_cl_type_list() -> String {
14    format!(
15        "{}, {}",
16        SUPPORTED_TYPES
17            .iter()
18            .map(|(simple_type, _parser)| simple_type)
19            .join(", "),
20        SUPPORTED_TYPES
21            .iter()
22            .map(|(simple_type, _parser)| PREFIX_FOR_OPTION.to_string() + simple_type)
23            .join(", ")
24    )
25}
26
27/// Returns a string listing examples of the format required when passing in payment code or
28/// session code args.
29pub fn supported_cl_type_examples() -> String {
30    let bytes = (1..33).collect::<Vec<_>>();
31    let array = <[u8; 32]>::try_from(bytes.as_ref()).unwrap();
32
33    format!(
34        r#""name_01:bool='false'"
35"name_02:i32='-1'"
36"name_03:i64='-2'"
37"name_04:u8='3'"
38"name_05:u32='4'"
39"name_06:u64='5'"
40"name_07:u128='6'"
41"name_08:u256='7'"
42"name_09:u512='8'"
43"name_10:unit=''"
44"name_11:string='a value'"
45"key_account_name:key='{}'"
46"key_hash_name:key='{}'"
47"key_uref_name:key='{}'"
48"account_hash_name:account_hash='{}'"
49"uref_name:uref='{}'"
50"public_key_name:public_key='{}'"
51"byte_list_name:byte_list='010203'"            # variable-length list of bytes, i.e. CLType::List(CLType::U8)
52"byte_array_5_name:byte_array_5='0102030405'"  # fixed-length array of bytes, in this example CLType::ByteArray(5)
53"byte_array_32_name:byte_array_32='{}'"
54
55Optional values of all of these types can also be specified.
56Prefix the type with "opt_" and use the term "null" without quotes to specify a None value:
57"name_01:opt_bool='true'"       # Some(true)
58"name_02:opt_bool='false'"      # Some(false)
59"name_03:opt_bool=null"         # None
60"name_04:opt_i32='-1'"          # Some(-1)
61"name_05:opt_i32=null"          # None
62"name_06:opt_unit=''"           # Some(())
63"name_07:opt_unit=null"         # None
64"name_08:opt_string='a value'"  # Some("a value".to_string())
65"name_09:opt_string='null'"     # Some("null".to_string())
66"name_10:opt_string=null"       # None
67"#,
68        Key::Account(AccountHash::new(array)).to_formatted_string(),
69        Key::Hash(array).to_formatted_string(),
70        Key::URef(URef::new(array, AccessRights::NONE)).to_formatted_string(),
71        AccountHash::new(array).to_formatted_string(),
72        URef::new(array, AccessRights::READ_ADD_WRITE).to_formatted_string(),
73        PublicKey::from_hex("0119bf44096984cdfe8541bac167dc3b96c85086aa30b6b6cb0c5c38ad703166e1")
74            .unwrap()
75            .to_hex(),
76        base16::encode_lower(&bytes),
77    )
78}