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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
use crate::{
client_proxy::ClientProxy,
commands::{subcommand_execute, Command},
};
use chrono::{DateTime, Utc};
use diem_types::waypoint::Waypoint;
use std::time::{Duration, UNIX_EPOCH};
pub struct DevCommand {}
impl Command for DevCommand {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["dev", "d"]
}
fn get_description(&self) -> &'static str {
"Local Move development"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
let commands: Vec<Box<dyn Command>> = vec![
Box::new(DevCommandCompile {}),
Box::new(DevCommandPublish {}),
Box::new(DevCommandExecute {}),
Box::new(DevCommandUpgradeStdlib {}),
Box::new(DevCommandGenWaypoint {}),
Box::new(DevCommandChangeDiemVersion {}),
Box::new(DevCommandEnableCustomScript {}),
Box::new(DevSubmitWriteSet {}),
];
subcommand_execute(params[0], commands, client, ¶ms[1..]);
}
}
pub struct DevCommandCompile {}
impl Command for DevCommandCompile {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["compile", "c"]
}
fn get_params_help(&self) -> &'static str {
"<sender_account_address>|<sender_account_ref_id> <file_path> <dependency_source_files...>"
}
fn get_description(&self) -> &'static str {
"Compile Move program"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() < 3 {
println!("Invalid number of arguments for compilation");
return;
}
println!(">> Compiling program");
match client.compile_program(params) {
Ok(paths) => {
println!("Successfully compiled a program at:");
for p in paths {
println!(" {}", p);
}
}
Err(e) => println!("{}", e),
}
}
}
pub struct DevCommandPublish {}
impl Command for DevCommandPublish {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["publish", "p"]
}
fn get_params_help(&self) -> &'static str {
"<sender_account_address>|<sender_account_ref_id> <compiled_module_path>"
}
fn get_description(&self) -> &'static str {
"Publish Move module on-chain"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() != 3 {
println!("Invalid number of arguments to publish module");
return;
}
match client.publish_module(params) {
Ok(_) => println!("Successfully published module"),
Err(e) => println!("{}", e),
}
}
}
pub struct DevCommandExecute {}
impl Command for DevCommandExecute {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["execute", "e"]
}
fn get_params_help(&self) -> &'static str {
"<sender_account_address>|<sender_account_ref_id> <compiled_module_path> [parameters]"
}
fn get_description(&self) -> &'static str {
"Execute custom Move script"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() < 3 {
println!("Invalid number of arguments to execute script");
return;
}
match client.execute_script(params) {
Ok(_) => println!("Successfully finished execution"),
Err(e) => println!("{}", e),
}
}
}
pub struct DevCommandEnableCustomScript {}
impl Command for DevCommandEnableCustomScript {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["enable_custom_script", "s"]
}
fn get_params_help(&self) -> &'static str {
""
}
fn get_description(&self) -> &'static str {
"Allow executing arbitrary script in the network. This disables script hash verification."
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() != 1 {
println!("Invalid number of arguments");
return;
}
match client.enable_custom_script(params, false, true) {
Ok(_) => println!("Successfully finished execution"),
Err(e) => println!("{}", e),
}
}
}
pub struct DevCommandChangeDiemVersion {}
impl Command for DevCommandChangeDiemVersion {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["change_diem_version", "v"]
}
fn get_params_help(&self) -> &'static str {
"<new_diem_version>"
}
fn get_description(&self) -> &'static str {
"Change the diem_version stored on chain"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() != 2 {
println!("Invalid number of arguments");
return;
}
match client.change_diem_version(params, true) {
Ok(_) => println!("Successfully finished execution"),
Err(e) => println!("{}", e),
}
}
}
pub struct DevCommandUpgradeStdlib {}
impl Command for DevCommandUpgradeStdlib {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["upgrade_stdlib", "u"]
}
fn get_params_help(&self) -> &'static str {
""
}
fn get_description(&self) -> &'static str {
"Upgrade the move stdlib used for the blockchain"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() != 1 {
println!("Invalid number of arguments");
return;
}
match client.upgrade_stdlib(params, true) {
Ok(_) => println!("Successfully finished execution"),
Err(e) => println!("{}", e),
}
}
}
pub struct DevCommandGenWaypoint {}
impl Command for DevCommandGenWaypoint {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["gen_waypoint", "g"]
}
fn get_params_help(&self) -> &'static str {
""
}
fn get_description(&self) -> &'static str {
"Generate a waypoint for the latest epoch change LedgerInfo"
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() != 1 {
println!("No parameters required for waypoint generation");
return;
}
println!("Retrieving the uptodate ledger info...");
if let Err(e) = client.test_validator_connection() {
println!("Failed to get uptodate ledger info connection: {}", e);
return;
}
let latest_epoch_change_li = match client.latest_epoch_change_li() {
Some(li) => li,
None => {
println!("No epoch change LedgerInfo found");
return;
}
};
let li_time_str = DateTime::<Utc>::from(
UNIX_EPOCH
+ Duration::from_micros(latest_epoch_change_li.ledger_info().timestamp_usecs()),
);
match Waypoint::new_epoch_boundary(latest_epoch_change_li.ledger_info()) {
Err(e) => println!("Failed to generate a waypoint: {}", e),
Ok(waypoint) => println!(
"Waypoint (end of epoch {}, time {}): {}",
latest_epoch_change_li.ledger_info().epoch(),
li_time_str,
waypoint
),
}
}
}
pub struct DevSubmitWriteSet {}
impl Command for DevSubmitWriteSet {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["submit_writeset", "ws"]
}
fn get_params_help(&self) -> &'static str {
"<path_to_writeset>"
}
fn get_description(&self) -> &'static str {
"Submit a WriteSet with local diem root account. Path should be a bcs serialized TransactionPayload."
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() < 2 {
println!("Invalid number of arguments to execute script");
return;
}
match client.submit_writeset(params) {
Ok(_) => println!("Successfully finished execution"),
Err(e) => println!("{}", e),
}
}
}