-
Notifications
You must be signed in to change notification settings - Fork 18
/
cli.rs
155 lines (127 loc) · 5.79 KB
/
cli.rs
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Tuxedo Template Wallet's Command Line Interface.
//!
//! Built with clap's derive macros.
use std::path::PathBuf;
use clap::{ArgAction::Append, Args, Parser, Subcommand};
use sp_core::H256;
use tuxedo_core::types::OutputRef;
use crate::{h256_from_string, keystore::SHAWN_PUB_KEY, output_ref_from_string, DEFAULT_ENDPOINT};
/// The default number of coins to be minted.
pub const DEFAULT_MINT_VALUE: &str = "100";
/// The wallet's main CLI struct
#[derive(Debug, Parser)]
#[command(about, version)]
pub struct Cli {
#[arg(long, short, default_value_t = DEFAULT_ENDPOINT.to_string())]
/// RPC endpoint of the node that this wallet will connect to.
pub endpoint: String,
#[arg(long, short('d'))]
/// Path where the wallet data is stored. Default value is platform specific.
pub base_path: Option<PathBuf>,
#[arg(long, verbatim_doc_comment)]
/// Skip the initial sync that the wallet typically performs with the node.
/// The wallet will use the latest data it had previously synced.
pub no_sync: bool,
#[arg(long)]
/// A temporary directory will be created to store the configuration and will be deleted at the end of the process.
/// path will be ignored if this is set.
pub tmp: bool,
#[arg(long, verbatim_doc_comment)]
/// Specify a development wallet instance, using a temporary directory (like --tmp).
/// The keystore will contain the development key Shawn.
pub dev: bool,
/// Use the Parachain template encoding instead of the regular node template encoding.
#[arg(long, short, verbatim_doc_comment)]
pub parachain: bool,
#[command(subcommand)]
pub command: Option<Command>,
}
/// The tasks supported by the wallet
#[derive(Debug, Subcommand)]
pub enum Command {
/// Demonstrate creating an amoeba and performing mitosis on it.
AmoebaDemo,
/// Mint coins , optionally amount and publicKey of owner can be passed
/// if amount is not passed , 100 coins are minted
/// If publickKey of owner is not passed , then by default SHAWN_PUB_KEY is used.
#[command(verbatim_doc_comment)]
MintCoins(MintCoinArgs),
/// Verify that a particular coin exists.
/// Show its value and owner from both chain storage and the local database.
#[command(verbatim_doc_comment)]
VerifyCoin {
/// A hex-encoded output reference
#[arg(value_parser = output_ref_from_string)]
output_ref: OutputRef,
},
/// Spend some coins.
/// For now, all outputs in a single transaction go to the same recipient.
// FixMe: #62
#[command(verbatim_doc_comment)]
SpendCoins(SpendArgs),
/// Insert a private key into the keystore to later use when signing transactions.
InsertKey {
/// Seed phrase of the key to insert.
seed: String,
// /// Height from which the blockchain should be scanned to sync outputs
// /// belonging to this address. If non is provided, no re-syncing will
// /// happen and this key will be treated like a new key.
// sync_height: Option<u32>,
},
/// Generate a private key using either some or no password and insert into the keystore.
GenerateKey {
/// Initialize a public/private key pair with a password
password: Option<String>,
},
/// Show public information about all the keys in the keystore.
ShowKeys,
/// Remove a specific key from the keystore.
/// WARNING! This will permanently delete the private key information.
/// Make sure your keys are backed up somewhere safe.
#[command(verbatim_doc_comment)]
RemoveKey {
/// The public key to remove
#[arg(value_parser = h256_from_string)]
pub_key: H256,
},
/// For each key tracked by the wallet, shows the sum of all UTXO values owned by that key.
/// This sum is sometimes known as the "balance".
#[command(verbatim_doc_comment)]
ShowBalance,
/// Show the complete list of UTXOs known to the wallet.
ShowAllOutputs,
/// Show the latest on-chain timestamp.
ShowTimestamp,
}
#[derive(Debug, Args)]
pub struct MintCoinArgs {
/// Pass the amount to be minted.
#[arg(long, short, verbatim_doc_comment, action = Append,default_value = DEFAULT_MINT_VALUE)]
pub amount: u128,
// https://docs.rs/clap/latest/clap/_derive/_cookbook/typed_derive/index.html
// shows how to specify a custom parsing function
/// Hex encoded address (sr25519 pubkey) of the owner.
#[arg(long, short, verbatim_doc_comment, value_parser = h256_from_string, default_value = SHAWN_PUB_KEY)]
pub owner: H256,
}
#[derive(Debug, Args)]
pub struct SpendArgs {
/// An input to be consumed by this transaction. This argument may be specified multiple times.
/// They must all be coins.
#[arg(long, short, verbatim_doc_comment, value_parser = output_ref_from_string)]
pub input: Vec<OutputRef>,
// /// All inputs to the transaction will be from this same sender.
// /// When not specified, inputs from any owner are chosen indiscriminantly
// #[arg(long, short, value_parser = h256_from_string)]
// sender: Option<H256>,
// https://docs.rs/clap/latest/clap/_derive/_cookbook/typed_derive/index.html
// shows how to specify a custom parsing function
/// Hex encoded address (sr25519 pubkey) of the recipient.
#[arg(long, short, verbatim_doc_comment, value_parser = h256_from_string, default_value = SHAWN_PUB_KEY)]
pub recipient: H256,
// The `action = Append` allows us to accept the same value multiple times.
/// An output amount. For the transaction to be valid, the outputs must add up to less than the sum of the inputs.
/// The wallet will not enforce this and will gladly send an invalid which will then be rejected by the node.
#[arg(long, short, verbatim_doc_comment, action = Append)]
pub output_amount: Vec<u128>,
}