MCPcopy Index your code
hub / github.com/BitVM/BitVM / handle_command

Method handle_command

bridge/src/client/cli/key_command.rs:66–167  ·  view source on GitHub ↗
(&self, sub_matches: &ArgMatches)

Source from the content-addressed store, hash-verified

64 }
65
66 pub fn handle_command(&self, sub_matches: &ArgMatches) -> io::Result<()> {
67 let mut config = self.read_config()?;
68
69 if !sub_matches.args_present() {
70 // If no arguments are specified, output the current key configuration.
71 let keys = HashMap::from([
72 ("DEPOSITOR", &config.keys.depositor),
73 ("OPERATOR", &config.keys.operator),
74 ("VERIFIER", &config.keys.verifier),
75 ("WITHDRAWER", &config.keys.withdrawer),
76 ("VERIFYING KEY", &config.keys.verifying_key),
77 ]);
78
79 if keys.values().any(|k| k.is_some()) {
80 println!("Key configuration:");
81 println!();
82
83 let print_user_key = |private_key: &Option<String>, name: &str| {
84 if let Some(prvkey) = private_key {
85 println!("[{name}]:");
86 println!(" Private key: {}", prvkey);
87 println!(" Public key: {}", pubkey_of(prvkey));
88 println!();
89 }
90 };
91
92 let print_verifying_key = |verifying_key: &Option<String>, name: &str| {
93 if let Some(vk) = verifying_key {
94 println!("[{name}]:");
95 println!(" Key: {}", vk);
96 println!();
97 }
98 };
99
100 let mut name = "DEPOSITOR";
101 print_user_key(keys.get(name).unwrap(), name);
102 name = "OPERATOR";
103 print_user_key(keys.get(name).unwrap(), name);
104 name = "VERIFIER";
105 print_user_key(keys.get(name).unwrap(), name);
106 name = "WITHDRAWER";
107 print_user_key(keys.get(name).unwrap(), name);
108 name = "VERIFYING KEY";
109 print_verifying_key(keys.get(name).unwrap(), name);
110 } else {
111 println!("No keys are configured.");
112 println!();
113 }
114
115 Ok(())
116 } else {
117 if let Some(secret_key) = sub_matches.get_one::<String>("depositor") {
118 if self.validate_key(secret_key) {
119 config.keys.depositor = Some(secret_key.clone());
120 println!(
121 "Secret key for depositor {} saved successfully!",
122 pubkey_of(secret_key)
123 );

Callers 2

mainFunction · 0.80

Calls 6

read_configMethod · 0.80
validate_keyMethod · 0.80
cloneMethod · 0.80
write_configMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected