فهرست منبع

added cashier generation code to cli/ rpc

rachel-rose 5 سال پیش
والد
کامیت
b3c1768bd6
3فایلهای تغییر یافته به همراه39 افزوده شده و 2 حذف شده
  1. 17 1
      scripts/drk
  2. 14 0
      src/rpc/adapter.rs
  3. 8 1
      src/rpc/jsonserver.rs

+ 17 - 1
scripts/drk

@@ -13,7 +13,8 @@ def arg_parser(client):
     parser.add_argument("-i", "--info", action='store_true', help="Request info from daemon")
     parser.add_argument("-s", "--stop", action='store_true', help="Send a stop signal to the daemon")
     parser.add_argument("-n", "--new", action='store_true', help="Generate a new wallet")
-    parser.add_argument("-hi", "--hello", action='store_true', help="Say hello")
+    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")
     args = parser.parse_args()
 
     if args.key:
@@ -53,6 +54,13 @@ def arg_parser(client):
         except Exception:
             raise
 
+    if args.cash:
+        try:
+            print("Cash was entered")
+            client.new_cashier_wallet(client.payload)
+        except Exception:
+            raise
+
 
 # TODO: refactor into async
 class DarkClient:
@@ -102,6 +110,14 @@ class DarkClient:
         wallet = self.__request(payload)
         print(wallet)
 
+    def new_cashier_wallet(self, payload):
+        payload['method'] = "new_cashier_wallet"
+        payload['jsonrpc'] = "2.0"
+        payload['id'] = "0"
+        wallet = self.__request(payload)
+        print(wallet)
+
+
     def __request(self, payload):
         response = requests.post(self.url, json=payload).json()
         # print something better

+ 14 - 0
src/rpc/adapter.rs

@@ -69,6 +69,20 @@ impl RpcAdapter {
         Ok(connect.execute_batch(&contents)?)
     }
 
+    pub async fn new_cashier_wallet() -> Result<()> {
+        debug!(target: "adapter", "new_wallet() [START]");
+        let path = dirs::home_dir()
+            .expect("Cannot find home directory.")
+            .as_path()
+            .join(".config/darkfi/cashier.db");
+        debug!(target: "adapter", "new_wallet() [FOUND PATH]");
+        println!("Found path: {:?}", &path);
+        debug!(target: "adapter", "new_wallet() [TRY DB CONNECT]");
+        let connect = Connection::open(&path).expect("Failed to connect to database.");
+        let contents = include_str!("../../res/schema.sql");
+        Ok(connect.execute_batch(&contents)?)
+    }
+
     //pub async fn decrypt(conn: &Connection, password: )
     // TODO: getting an error when i call this function- does not implement send
     pub async fn save_key(conn: &Connection, pubkey: Vec<u8>, privkey: Vec<u8>) -> Result<()> {

+ 8 - 1
src/rpc/jsonserver.rs

@@ -156,7 +156,7 @@ impl RpcInterface {
         });
         io.add_method("new_wallet", move |_| async move {
             println!("New wallet method called...");
-            RpcAdapter::new_wallet().await;
+            RpcAdapter::new_wallet().await.expect("Failed to create wallet.");
             Ok(jsonrpc_core::Value::Null)
         });
         io.add_method("key_gen", move |_| async move {
@@ -166,6 +166,13 @@ impl RpcInterface {
                 "Attempted key generation".into(),
             ))
         });
+        io.add_method("new_cashier_wallet", move |_| async move {
+            println!("Key generation method called...");
+            RpcAdapter::new_cashier_wallet().await.expect("Failed to generate key");
+            Ok(jsonrpc_core::Value::String(
+                "Tried to create new cashier wallet".into(),
+            ))
+        });
         debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");
         Ok(io)
     }