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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
use clap::{crate_version, Arg, ArgGroup, Command};
use clockwork_thread_program::state::{SerializableInstruction, Trigger};
use clockwork_webhook_program::state::HttpMethod;
use solana_sdk::{pubkey::Pubkey, signature::Keypair};
use crate::parser::ProgramInfo;
#[derive(Debug, PartialEq)]
pub enum CliCommand {
// Config commands
ConfigGet,
ConfigSet {
admin: Option<Pubkey>,
epoch_thread: Option<Pubkey>,
hasher_thread: Option<Pubkey>,
},
// Crontab
Crontab {
schedule: String,
},
// Delegation
DelegationCreate {
worker_id: u64,
},
DelegationDeposit {
amount: u64,
delegation_id: u64,
worker_id: u64,
},
DelegationGet {
delegation_id: u64,
worker_id: u64,
},
DelegationWithdraw {
amount: u64,
delegation_id: u64,
worker_id: u64,
},
ExplorerGetThread {
id: Option<String>,
address: Option<Pubkey>,
},
Initialize {
mint: Pubkey,
},
// Localnet commands
Localnet {
force_init: bool,
clone_addresses: Vec<Pubkey>,
network_url: Option<String>,
program_infos: Vec<ProgramInfo>,
solana_archive: Option<String>,
clockwork_archive: Option<String>,
dev: bool,
},
// Pool commands
PoolGet {
id: u64,
},
PoolList {},
PoolUpdate {
id: u64,
size: usize,
},
// TODO Rename to Version. Use flags to filter by program.
// Default to listing all deployed program versions on the user's configured cluster.
ThreadCrateInfo,
// Thread commands
ThreadCreate {
id: String,
kickoff_instruction: SerializableInstruction,
trigger: Trigger,
},
ThreadDelete {
id: String,
},
ThreadGet {
id: Option<String>,
address: Option<Pubkey>,
},
ThreadPause {
id: String,
},
ThreadResume {
id: String,
},
ThreadReset {
id: String,
},
ThreadUpdate {
id: String,
rate_limit: Option<u64>,
schedule: Option<String>,
},
// Registry
RegistryGet,
RegistryUnlock,
// Secrets
SecretApprove {
name: String,
delegate: Pubkey,
},
SecretCreate {
name: String,
word: String,
},
SecretGet {
name: String,
},
SecretList {},
SecretRevoke {
name: String,
delegate: Pubkey,
},
// Webhook
WebhookCreate {
body: Vec<u8>,
id: Vec<u8>,
method: HttpMethod,
url: String,
},
WebhookGet {
id: Vec<u8>,
},
// Worker commands
WorkerCreate {
signatory: Keypair,
},
WorkerGet {
id: u64,
},
WorkerUpdate {
id: u64,
signatory: Option<Keypair>,
},
}
pub fn app() -> Command<'static> {
Command::new("Clockwork")
.bin_name("clockwork")
.about("An automation engine for the Solana blockchain")
.version(crate_version!())
.arg_required_else_help(true)
.subcommand(
Command::new("config")
.about("Manage the Clockwork network config")
.arg_required_else_help(true)
.subcommand(Command::new("get").about("Get a config value"))
.subcommand(
Command::new("set")
.about("Set a config value")
.arg(
Arg::new("admin")
.long("admin")
.value_name("ADDRESS")
.takes_value(true),
)
.arg(
Arg::new("epoch_thread")
.long("epoch_thread")
.value_name("ADDRESS")
.takes_value(true),
)
.arg(
Arg::new("hasher_thread")
.long("hasher_thread")
.value_name("ADDRESS")
.takes_value(true),
)
.group(
ArgGroup::new("config_settings")
.args(&["admin", "epoch_thread", "hasher_thread"])
.multiple(true),
),
),
)
.subcommand(
Command::new("crontab")
.about("Generate a cron firing table from schedule")
.arg_required_else_help(true)
.arg(
Arg::new("schedule")
.index(1)
.takes_value(true)
.required(true)
.help("The schedule to generate a cron table for"),
),
)
.subcommand(
Command::new("delegation")
.about("Manage a stake delegation to a Clockwork worker")
.subcommand(
Command::new("create")
.about("Create a new delegation")
.arg_required_else_help(true)
.arg(
Arg::new("worker_id")
.long("worker_id")
.short('w')
.takes_value(true)
.required(false)
.help("The ID of the worker to create a delegation with"),
),
)
.subcommand(
Command::new("deposit")
.about("Deposit CLOCK to a delegation account")
.arg_required_else_help(true)
.arg(
Arg::new("amount")
.long("amount")
.short('a')
.takes_value(true)
.required(false)
.help("The number of tokens to deposit"),
)
.arg(
Arg::new("delegation_id")
.long("delegation_id")
.short('i')
.takes_value(true)
.required(false)
.help("The ID of the delegation to deposit into"),
)
.arg(
Arg::new("worker_id")
.long("worker_id")
.short('w')
.takes_value(true)
.required(false)
.help("The ID of the worker"),
),
)
.subcommand(
Command::new("get")
.about("Get a delegation")
.arg_required_else_help(true)
.arg(
Arg::new("delegation_id")
.long("delegation_id")
.short('i')
.takes_value(true)
.required(false)
.help("The ID of the delegation"),
)
.arg(
Arg::new("worker_id")
.long("worker_id")
.short('w')
.takes_value(true)
.required(false)
.help("The ID of the worker"),
),
)
.subcommand(
Command::new("withdraw")
.about("Withdraw CLOCK from a delegation account")
.arg_required_else_help(true)
.arg(
Arg::new("amount")
.long("amount")
.short('a')
.takes_value(true)
.required(false)
.help("The number of tokens to withdraw"),
)
.arg(
Arg::new("delegation_id")
.long("delegation_id")
.short('i')
.takes_value(true)
.required(false)
.help("The ID of the delegation to withdraw from"),
)
.arg(
Arg::new("worker_id")
.long("worker_id")
.short('w')
.takes_value(true)
.required(false)
.help("The ID of the worker"),
),
),
)
.subcommand(
Command::new("explorer")
.about("Prints Explorer Urls")
.arg_required_else_help(true)
.subcommand(
Command::new("get")
.about("Prints thread explorer url")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The label of the thread to lookup (only works if you \
are the signer of that thread)")
)
.arg(
Arg::new("address")
.short('k')
.long("address")
.takes_value(true)
.help("The address of the thread to lookup"),
),
)
)
.subcommand(
Command::new("initialize")
.about("Initialize the Clockwork network program")
.arg(
Arg::new("mint")
.long("mint")
.short('m')
.takes_value(true)
.required(true)
.help("Mint address of network token"),
),
)
.subcommand(
Command::new("localnet")
.about("Launch a local Clockwork worker for app development and testing")
.arg(
Arg::with_name("bpf_program")
.long("bpf-program")
.value_names(&["ADDRESS_OR_KEYPAIR", "BPF_PROGRAM.SO"])
.takes_value(true)
.number_of_values(2)
.multiple(true)
.help(
"Add a BPF program to the genesis configuration. \
If the ledger already exists then this parameter is silently ignored. \
First argument can be a pubkey string or path to a keypair",
),
)
.arg(
Arg::with_name("clone")
.long("clone")
.short('c')
.value_names(&["ADDRESS"])
.takes_value(true)
.number_of_values(1)
.multiple(true)
.help("Copy an account from the cluster referenced by the --url argument the genesis configuration. If the ledger already exists then this parameter is silently ignored")
)
.arg(
Arg::with_name("url")
.long("url")
.short('u')
.value_names(&["URL_OR_MONIKER"])
.takes_value(true)
.number_of_values(1)
.multiple(false)
.help("URL for Solana's JSON RPC or moniker (or their first letter): [mainnet-beta, testnet, devnet, localhost]")
)
.arg(Arg::with_name("force_init")
.long("force-init")
.help("Initializes and downloads localnet dependencies")
)
.arg(
Arg::with_name("solana_archive")
.long("solana-archive")
.help("url or local path to the solana archive containing the necessary \
dependencies such as solana-test-validator. \
Can be useful for debugging or testing different versions of solana-test-validator
")
.takes_value(true),
)
.arg(
Arg::with_name("clockwork_archive")
.long("clockwork-archive")
.help("url or local path to the solana archive containing the necessary \
dependencies such as clocwkork-thread-program, etc. \
Can be useful for debugging or testing different versions of clockwork releases
")
.takes_value(true),
)
.arg(
Arg::with_name("dev")
.long("dev")
.help("Use development versions of clockwork programs")
)
)
.subcommand(
Command::new("pool")
.about("Manage the Clockwork network worker pools")
.subcommand(
Command::new("get")
.about("Get a pool")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The ID of the pool to lookup"),
),
)
.subcommand(Command::new("list").about("List the pools"))
.subcommand(
Command::new("update")
.about("Update a pool")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The ID of the pool to update"),
)
.arg(
Arg::new("size")
.long("size")
.short('s')
.takes_value(true)
.required(false)
.help("The size of the pool"),
),
),
)
.subcommand(
Command::new("secret")
.about("Manage your secrets")
.arg_required_else_help(true)
.subcommand(
Command::new("approve")
.about("Approve a new delegate to use a secret")
.arg(
Arg::new("name")
.long("name")
.short('n')
.value_name("NAME")
.takes_value(true)
.required(true)
.help("The name of the secret")
)
.arg(
Arg::new("delegate")
.long("delegate")
.short('d')
.value_name("PUBKEY")
.takes_value(true)
.required(true)
.help("The delegate to approve")
)
)
.subcommand(
Command::new("list")
.about("List your secrets")
)
.subcommand(
Command::new("create")
.about("Save a new secret")
.arg(
Arg::new("word")
.long("word")
.short('w')
.value_name("WORD")
.takes_value(true)
.required(true)
.help("The secret word to securely save")
)
.arg(
Arg::new("name")
.long("name")
.short('n')
.value_name("NAME")
.takes_value(true)
.required(true)
.help("The name of the secret")
)
)
.subcommand(
Command::new("get")
.about("Retrieve a previously saved secret")
.arg(
Arg::new("name")
.long("name")
.short('n')
.value_name("NAME")
.takes_value(true)
.required(true)
.help("The name of the secret")
)
)
.subcommand(
Command::new("revoke")
.about("Revoke a delegate's approval to use a secret")
.arg(
Arg::new("name")
.long("name")
.short('n')
.value_name("NAME")
.takes_value(true)
.required(true)
.help("The name of the secret")
)
.arg(
Arg::new("delegate")
.long("delegate")
.short('d')
.value_name("PUBKEY")
.takes_value(true)
.required(true)
.help("The delegate to revoke approval from")
)
)
)
.subcommand(
Command::new("thread")
.about("Manage your transaction threads")
.arg_required_else_help(true)
.subcommand(
Command::new("crate-info")
.about("Crate Information")
)
.subcommand(
Command::new("create")
.about("Create an new thread")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.long("id")
.short('i')
.value_name("ID")
.takes_value(true)
.required(true)
.help("The ID of the thread to be created"),
)
.arg(
Arg::new("kickoff_instruction")
.long("kickoff_instruction")
.short('k')
.value_name("FILEPATH")
.takes_value(true)
.required(true)
.help("Filepath to a description of the kickoff instruction"),
)
.arg(
Arg::new("account")
.long("account")
.short('a')
.value_name("ADDRESS")
.takes_value(true)
.help("An account-based trigger"),
)
.arg(
Arg::new("cron")
.long("cron")
.short('c')
.value_name("SCHEDULE")
.takes_value(true)
.help("A cron-based trigger"),
)
.arg(
Arg::new("immediate")
.long("immediate")
.short('m')
.takes_value(false)
.help("An immediate trigger"),
)
.group(
ArgGroup::new("trigger")
.args(&["account", "cron", "immediate"])
.required(true),
),
)
.subcommand(
Command::new("delete")
.about("Delete a thread")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The id of the thread to delete"),
),
)
.subcommand(
Command::new("get")
.about("Lookup a thread")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The label of the thread to lookup (only works if you \
are the signer of that thread)")
)
.arg(
Arg::new("address")
.short('k')
.long("address")
.takes_value(true)
.help("The address of the thread to lookup"),
)
)
.subcommand(
Command::new("pause")
.about("Pause a thread")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The id of the thread to pause"),
),
)
.subcommand(
Command::new("resume").about("Resume a thread").arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The id of the thread to resume"),
),
)
.subcommand(
Command::new("reset").about("Reset a thread").arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The id of the thread to stop"),
),
)
.subcommand(
Command::new("update")
.about("Update a property of a thread")
.arg_required_else_help(true)
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(false)
.help("The id of the thread to lookup"),
)
.arg(
Arg::new("rate_limit")
.long("rate_limit")
.short('r')
.takes_value(true)
.required(false)
.help(
"The maximum number of instructions this thread can execute per slot",
),
)
.arg(
Arg::new("schedule")
.long("schedule")
.short('s')
.takes_value(true)
.required(false)
.help("The cron schedule of the thread"),
),
),
)
.subcommand(
Command::new("registry")
.about("Manage the Clockwork network registry")
.arg_required_else_help(true)
.subcommand(Command::new("get").about("Lookup the registry"))
.subcommand(Command::new("unlock").about("Manually unlock the registry")),
)
.subcommand(
Command::new("snapshot")
.about("Lookup the current Clockwork network registry")
)
.subcommand(
Command::new("webhook")
.about("Manage your webhooks")
.arg_required_else_help(true)
.subcommand(
Command::new("create")
.about("Create a new webhook")
.arg(
Arg::new("body")
.long("body")
.short('b')
.value_name("VALUE")
.takes_value(true)
.required(false)
.help("The body of the request")
)
.arg(
Arg::new("id")
.long("id")
.short('i')
.value_name("ID")
.takes_value(true)
.required(true)
.help("The id of the webhook")
)
.arg(
Arg::new("method")
.long("method")
.short('m')
.value_name("GET|POST")
.takes_value(true)
.required(true)
.help("The http method to use")
)
.arg(
Arg::new("url")
.long("url")
.short('u')
.value_name("URL")
.takes_value(true)
.required(true)
.help("The url to send the webhook to")
)
)
.subcommand(
Command::new("get")
.about("Lookup a webhook")
.arg(
Arg::new("id")
.long("id")
.short('i')
.value_name("ID")
.takes_value(true)
.required(true)
.help("The id of the webhook")
)
)
)
.subcommand(
Command::new("worker")
.about("Manage your workers")
.arg_required_else_help(true)
.subcommand(
Command::new("create")
.about("Register a new worker with the Clockwork network")
.arg(
Arg::new("signatory_keypair")
.index(1)
.takes_value(true)
.required(true)
.help("Filepath to the worker's signatory keypair"),
),
)
.subcommand(
Command::new("get")
.about("Lookup a worker on the Clockwork network")
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(true)
.help("The ID of the worker to lookup"),
),
)
.subcommand(
Command::new("update")
.about("Update a new worker")
.arg(
Arg::new("id")
.index(1)
.takes_value(true)
.required(true)
.help("The ID of the worker to edit"),
)
.arg(
Arg::new("signatory_keypair")
.long("signatory_keypair")
.short('k')
.takes_value(true)
.required(false)
.help("Filepath to the worker's new signatory keypair"),
),
),
)
}