solana_clap_utils/
nonce.rs1use {
2 crate::{input_validators::*, offline::BLOCKHASH_ARG, ArgConstant},
3 clap::{App, Arg},
4};
5
6pub const NONCE_ARG: ArgConstant<'static> = ArgConstant {
7 name: "nonce",
8 long: "nonce",
9 help: "Provide the nonce account to use when creating a nonced \n\
10 transaction. Nonced transactions are useful when a transaction \n\
11 requires a lengthy signing process. Learn more about nonced \n\
12 transactions at https://docs.solanalabs.com/cli/examples/durable-nonce",
13};
14
15pub const NONCE_AUTHORITY_ARG: ArgConstant<'static> = ArgConstant {
16 name: "nonce_authority",
17 long: "nonce-authority",
18 help: "Provide the nonce authority keypair to use when signing a nonced transaction",
19};
20
21fn nonce_arg<'a, 'b>() -> Arg<'a, 'b> {
22 Arg::with_name(NONCE_ARG.name)
23 .long(NONCE_ARG.long)
24 .takes_value(true)
25 .value_name("PUBKEY")
26 .requires(BLOCKHASH_ARG.name)
27 .validator(is_valid_pubkey)
28 .help(NONCE_ARG.help)
29}
30
31pub fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
32 Arg::with_name(NONCE_AUTHORITY_ARG.name)
33 .long(NONCE_AUTHORITY_ARG.long)
34 .takes_value(true)
35 .value_name("KEYPAIR")
36 .validator(is_valid_signer)
37 .help(NONCE_AUTHORITY_ARG.help)
38}
39
40pub trait NonceArgs {
41 fn nonce_args(self, global: bool) -> Self;
42}
43
44impl NonceArgs for App<'_, '_> {
45 fn nonce_args(self, global: bool) -> Self {
46 self.arg(nonce_arg().global(global)).arg(
47 nonce_authority_arg()
48 .requires(NONCE_ARG.name)
49 .global(global),
50 )
51 }
52}