rachel-rose 5 лет назад
Родитель
Сommit
2cf8d414ff
4 измененных файлов с 47 добавлено и 0 удалено
  1. 15 0
      scripts/drk
  2. 16 0
      src/rpc/adapter.rs
  3. 4 0
      src/rpc/jsonserver.rs
  4. 12 0
      src/wallet/schema.sql

+ 15 - 0
scripts/drk

@@ -12,6 +12,7 @@ def arg_parser(client):
     parser.add_argument("-k", "--key", action='store_true', help="Generate a new keypair")
     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")
     args = parser.parse_args()
 
@@ -22,6 +23,13 @@ def arg_parser(client):
         except Exception:
             raise
 
+    if args.new:
+        try:
+            print("Attemping to generate a new wallet...")
+            client.new_wallet(client.payload)
+        except Exception:
+            raise
+
     if args.info:
         try:
             print("Info was entered")
@@ -86,6 +94,13 @@ class DarkClient:
         payload['id'] = "0"
         hello = self.__request(payload)
         print(hello)
+    
+    def new_wallet(self, payload):
+        payload['method'] = "new_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()

+ 16 - 0
src/rpc/adapter.rs

@@ -34,8 +34,24 @@ impl RpcAdapter {
         (privkey, pubkey)
     }
 
+    pub async fn new_wallet() -> Result<()> {
+        println!("Creating a new wallet...");
+        let path = dirs::home_dir()
+            .expect("Cannot find home directory.")
+            .as_path()
+            .join(".config/darkfi/wallet.db");
+        let conn = Connection::open(&path).expect("Failed to connect to database.");
+        let mut db_file = File::open("wallet.sql")?;
+        let mut contents = String::new();
+        db_file.read_to_string(&mut contents)?;
+        println!("New wallet created");
+        Ok(conn.execute_batch(&mut 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<()> {
+        // loads the walle
         let mut db_file = File::open("wallet.sql")?;
         let mut contents = String::new();
         db_file.read_to_string(&mut contents)?;

+ 4 - 0
src/rpc/jsonserver.rs

@@ -154,6 +154,10 @@ impl RpcInterface {
             RpcAdapter::stop().await;
             Ok(jsonrpc_core::Value::Null)
         });
+        io.add_method("new_wallet", move |_| async move {
+            RpcAdapter::new_wallet().await;
+            Ok(jsonrpc_core::Value::Null)
+        });
         io.add_method("key_gen", move |_| async move {
             //let connection = RpcAdapter::db_connect().await;
             //let (public, private) = RpcAdapter::key_gen().await;

+ 12 - 0
src/wallet/schema.sql

@@ -1,3 +1,4 @@
+SQLCIPHER_OPEN_NOMUTEX;
 ATTACH DATABASE 'wallet.db' AS wallet KEY 'testkey';
 SELECT sqlcipher_export('wallet');
 CREATE TABLE IF NOT EXISTS keys(
@@ -6,4 +7,15 @@ CREATE TABLE IF NOT EXISTS keys(
     key_private BLOB NOT NULL
 );
 CREATE INDEX IF NOT EXISTS key_public on keys(key_public);
+CREATE TABLE IF NOT EXISTS coins(
+    coin BLOB NOT NULL
+    witness BLOB NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS note(
+    serial BLOB NOT NULL,
+    value INT NOT NULL,
+    coin_blind BLOB NOT NULL,
+    valcom_blind BLOB NOT NULL
+);