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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
pub mod alias;
pub mod arg_parsing;
pub mod asset;
pub mod bindings;
pub mod build;
pub mod deploy;
pub mod extend;
pub mod fetch;
pub mod id;
pub mod info;
pub mod init;
pub mod inspect;
pub mod invoke;
pub mod optimize;
pub mod read;
pub mod restore;
pub mod spec_verify;
pub mod upload;
use crate::{commands::global, print::Print, utils::deprecate_message};
#[derive(Debug, clap::Subcommand)]
pub enum Cmd {
/// Utilities to deploy a Stellar Asset Contract or get its id
#[command(subcommand)]
Asset(asset::Cmd),
/// Utilities to manage contract aliases
#[command(subcommand)]
Alias(alias::Cmd),
/// Generate code client bindings for a contract
#[command(subcommand)]
Bindings(bindings::Cmd),
Build(build::Cmd),
/// Extend the time to live ledger of a contract-data ledger entry.
///
/// If no keys are specified the contract itself is extended.
Extend(extend::Cmd),
/// Deploy a wasm contract
Deploy(deploy::wasm::Cmd),
/// Fetch a contract's Wasm binary
Fetch(fetch::Cmd),
/// Generate the contract id for a given contract or asset
#[command(subcommand)]
Id(id::Cmd),
/// Access info about contracts
#[command(subcommand)]
Info(info::Cmd),
/// Initialize a Soroban contract project.
///
/// This command will create a Cargo workspace project and add a sample Stellar contract.
/// The name of the contract can be specified by `--name`. It can be run multiple times
/// with different names in order to generate multiple contracts, and files won't
/// be overwritten unless `--overwrite` is passed.
Init(init::Cmd),
/// ⚠️ Deprecated, use `contract info`. Inspect a WASM file listing contract functions, meta, etc
#[command(display_order = 100)]
Inspect(inspect::Cmd),
/// Install a WASM file to the ledger without creating a contract instance
Upload(upload::Cmd),
/// ⚠️ Deprecated, use `contract upload`. Install a WASM file to the ledger without creating a contract instance
Install(upload::Cmd),
/// Invoke a contract function
///
/// Generates an "implicit CLI" for the specified contract on-the-fly using the contract's
/// schema, which gets embedded into every Soroban contract. The "slop" in this command,
/// everything after the `--`, gets passed to this implicit CLI. Get in-depth help for a given
/// contract:
///
/// stellar contract invoke ... -- --help
Invoke(invoke::Cmd),
/// ⚠️ Deprecated, use `build --optimize`. Optimize a WASM file
Optimize(optimize::Cmd),
/// Print the current value of a contract-data ledger entry
Read(read::Cmd),
/// Restore an evicted value for a contract-data legder entry.
///
/// If no keys are specificed the contract itself is restored.
Restore(restore::Cmd),
/// Verify that a contract spec references only defined types
// Hidden because it's unclear if this makes sense as a general subcommand
// to offer, but during the development of features relating to specs it has
// been helpful to have it as its own command. Verification is automatically
// run as part of `contract build` so for a general user this is not needed.
#[command(name = "spec-verify", hide = true)]
SpecVerify(spec_verify::Cmd),
}
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Asset(#[from] asset::Error),
#[error(transparent)]
Alias(#[from] alias::Error),
#[error(transparent)]
Bindings(#[from] bindings::Error),
#[error(transparent)]
Build(#[from] build::Error),
#[error(transparent)]
Extend(#[from] extend::Error),
#[error(transparent)]
Deploy(#[from] deploy::wasm::Error),
#[error(transparent)]
Fetch(#[from] fetch::Error),
#[error(transparent)]
Init(#[from] init::Error),
#[error(transparent)]
Id(#[from] id::Error),
#[error(transparent)]
Info(#[from] info::Error),
#[error(transparent)]
Inspect(#[from] inspect::Error),
#[error(transparent)]
Install(#[from] upload::Error),
#[error(transparent)]
Invoke(#[from] invoke::Error),
#[error(transparent)]
Optimize(#[from] optimize::Error),
#[error(transparent)]
Read(#[from] read::Error),
#[error(transparent)]
Restore(#[from] restore::Error),
#[error(transparent)]
SpecVerify(#[from] spec_verify::Error),
}
impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let print = Print::new(global_args.quiet);
match &self {
Cmd::Asset(asset) => asset.run(global_args).await?,
Cmd::Bindings(bindings) => bindings.run().await?,
Cmd::Build(build) => {
build.run(global_args)?;
}
Cmd::Extend(extend) => extend.run(global_args).await?,
Cmd::Alias(alias) => alias.run(global_args)?,
Cmd::Deploy(deploy) => deploy.run(global_args).await?,
Cmd::Id(id) => id.run().await?,
Cmd::Info(info) => info.run(global_args).await?,
Cmd::Init(init) => init.run(global_args)?,
Cmd::Inspect(inspect) => {
deprecate_message(
print,
"stellar contract inspect",
"Use `stellar contract info` instead.",
);
inspect.run()?;
}
Cmd::Install(install) => {
deprecate_message(
print,
"stellar contract install",
"Use `stellar contract upload` instead.",
);
install.run(global_args).await?;
}
Cmd::Upload(upload) => upload.run(global_args).await?,
Cmd::Invoke(invoke) => invoke.run(global_args).await?,
Cmd::Optimize(optimize) => {
deprecate_message(
print,
"stellar contract optimize",
"Use `stellar contract build --optimize` instead.",
);
optimize.run()?;
}
Cmd::Fetch(fetch) => fetch.run().await?,
Cmd::Read(read) => read.run().await?,
Cmd::Restore(restore) => restore.run(global_args).await?,
Cmd::SpecVerify(spec_verify) => spec_verify.run(global_args)?,
}
Ok(())
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum)]
pub enum Durability {
/// Persistent
Persistent,
/// Temporary
Temporary,
}
impl From<&Durability> for crate::xdr::ContractDataDurability {
fn from(d: &Durability) -> Self {
match d {
Durability::Persistent => crate::xdr::ContractDataDurability::Persistent,
Durability::Temporary => crate::xdr::ContractDataDurability::Temporary,
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum)]
pub enum SpecOutput {
/// XDR of array of contract spec entries
XdrBase64,
/// Array of xdr of contract spec entries
XdrBase64Array,
/// Pretty print of contract spec entries
Docs,
}