Преглед изворни кода

add get_key option to drk.rs

ghassmo пре 5 година
родитељ
комит
d945634cd9
2 измењених фајлова са 19 додато и 0 уклоњено
  1. 10 0
      src/bin/drk.rs
  2. 9 0
      src/cli/drk_cli.rs

+ 10 - 0
src/bin/drk.rs

@@ -62,6 +62,11 @@ impl Drk {
         Ok(self.request(r).await?)
     }
 
+    pub async fn get_key(&self) -> Result<()> {
+        let r = jsonrpc::request(json!("get_key"), json!([]));
+        Ok(self.request(r).await?)
+    }
+
     pub async fn get_info(&self) -> Result<()> {
         let r = jsonrpc::request(json!("get_info"), json!([]));
         Ok(self.request(r).await?)
@@ -86,6 +91,7 @@ impl Drk {
         let r = jsonrpc::request(json!("withdraw"), json!([address, amount]));
         Ok(self.request(r).await?)
     }
+
 }
 
 async fn start(config: &DrkConfig, options: DrkCli) -> Result<()> {
@@ -104,6 +110,10 @@ async fn start(config: &DrkConfig, options: DrkCli) -> Result<()> {
         client.key_gen().await?;
     }
 
+    if options.get_key {
+        client.get_key().await?;
+    }
+
     if options.info {
         client.get_info().await?;
     }

+ 9 - 0
src/cli/drk_cli.rs

@@ -60,6 +60,7 @@ pub struct DrkCli {
     pub cashier: bool,
     pub wallet: bool,
     pub key: bool,
+    pub get_key: bool,
     pub info: bool,
     pub hello: bool,
     pub stop: bool,
@@ -101,6 +102,12 @@ impl DrkCli {
                     .help_heading(Some("Test key"))
                     .takes_value(false),
             )
+            .arg(
+                Arg::new("getkey")
+                    .long("getkey")
+                    .help_heading(Some("Get public key as base-58 encoded string"))
+                    .takes_value(false),
+            )
             .arg(
                 Arg::new("wallet")
                     .short('w')
@@ -199,6 +206,7 @@ impl DrkCli {
         let info = app.is_present("info");
         let hello = app.is_present("hello");
         let stop = app.is_present("stop");
+        let get_key = app.is_present("getkey");
 
         let deposit = None;
         match app.subcommand_matches("deposit") {
@@ -269,6 +277,7 @@ impl DrkCli {
             cashier,
             wallet,
             key,
+            get_key,
             info,
             hello,
             stop,