Explorar o código

cashier key gen test passed

rachel-rose %!s(int64=5) %!d(string=hai) anos
pai
achega
95bf3ccf45
Modificáronse 4 ficheiros con 51 adicións e 20 borrados
  1. 15 0
      scripts/drk
  2. 26 16
      src/rpc/adapter.rs
  3. 9 2
      src/rpc/jsonserver.rs
  4. 1 2
      src/wallet/walletdb.rs

+ 15 - 0
scripts/drk

@@ -16,6 +16,7 @@ def arg_parser(client):
     parser.add_argument("-n", "--new", action='store_true', help="Generate a new wallet")
     parser.add_argument("-o", "--hello", action='store_true', help="Say hello")
     parser.add_argument("-c", "--cash", action='store_true', help="Create a new cashier wallet")
+    parser.add_argument("-q", "--ckeygen", action='store_true', help="Cash key gen")
     parser.add_argument("-x", "--cashkey", action='store_true', help="Print cashierkey")
     parser.add_argument("-t", "--test", action='store_true', help="Test path")
     args = parser.parse_args()
@@ -27,6 +28,13 @@ def arg_parser(client):
         except Exception:
             raise
 
+    if args.ckeygen:
+        try:
+            print("Attempting to print cashier key...")
+            client.ckeygen(client.payload)
+        except Exception:
+            raise
+
     if args.cashkey:
         try:
             print("Attempting to print cashier key...")
@@ -98,6 +106,13 @@ class DarkClient:
             "id": [],
         }
 
+    def ckeygen(self, payload):
+        payload['method'] = "cash_key_gen"
+        payload['jsonrpc'] = "2.0"
+        payload['id'] = "0"
+        ckeygen = self.__request(payload)
+        print(ckeygen)
+
     def cashkey(self, payload):
         payload['method'] = "get_cash_key"
         payload['jsonrpc'] = "2.0"

+ 26 - 16
src/rpc/adapter.rs

@@ -1,7 +1,6 @@
 use crate::wallet::WalletDB;
 use crate::Result;
 use log::*;
-use std::path::PathBuf;
 use std::sync::Arc;
 
 // Dummy adapter for now
@@ -12,16 +11,6 @@ impl RpcAdapter {
         Arc::new(Self {})
     }
 
-    pub async fn key_gen() -> Result<()> {
-        debug!(target: "adapter", "key_gen() [START]");
-        let (public, private) = WalletDB::create_key().await;
-        let path = WalletDB::path("wallet.db").expect("Failed to get path");
-        WalletDB::save_key(path, public, private)
-            .await
-            .expect("Failed to save key");
-        Ok(())
-    }
-
     pub async fn new_wallet() -> Result<()> {
         debug!(target: "adapter", "new_wallet() [START]");
         let path = WalletDB::path("wallet.db").expect("Failed to get path");
@@ -29,17 +18,30 @@ impl RpcAdapter {
         Ok(())
     }
 
-    pub async fn new_cashier_wallet() -> Result<()> {
+    pub async fn new_cash_wallet() -> Result<()> {
         debug!(target: "adapter", "new_cashier_wallet() [START]");
         let path = WalletDB::path("cashier.db").expect("Failed to get path");
         WalletDB::new(path).await?;
         Ok(())
     }
 
-    pub async fn save_cash_key(pubkey: Vec<u8>) -> Result<()> {
-        debug!(target: "adapter", "save_cash_key() [START]");
+    pub async fn key_gen() -> Result<()> {
+        debug!(target: "adapter", "key_gen() [START]");
+        let (public, private) = WalletDB::create_key().await;
+        let path = WalletDB::path("wallet.db").expect("Failed to get path");
+        WalletDB::save_key(path, public, private)
+            .await
+            .expect("Failed to save key");
+        Ok(())
+    }
+
+    pub async fn cash_key_gen() -> Result<()> {
+        debug!(target: "adapter", "key_gen() [START]");
+        let (public, private) = WalletDB::create_key().await;
         let path = WalletDB::path("cashier.db").expect("Failed to get path");
-        WalletDB::save(path, pubkey).await?;
+        WalletDB::save_key(path, public, private)
+            .await
+            .expect("Failed to save key");
         Ok(())
     }
 
@@ -53,7 +55,8 @@ impl RpcAdapter {
     pub async fn get_cash_key() -> Result<()> {
         debug!(target: "adapter", "get_cash_key() [START]");
         let path = WalletDB::path("cashier.db").expect("Failed to get path");
-        WalletDB::get(path).await?;
+        let key = WalletDB::get(path).await?;
+        println!("{:?}", key);
         Ok(())
     }
     pub async fn save_key(pubkey: Vec<u8>) -> Result<()> {
@@ -63,6 +66,13 @@ impl RpcAdapter {
         Ok(())
     }
 
+    pub async fn save_cash_key(pubkey: Vec<u8>) -> Result<()> {
+        debug!(target: "adapter", "save_cash_key() [START]");
+        let path = WalletDB::path("cashier.db").expect("Failed to get path");
+        WalletDB::save(path, pubkey).await?;
+        Ok(())
+    }
+
     pub async fn get_info() {}
 
     pub async fn say_hello() {}

+ 9 - 2
src/rpc/jsonserver.rs

@@ -152,7 +152,7 @@ impl RpcInterface {
         });
 
         io.add_method("get_cash_key", move |_| async move {
-            //RpcAdapter::get_path().await;
+            RpcAdapter::get_cash_key().await.expect("Failed to get key");
             Ok(jsonrpc_core::Value::String("Getting cashier key...".into()))
         });
 
@@ -179,9 +179,16 @@ impl RpcInterface {
                 "Attempted key generation".into(),
             ))
         });
+        io.add_method("cash_key_gen", move |_| async move {
+            println!("Key generation method called...");
+            RpcAdapter::cash_key_gen().await.expect("Failed to generate key");
+            Ok(jsonrpc_core::Value::String(
+                "Attempted key generation".into(),
+            ))
+        });
         io.add_method("new_cashier_wallet", move |_| async move {
             println!("Key generation method called...");
-            RpcAdapter::new_cashier_wallet()
+            RpcAdapter::new_cash_wallet()
                 .await
                 .expect("Failed to generate key");
             Ok(jsonrpc_core::Value::String(

+ 1 - 2
src/wallet/walletdb.rs

@@ -8,8 +8,7 @@ use std::path::PathBuf;
 
 // TODO: make this more generic to remove boiler plate. e.g. create_wallet(cashier) instead of
 // create_cashier_wallet
-pub struct WalletDB {
-}
+pub struct WalletDB {}
 
 impl WalletDB {
     pub async fn new(path: PathBuf) -> Result<()> {