فهرست منبع

added wallet connect functions to rpc adapter

rachel-rose 5 سال پیش
والد
کامیت
eb26a44a2e
2فایلهای تغییر یافته به همراه38 افزوده شده و 5 حذف شده
  1. 34 4
      src/rpc/adapter.rs
  2. 4 1
      src/rpc/jsonserver.rs

+ 34 - 4
src/rpc/adapter.rs

@@ -1,6 +1,13 @@
-// Adapter class goes here
-//use crate::rpc::jsonserver::JsonRpcInterface;
+#[macro_use]
 use std::sync::Arc;
 use std::sync::Arc;
+use rusqlite::Connection;
+use ff::Field;
+use rand::rngs::OsRng;
+use std::fs::File;
+use std::io::prelude::*;
+use crate::serial;
+use crate::Result;
+use smol::Async;
 
 
 // Dummy adapter for now
 // Dummy adapter for now
 pub struct RpcAdapter {}
 pub struct RpcAdapter {}
@@ -10,9 +17,32 @@ impl RpcAdapter {
         Arc::new(Self {})
         Arc::new(Self {})
     }
     }
 
 
-    pub async fn get_info() {}
+    pub async fn db_connect() -> Connection {
+        let path = dirs::home_dir()
+            .expect("Cannot find home directory.")
+            .as_path()
+            .join(".config/darkfi/wallet.db");
+        let connector = Connection::open(&path);
+        connector.expect("Failed to connect to database.")
+    }
+
+    pub async fn key_gen() -> (Vec<u8>, Vec<u8>) {
+        let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
+        let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
+        let pubkey = serial::serialize(&public);
+        let privkey = serial::serialize(&secret);
+        (privkey, pubkey)
+    }
 
 
-    pub async fn key_gen() {}
+    // 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<()> {
+        let mut db_file = File::open("wallet.sql")?;
+        let mut contents = String::new();
+        db_file.read_to_string(&mut contents)?;
+        Ok(conn.execute_batch(&mut contents)?)
+    }
+
+    pub async fn get_info() {}
 
 
     pub async fn say_hello() {}
     pub async fn say_hello() {}
 
 

+ 4 - 1
src/rpc/jsonserver.rs

@@ -155,7 +155,10 @@ impl RpcInterface {
             Ok(jsonrpc_core::Value::Null)
             Ok(jsonrpc_core::Value::Null)
         });
         });
         io.add_method("key_gen", move |_| async move {
         io.add_method("key_gen", move |_| async move {
-            RpcAdapter::key_gen().await;
+            //let connection = RpcAdapter::db_connect().await;
+            //let (public, private) = RpcAdapter::key_gen().await;
+            // getting an error on the following:
+            // RpcAdapter::save_key(&connection, private, public).await;
             Ok(jsonrpc_core::Value::Null)
             Ok(jsonrpc_core::Value::Null)
         });
         });
         debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");
         debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");