-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcli.rs
More file actions
9290 lines (8353 loc) · 333 KB
/
cli.rs
File metadata and controls
9290 lines (8353 loc) · 333 KB
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
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! The CLI commands that are re-used between the executables `namada`,
//! `namada-node` and `namada-client`.
//!
//! The `namada` executable groups together the most commonly used commands
//! inlined from the node and the client. The other commands for the node or the
//! client can be dispatched via `namada node ...` or `namada client ...`,
//! respectively.
pub mod api;
pub mod client;
pub mod context;
pub mod relayer;
mod utils;
pub mod wallet;
use clap::{ArgGroup, ArgMatches, ColorChoice};
use color_eyre::eyre::Result;
use namada_sdk::io::StdIo;
use utils::*;
pub use utils::{Cmd, safe_exit};
pub use self::context::Context;
use crate::cli::api::CliIo;
const APP_NAME: &str = "Namada";
// Main Namada sub-commands
const NODE_CMD: &str = "node";
const CLIENT_CMD: &str = "client";
const WALLET_CMD: &str = "wallet";
const RELAYER_CMD: &str = "relayer";
pub mod cmds {
use super::args::CliTypes;
use super::utils::*;
use super::{
ArgMatches, CLIENT_CMD, NODE_CMD, RELAYER_CMD, WALLET_CMD, args,
};
use crate::wrap;
/// Commands for `namada` binary.
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug)]
pub enum Namada {
// Sub-binary-commands
Node(NamadaNode),
Relayer(NamadaRelayer),
Client(NamadaClient),
Wallet(NamadaWallet),
// Inlined commands from the node.
Ledger(Ledger),
// Inlined commands from the relayer.
EthBridgePool(EthBridgePool),
// Inlined commands from the client.
TxCustom(TxCustom),
TxTransparentTransfer(TxTransparentTransfer),
TxShieldedTransfer(TxShieldedTransfer),
TxShieldingTransfer(TxShieldingTransfer),
TxUnshieldingTransfer(TxUnshieldingTransfer),
TxIbcTransfer(TxIbcTransfer),
TxOsmosisSwap(TxOsmosisSwap),
TxUpdateAccount(TxUpdateAccount),
TxInitProposal(TxInitProposal),
TxVoteProposal(TxVoteProposal),
TxRevealPk(TxRevealPk),
// Generate CLI completions
Complete(Complete),
}
impl Cmd for Namada {
fn add_sub(app: App) -> App {
app.subcommand(NamadaNode::def().display_order(1))
.subcommand(NamadaClient::def().display_order(1))
.subcommand(NamadaWallet::def().display_order(1))
.subcommand(Ledger::def().display_order(2))
.subcommand(TxCustom::def().display_order(2))
.subcommand(TxTransparentTransfer::def().display_order(2))
.subcommand(TxShieldedTransfer::def().display_order(2))
.subcommand(TxShieldingTransfer::def().display_order(2))
.subcommand(TxUnshieldingTransfer::def().display_order(2))
.subcommand(TxIbcTransfer::def().display_order(2))
.subcommand(TxOsmosisSwap::def().display_order(2))
.subcommand(TxUpdateAccount::def().display_order(2))
.subcommand(TxInitProposal::def().display_order(2))
.subcommand(TxVoteProposal::def().display_order(2))
.subcommand(TxRevealPk::def().display_order(2))
.subcommand(Complete::def().display_order(3))
}
fn parse(matches: &ArgMatches) -> Option<Self> {
let node = SubCmd::parse(matches).map(Self::Node);
let client = SubCmd::parse(matches).map(Self::Client);
let wallet = SubCmd::parse(matches).map(Self::Wallet);
let ledger = SubCmd::parse(matches).map(Self::Ledger);
let tx_custom = SubCmd::parse(matches).map(Self::TxCustom);
let tx_transparent_transfer =
SubCmd::parse(matches).map(Self::TxTransparentTransfer);
let tx_shielded_transfer =
SubCmd::parse(matches).map(Self::TxShieldedTransfer);
let tx_shielding_transfer =
SubCmd::parse(matches).map(Self::TxShieldingTransfer);
let tx_unshielding_transfer =
SubCmd::parse(matches).map(Self::TxUnshieldingTransfer);
let tx_ibc_transfer =
SubCmd::parse(matches).map(Self::TxIbcTransfer);
let tx_osmosis_swap =
SubCmd::parse(matches).map(Self::TxOsmosisSwap);
let tx_update_account =
SubCmd::parse(matches).map(Self::TxUpdateAccount);
let tx_init_proposal =
SubCmd::parse(matches).map(Self::TxInitProposal);
let tx_vote_proposal =
SubCmd::parse(matches).map(Self::TxVoteProposal);
let tx_reveal_pk = SubCmd::parse(matches).map(Self::TxRevealPk);
let complete = SubCmd::parse(matches).map(Self::Complete);
node.or(client)
.or(wallet)
.or(ledger)
.or(tx_custom)
.or(tx_transparent_transfer)
.or(tx_shielded_transfer)
.or(tx_shielding_transfer)
.or(tx_unshielding_transfer)
.or(tx_ibc_transfer)
.or(tx_osmosis_swap)
.or(tx_update_account)
.or(tx_init_proposal)
.or(tx_vote_proposal)
.or(tx_reveal_pk)
.or(complete)
}
}
/// Used as top-level commands (`Cmd` instance) in `namadan` binary.
/// Used as sub-commands (`SubCmd` instance) in `namada` binary.
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum NamadaNode {
Ledger(Ledger),
Config(Config),
Utils(NodeUtils),
}
impl Cmd for NamadaNode {
fn add_sub(app: App) -> App {
app.subcommand(Ledger::def())
.subcommand(Config::def())
.subcommand(NodeUtils::def())
}
fn parse(matches: &ArgMatches) -> Option<Self> {
let ledger = SubCmd::parse(matches).map(Self::Ledger);
let config = SubCmd::parse(matches).map(Self::Config);
let utils = SubCmd::parse(matches).map(Self::Utils);
ledger.or(config).or(utils)
}
}
impl SubCmd for NamadaNode {
const CMD: &'static str = NODE_CMD;
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.and_then(<Self as Cmd>::parse)
}
fn def() -> App {
<Self as Cmd>::add_sub(
App::new(Self::CMD)
.about(wrap!("Node sub-commands."))
.subcommand_required(true)
.arg_required_else_help(true),
)
}
}
/// Used as top-level commands (`Cmd` instance) in `namadar` binary.
/// Used as sub-commands (`SubCmd` instance) in `namada` binary.
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum NamadaRelayer {
EthBridgePool(EthBridgePool),
ValidatorSet(ValidatorSet),
}
impl Cmd for NamadaRelayer {
fn add_sub(app: App) -> App {
app.subcommand(EthBridgePool::def())
.subcommand(ValidatorSet::def())
}
fn parse(matches: &ArgMatches) -> Option<Self> {
let eth_bridge_pool =
SubCmd::parse(matches).map(Self::EthBridgePool);
let validator_set = SubCmd::parse(matches).map(Self::ValidatorSet);
eth_bridge_pool.or(validator_set)
}
}
impl SubCmd for NamadaRelayer {
const CMD: &'static str = RELAYER_CMD;
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.and_then(<Self as Cmd>::parse)
}
fn def() -> App {
<Self as Cmd>::add_sub(
App::new(Self::CMD)
.about(wrap!("Relayer sub-commands."))
.subcommand_required(true),
)
}
}
/// Used as top-level commands (`Cmd` instance) in `namadac` binary.
/// Used as sub-commands (`SubCmd` instance) in `namada` binary.
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum NamadaClient {
/// The [`super::Context`] provides access to the wallet and the
/// config. It will generate a new wallet and config, if they
/// don't exist.
WithContext(NamadaClientWithContext),
/// Utils don't have [`super::Context`], only the global arguments.
WithoutContext(ClientUtils),
}
impl Cmd for NamadaClient {
fn add_sub(app: App) -> App {
app
// Simple transactions
.subcommand(TxCustom::def().display_order(1))
.subcommand(TxTransparentTransfer::def().display_order(1))
.subcommand(TxShieldedTransfer::def().display_order(1))
.subcommand(TxShieldingTransfer::def().display_order(1))
.subcommand(TxUnshieldingTransfer::def().display_order(1))
.subcommand(TxIbcTransfer::def().display_order(1))
.subcommand(TxOsmosisSwap::def().display_order(1))
.subcommand(TxUpdateAccount::def().display_order(1))
.subcommand(TxInitAccount::def().display_order(1))
.subcommand(TxRevealPk::def().display_order(1))
// Governance transactions
.subcommand(TxInitProposal::def().display_order(1))
.subcommand(TxVoteProposal::def().display_order(1))
// PoS transactions
.subcommand(TxBecomeValidator::def().display_order(2))
.subcommand(TxInitValidator::def().display_order(2))
.subcommand(TxUnjailValidator::def().display_order(2))
.subcommand(TxDeactivateValidator::def().display_order(2))
.subcommand(TxReactivateValidator::def().display_order(2))
.subcommand(Bond::def().display_order(2))
.subcommand(Unbond::def().display_order(2))
.subcommand(Withdraw::def().display_order(2))
.subcommand(Redelegate::def().display_order(2))
.subcommand(ClaimRewards::def().display_order(2))
.subcommand(TxCommissionRateChange::def().display_order(2))
.subcommand(TxChangeConsensusKey::def().display_order(2))
.subcommand(TxMetadataChange::def().display_order(2))
// Ethereum bridge transactions
.subcommand(AddToEthBridgePool::def().display_order(3))
// PGF transactions
.subcommand(TxUpdateStewardCommission::def().display_order(4))
.subcommand(TxResignSteward::def().display_order(4))
// Queries
.subcommand(QueryEpoch::def().display_order(5))
.subcommand(QueryNextEpochInfo::def().display_order(5))
.subcommand(QueryStatus::def().display_order(5))
.subcommand(QueryAccount::def().display_order(5))
.subcommand(QueryConversions::def().display_order(5))
.subcommand(QueryMaspRewardTokens::def().display_order(5))
.subcommand(QueryBlock::def().display_order(5))
.subcommand(QueryBalance::def().display_order(5))
.subcommand(
QueryShieldingRewardsEstimate::def().display_order(5),
)
.subcommand(QueryBonds::def().display_order(5))
.subcommand(QueryBondedStake::def().display_order(5))
.subcommand(QuerySlashes::def().display_order(5))
.subcommand(QueryDelegations::def().display_order(5))
.subcommand(QueryFindValidator::def().display_order(5))
.subcommand(QueryIbcRateLimit::def().display_order(5))
.subcommand(QueryResult::def().display_order(5))
.subcommand(QueryRawBytes::def().display_order(5))
.subcommand(QueryProposal::def().display_order(5))
.subcommand(QueryProposalVotes::def().display_order(5))
.subcommand(QueryProposalResult::def().display_order(5))
.subcommand(QueryProtocolParameters::def().display_order(5))
.subcommand(QueryPgf::def().display_order(5))
.subcommand(QueryValidatorState::def().display_order(5))
.subcommand(QueryCommissionRate::def().display_order(5))
.subcommand(QueryRewards::def().display_order(5))
.subcommand(QueryMetaData::def().display_order(5))
.subcommand(QueryTotalSupply::def().display_order(5))
.subcommand(QueryEffNativeSupply::def().display_order(5))
.subcommand(QueryStakingRewardsRate::def().display_order(5))
// Actions
.subcommand(ShieldedSync::def().display_order(6))
.subcommand(GenIbcShieldingTransfer::def().display_order(6))
// Utils
.subcommand(ClientUtils::def().display_order(7))
}
fn parse(matches: &ArgMatches) -> Option<Self> {
use NamadaClientWithContext::*;
let tx_custom = Self::parse_with_ctx(matches, TxCustom);
let tx_transparent_transfer =
Self::parse_with_ctx(matches, TxTransparentTransfer);
let tx_shielded_transfer =
Self::parse_with_ctx(matches, TxShieldedTransfer);
let tx_shielding_transfer =
Self::parse_with_ctx(matches, TxShieldingTransfer);
let tx_unshielding_transfer =
Self::parse_with_ctx(matches, TxUnshieldingTransfer);
let tx_ibc_transfer = Self::parse_with_ctx(matches, TxIbcTransfer);
let tx_osmosis_swap = Self::parse_with_ctx(matches, |cmd| {
TxOsmosisSwap(Box::new(cmd))
});
let tx_update_account =
Self::parse_with_ctx(matches, TxUpdateAccount);
let tx_init_account = Self::parse_with_ctx(matches, TxInitAccount);
let tx_become_validator =
Self::parse_with_ctx(matches, TxBecomeValidator);
let tx_init_validator =
Self::parse_with_ctx(matches, TxInitValidator);
let tx_unjail_validator =
Self::parse_with_ctx(matches, TxUnjailValidator);
let tx_deactivate_validator =
Self::parse_with_ctx(matches, TxDeactivateValidator);
let tx_reactivate_validator =
Self::parse_with_ctx(matches, TxReactivateValidator);
let tx_reveal_pk = Self::parse_with_ctx(matches, TxRevealPk);
let tx_init_proposal =
Self::parse_with_ctx(matches, TxInitProposal);
let tx_vote_proposal =
Self::parse_with_ctx(matches, TxVoteProposal);
let tx_update_steward_commission =
Self::parse_with_ctx(matches, TxUpdateStewardCommission);
let tx_resign_steward =
Self::parse_with_ctx(matches, TxResignSteward);
let tx_commission_rate_change =
Self::parse_with_ctx(matches, TxCommissionRateChange);
let tx_change_consensus_key =
Self::parse_with_ctx(matches, TxChangeConsensusKey);
let tx_change_metadata =
Self::parse_with_ctx(matches, TxMetadataChange);
let bond = Self::parse_with_ctx(matches, Bond);
let unbond = Self::parse_with_ctx(matches, Unbond);
let withdraw = Self::parse_with_ctx(matches, Withdraw);
let redelegate = Self::parse_with_ctx(matches, Redelegate);
let claim_rewards = Self::parse_with_ctx(matches, ClaimRewards);
let query_epoch = Self::parse_with_ctx(matches, QueryEpoch);
let query_next_epoch_info =
Self::parse_with_ctx(matches, QueryNextEpochInfo);
let query_status = Self::parse_with_ctx(matches, QueryStatus);
let query_account = Self::parse_with_ctx(matches, QueryAccount);
let query_conversions =
Self::parse_with_ctx(matches, QueryConversions);
let query_masp_reward_tokens =
Self::parse_with_ctx(matches, QueryMaspRewardTokens);
let query_block = Self::parse_with_ctx(matches, QueryBlock);
let query_balance = Self::parse_with_ctx(matches, QueryBalance);
let query_rewards_estimate =
Self::parse_with_ctx(matches, QueryShieldingRewardsEstimate);
let query_bonds = Self::parse_with_ctx(matches, QueryBonds);
let query_bonded_stake =
Self::parse_with_ctx(matches, QueryBondedStake);
let query_slashes = Self::parse_with_ctx(matches, QuerySlashes);
let query_rewards = Self::parse_with_ctx(matches, QueryRewards);
let query_delegations =
Self::parse_with_ctx(matches, QueryDelegations);
let query_total_supply =
Self::parse_with_ctx(matches, QueryTotalSupply);
let query_native_supply =
Self::parse_with_ctx(matches, QueryEffNativeSupply);
let query_staking_rewards_rate =
Self::parse_with_ctx(matches, QueryStakingRewardsRate);
let query_find_validator =
Self::parse_with_ctx(matches, QueryFindValidator);
let query_result = Self::parse_with_ctx(matches, QueryResult);
let query_raw_bytes = Self::parse_with_ctx(matches, QueryRawBytes);
let query_proposal = Self::parse_with_ctx(matches, QueryProposal);
let query_proposal_votes =
Self::parse_with_ctx(matches, QueryProposalVotes);
let query_proposal_result =
Self::parse_with_ctx(matches, QueryProposalResult);
let query_protocol_parameters =
Self::parse_with_ctx(matches, QueryProtocolParameters);
let query_pgf = Self::parse_with_ctx(matches, QueryPgf);
let query_validator_state =
Self::parse_with_ctx(matches, QueryValidatorState);
let query_commission =
Self::parse_with_ctx(matches, QueryCommissionRate);
let query_metadata = Self::parse_with_ctx(matches, QueryMetaData);
let query_ibc_rate_limit =
Self::parse_with_ctx(matches, QueryIbcRateLimit);
let add_to_eth_bridge_pool =
Self::parse_with_ctx(matches, AddToEthBridgePool);
let shielded_sync = Self::parse_with_ctx(matches, ShieldedSync);
let gen_ibc_shielding =
Self::parse_with_ctx(matches, GenIbcShieldingTransfer);
let utils = SubCmd::parse(matches).map(Self::WithoutContext);
tx_custom
.or(tx_transparent_transfer)
.or(tx_shielded_transfer)
.or(tx_shielding_transfer)
.or(tx_unshielding_transfer)
.or(tx_ibc_transfer)
.or(tx_osmosis_swap)
.or(tx_update_account)
.or(tx_init_account)
.or(tx_reveal_pk)
.or(tx_init_proposal)
.or(tx_vote_proposal)
.or(tx_become_validator)
.or(tx_init_validator)
.or(tx_commission_rate_change)
.or(tx_change_consensus_key)
.or(tx_change_metadata)
.or(tx_unjail_validator)
.or(tx_deactivate_validator)
.or(tx_reactivate_validator)
.or(bond)
.or(unbond)
.or(withdraw)
.or(redelegate)
.or(claim_rewards)
.or(add_to_eth_bridge_pool)
.or(tx_update_steward_commission)
.or(tx_resign_steward)
.or(query_epoch)
.or(query_next_epoch_info)
.or(query_status)
.or(query_conversions)
.or(query_masp_reward_tokens)
.or(query_block)
.or(query_balance)
.or(query_rewards_estimate)
.or(query_bonds)
.or(query_bonded_stake)
.or(query_slashes)
.or(query_rewards)
.or(query_delegations)
.or(query_find_validator)
.or(query_result)
.or(query_raw_bytes)
.or(query_proposal)
.or(query_proposal_votes)
.or(query_proposal_result)
.or(query_protocol_parameters)
.or(query_pgf)
.or(query_validator_state)
.or(query_commission)
.or(query_metadata)
.or(query_total_supply)
.or(query_native_supply)
.or(query_staking_rewards_rate)
.or(query_account)
.or(query_ibc_rate_limit)
.or(shielded_sync)
.or(gen_ibc_shielding)
.or(utils)
}
}
impl NamadaClient {
/// A helper method to parse sub cmds with context
fn parse_with_ctx<T: SubCmd>(
matches: &ArgMatches,
sub_to_self: impl Fn(T) -> NamadaClientWithContext,
) -> Option<Self> {
SubCmd::parse(matches)
.map(|sub| Self::WithContext(sub_to_self(sub)))
}
}
impl SubCmd for NamadaClient {
const CMD: &'static str = CLIENT_CMD;
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.and_then(<Self as Cmd>::parse)
}
fn def() -> App {
<Self as Cmd>::add_sub(
App::new(Self::CMD)
.about(wrap!("Client sub-commands."))
.subcommand_required(true)
.arg_required_else_help(true),
)
}
}
#[derive(Clone, Debug)]
pub enum NamadaClientWithContext {
// Ledger cmds
TxCustom(TxCustom),
TxTransparentTransfer(TxTransparentTransfer),
TxShieldedTransfer(TxShieldedTransfer),
TxShieldingTransfer(TxShieldingTransfer),
TxUnshieldingTransfer(TxUnshieldingTransfer),
TxIbcTransfer(TxIbcTransfer),
TxOsmosisSwap(Box<TxOsmosisSwap>),
QueryResult(QueryResult),
TxUpdateAccount(TxUpdateAccount),
TxInitAccount(TxInitAccount),
TxBecomeValidator(TxBecomeValidator),
TxInitValidator(TxInitValidator),
TxCommissionRateChange(TxCommissionRateChange),
TxChangeConsensusKey(TxChangeConsensusKey),
TxMetadataChange(TxMetadataChange),
TxUnjailValidator(TxUnjailValidator),
TxDeactivateValidator(TxDeactivateValidator),
TxReactivateValidator(TxReactivateValidator),
TxInitProposal(TxInitProposal),
TxVoteProposal(TxVoteProposal),
TxRevealPk(TxRevealPk),
Bond(Bond),
Unbond(Unbond),
Withdraw(Withdraw),
ClaimRewards(ClaimRewards),
Redelegate(Redelegate),
AddToEthBridgePool(AddToEthBridgePool),
TxUpdateStewardCommission(TxUpdateStewardCommission),
TxResignSteward(TxResignSteward),
QueryEpoch(QueryEpoch),
QueryNextEpochInfo(QueryNextEpochInfo),
QueryStatus(QueryStatus),
QueryAccount(QueryAccount),
QueryConversions(QueryConversions),
QueryMaspRewardTokens(QueryMaspRewardTokens),
QueryBlock(QueryBlock),
QueryBalance(QueryBalance),
QueryShieldingRewardsEstimate(QueryShieldingRewardsEstimate),
QueryBonds(QueryBonds),
QueryBondedStake(QueryBondedStake),
QueryCommissionRate(QueryCommissionRate),
QueryMetaData(QueryMetaData),
QuerySlashes(QuerySlashes),
QueryDelegations(QueryDelegations),
QueryTotalSupply(QueryTotalSupply),
QueryEffNativeSupply(QueryEffNativeSupply),
QueryStakingRewardsRate(QueryStakingRewardsRate),
QueryFindValidator(QueryFindValidator),
QueryRawBytes(QueryRawBytes),
QueryProposal(QueryProposal),
QueryProposalVotes(QueryProposalVotes),
QueryProposalResult(QueryProposalResult),
QueryProtocolParameters(QueryProtocolParameters),
QueryPgf(QueryPgf),
QueryValidatorState(QueryValidatorState),
QueryRewards(QueryRewards),
QueryIbcRateLimit(QueryIbcRateLimit),
ShieldedSync(ShieldedSync),
GenIbcShieldingTransfer(GenIbcShieldingTransfer),
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug)]
pub enum NamadaWallet {
/// Key generation
KeyGen(WalletGen),
/// Key derivation
KeyDerive(WalletDerive),
/// Payment address generation
PayAddrGen(WalletGenPaymentAddress),
/// Key / address list
KeyAddrList(WalletListKeysAddresses),
/// Key / address search
KeyAddrFind(WalletFindKeysAddresses),
/// Key export
KeyExport(WalletExportKey),
/// Key convert
KeyConvert(WalletConvertKey),
/// Key import
KeyImport(WalletImportKey),
/// Key / address add
KeyAddrAdd(WalletAddKeyAddress),
/// Key / address remove
KeyAddrRemove(WalletRemoveKeyAddress),
}
impl Cmd for NamadaWallet {
fn add_sub(app: App) -> App {
app.subcommand(WalletGen::def())
.subcommand(WalletDerive::def())
.subcommand(WalletGenPaymentAddress::def())
.subcommand(WalletListKeysAddresses::def())
.subcommand(WalletFindKeysAddresses::def())
.subcommand(WalletExportKey::def())
.subcommand(WalletConvertKey::def())
.subcommand(WalletImportKey::def())
.subcommand(WalletAddKeyAddress::def())
.subcommand(WalletRemoveKeyAddress::def())
}
fn parse(matches: &ArgMatches) -> Option<Self> {
let r#gen = SubCmd::parse(matches).map(Self::KeyGen);
let derive = SubCmd::parse(matches).map(Self::KeyDerive);
let pay_addr_gen = SubCmd::parse(matches).map(Self::PayAddrGen);
let key_addr_list = SubCmd::parse(matches).map(Self::KeyAddrList);
let key_addr_find = SubCmd::parse(matches).map(Self::KeyAddrFind);
let export = SubCmd::parse(matches).map(Self::KeyExport);
let convert = SubCmd::parse(matches).map(Self::KeyConvert);
let import = SubCmd::parse(matches).map(Self::KeyImport);
let key_addr_add = SubCmd::parse(matches).map(Self::KeyAddrAdd);
let key_addr_remove =
SubCmd::parse(matches).map(Self::KeyAddrRemove);
r#gen
.or(derive)
.or(pay_addr_gen)
.or(key_addr_list)
.or(key_addr_find)
.or(export)
.or(convert)
.or(import)
.or(key_addr_add)
.or(key_addr_remove)
}
}
impl SubCmd for NamadaWallet {
const CMD: &'static str = WALLET_CMD;
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.and_then(<Self as Cmd>::parse)
}
fn def() -> App {
<Self as Cmd>::add_sub(
App::new(Self::CMD)
.about(wrap!("Wallet sub-commands."))
.subcommand_required(true)
.arg_required_else_help(true),
)
}
}
/// In the transparent setting, generate a new keypair and an implicit
/// address derived from it. In the shielded setting, generate a new
/// spending key.
#[derive(Clone, Debug)]
pub struct WalletGen(pub args::KeyGen);
impl SubCmd for WalletGen {
const CMD: &'static str = "gen";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::KeyGen::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Generates a new transparent / shielded secret key."
))
.long_about(wrap!(
"In the transparent setting, generates a keypair with a \
given alias and derives the implicit address from its \
public key. The address will be stored with the same \
alias.\nIn the shielded setting, generates a new \
spending key with a given alias.\nIn both settings, by \
default, an HD-key with a default derivation path is \
generated, with a random mnemonic code."
))
.add_args::<args::KeyGen>()
}
}
/// In the transparent setting, derive a keypair and implicit address from
/// the mnemonic code.
/// In the shielded setting, derive a spending key from the mnemonic code.
#[derive(Clone, Debug)]
pub struct WalletDerive(pub args::KeyDerive);
impl SubCmd for WalletDerive {
const CMD: &'static str = "derive";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::KeyDerive::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Derive transparent / shielded key from the mnemonic code \
or a seed stored on the hardware wallet device."
))
.long_about(wrap!(
"In the transparent setting, derives a keypair from the \
given mnemonic code and HD derivation path and derives \
the implicit address from its public key. Stores the \
keypair and the address with the given alias.\nIn the \
shielded setting, derives a spending key.\nA hardware \
wallet can be used, in which case the private key is not \
derivable."
))
.add_args::<args::KeyDerive>()
}
}
/// List known keys and addresses
#[derive(Clone, Debug)]
pub struct WalletListKeysAddresses(pub args::KeyAddressList);
impl SubCmd for WalletListKeysAddresses {
const CMD: &'static str = "list";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| (Self(args::KeyAddressList::parse(matches))))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!("List known keys and addresses in the wallet."))
.long_about(wrap!(
"In the transparent setting, list known keypairs and \
addresses.\nIn the shielded setting, list known spending \
/ viewing keys and payment addresses."
))
.add_args::<args::KeyAddressList>()
}
}
/// Find known keys and addresses
#[derive(Clone, Debug)]
pub struct WalletFindKeysAddresses(pub args::KeyAddressFind);
impl SubCmd for WalletFindKeysAddresses {
const CMD: &'static str = "find";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::KeyAddressFind::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!("Find known keys and addresses in the wallet."))
.long_about(wrap!(
"In the transparent setting, searches for a keypair / \
address by a given alias, public key, or a public key \
hash. Looks up an alias of the given address.\nIn the \
shielded setting, searches for a spending / viewing key \
and payment address by a given alias. Looks up an alias \
of the given payment address."
))
.add_args::<args::KeyAddressFind>()
}
}
/// Export key to a file
#[derive(Clone, Debug)]
pub struct WalletExportKey(pub args::KeyExport);
impl SubCmd for WalletExportKey {
const CMD: &'static str = "export";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| (Self(args::KeyExport::parse(matches))))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Exports a transparent keypair / shielded spending key to \
a file."
))
.add_args::<args::KeyExport>()
}
}
/// Export key to a file
#[derive(Clone, Debug)]
pub struct WalletConvertKey(pub args::KeyConvert);
impl SubCmd for WalletConvertKey {
const CMD: &'static str = "convert";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| (Self(args::KeyConvert::parse(matches))))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Convert to tendermint priv_validator_key.json with your \
consensus key alias"
))
.add_args::<args::KeyConvert>()
}
}
/// Import key from a file
#[derive(Clone, Debug)]
pub struct WalletImportKey(pub args::KeyImport);
impl SubCmd for WalletImportKey {
const CMD: &'static str = "import";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| (Self(args::KeyImport::parse(matches))))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Imports a transparent keypair / shielded spending key \
from a file."
))
.add_args::<args::KeyImport>()
}
}
/// Add public / payment address to the wallet
#[derive(Clone, Debug)]
pub struct WalletAddKeyAddress(pub args::KeyAddressAdd);
impl SubCmd for WalletAddKeyAddress {
const CMD: &'static str = "add";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| (Self(args::KeyAddressAdd::parse(matches))))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!("Adds the given key or address to the wallet."))
.add_args::<args::KeyAddressAdd>()
}
}
/// Remove key / address
#[derive(Clone, Debug)]
pub struct WalletRemoveKeyAddress(pub args::KeyAddressRemove);
impl SubCmd for WalletRemoveKeyAddress {
const CMD: &'static str = "remove";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::KeyAddressRemove::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Remove the given alias and all associated keys / \
addresses from the wallet."
))
.add_args::<args::KeyAddressRemove>()
}
}
/// Generate a payment address from a viewing key or payment address
#[derive(Clone, Debug)]
pub struct WalletGenPaymentAddress(pub args::PayAddressGen);
impl SubCmd for WalletGenPaymentAddress {
const CMD: &'static str = "gen-payment-addr";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::PayAddressGen::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Generate the next payment address for a viewing key."
))
.add_args::<args::PayAddressGen>()
}
}
#[derive(Clone, Debug)]
pub enum Ledger {
Run(LedgerRun),
RunUntil(LedgerRunUntil),
Reset(LedgerReset),
DumpDb(LedgerDumpDb),
QueryDB(LedgerQueryDB),
RollBack(LedgerRollBack),
}
impl SubCmd for Ledger {
const CMD: &'static str = "ledger";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).and_then(|matches| {
let run = SubCmd::parse(matches).map(Self::Run);
let reset = SubCmd::parse(matches).map(Self::Reset);
let dump_db = SubCmd::parse(matches).map(Self::DumpDb);
let query_db = SubCmd::parse(matches).map(Self::QueryDB);
let rollback = SubCmd::parse(matches).map(Self::RollBack);
let run_until = SubCmd::parse(matches).map(Self::RunUntil);
run.or(reset)
.or(dump_db)
.or(query_db)
.or(rollback)
.or(run_until)
// The `run` command is the default if no sub-command given
.or(Some(Self::Run(LedgerRun(args::LedgerRun {
start_time: None,
migration_path: None,
migration_hash: None,
migration_height: None,
}))))
})
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Ledger node sub-commands. If no sub-command specified, \
defaults to run the node."
))
.subcommand(LedgerRun::def())
.subcommand(LedgerRunUntil::def())
.subcommand(LedgerReset::def())
.subcommand(LedgerDumpDb::def())
.subcommand(LedgerQueryDB::def())
.subcommand(LedgerRollBack::def())
}
}
#[derive(Clone, Debug)]
pub struct LedgerRun(pub args::LedgerRun);
impl SubCmd for LedgerRun {
const CMD: &'static str = "run";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::LedgerRun::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!("Run Namada ledger node."))
.add_args::<args::LedgerRun>()
}
}
#[derive(Clone, Debug)]
pub struct LedgerRunUntil(pub args::LedgerRunUntil);
impl SubCmd for LedgerRunUntil {
const CMD: &'static str = "run-until";
fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::LedgerRunUntil::parse(matches)))
}
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Run Namada ledger node until a given height. Then halt \
or suspend."
))
.add_args::<args::LedgerRunUntil>()
}
}
#[derive(Clone, Debug)]
pub struct LedgerReset(pub args::LedgerReset);
impl SubCmd for LedgerReset {
const CMD: &'static str = "reset";