Просмотр исходного кода

added test case for pub key retrieval

rachel-rose 5 лет назад
Родитель
Сommit
88df2426a9
4 измененных файлов с 35 добавлено и 2 удалено
  1. 15 0
      scripts/drk
  2. 13 0
      src/rpc/adapter.rs
  3. 5 0
      src/rpc/jsonserver.rs
  4. 2 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("-x", "--cashkey", action='store_true', help="Print cashierkey")
     parser.add_argument("-t", "--test", action='store_true', help="Test path")
     args = parser.parse_args()
 
@@ -26,6 +27,13 @@ def arg_parser(client):
         except Exception:
             raise
 
+    if args.cashkey:
+        try:
+            print("Attempting to print cashier key...")
+            client.cashkey(client.payload)
+        except Exception:
+            raise
+
     if args.key:
         try:
             print("Attemping to generate a new key pair...")
@@ -90,6 +98,13 @@ class DarkClient:
             "id": [],
         }
 
+    def cashkey(self, payload):
+        payload['method'] = "get_cash_key"
+        payload['jsonrpc'] = "2.0"
+        payload['id'] = "0"
+        cashk = self.__request(payload)
+        print(cashk)
+        
     def test_path(self, payload):
         payload['method'] = "test_path"
         payload['jsonrpc'] = "2.0"

+ 13 - 0
src/rpc/adapter.rs

@@ -43,6 +43,19 @@ impl RpcAdapter {
         Ok(())
     }
 
+    pub async fn get_key() -> Result<()> {
+        debug!(target: "adapter", "get_key() [START]");
+        let path = WalletDB::path("wallet.db").expect("Failed to get path");
+        WalletDB::get(path).await?;
+        Ok(())
+    }
+
+    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?;
+        Ok(())
+    }
     pub async fn save_key(pubkey: Vec<u8>) -> Result<()> {
         debug!(target: "adapter", "save_key() [START]");
         let path = WalletDB::path("wallet.db").expect("Failed to get path");

+ 5 - 0
src/rpc/jsonserver.rs

@@ -151,6 +151,11 @@ impl RpcInterface {
             Ok(jsonrpc_core::Value::String("TEST PATH!".into()))
         });
 
+        io.add_method("get_cash_key", move |_| async move {
+            //RpcAdapter::get_path().await;
+            Ok(jsonrpc_core::Value::String("Getting cashier key...".into()))
+        });
+
         io.add_method("get_info", move |_| async move {
             RpcAdapter::get_info().await;
             Ok(jsonrpc_core::Value::Null)

+ 2 - 2
src/wallet/walletdb.rs

@@ -55,7 +55,7 @@ impl WalletDB {
     }
 
     pub async fn get(path: PathBuf) -> Result<()> {
-        debug!(target: "get_cash_public", "Returning cashier keys...");
+        debug!(target: "get", "Returning keys...");
         let connect = Connection::open(&path).expect("Failed to connect to database.");
         let mut stmt = connect.prepare("SELECT key_public FROM keys").unwrap();
         let key_iter = stmt
@@ -67,7 +67,7 @@ impl WalletDB {
         }
         let key = match pub_keys.pop() {
             Some(key_found) => println!("{:?}", key_found),
-            None => println!("No cashier public key found"),
+            None => println!("No public key found"),
         };
         Ok(key)
     }