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

key_gen() generating new keypair and add them to walletdb

ghassmo 4 лет назад
Родитель
Сommit
7a0c98682a
3 измененных файлов с 6 добавлено и 7 удалено
  1. 1 1
      src/cli/drk_cli.rs
  2. 2 4
      src/rpc/adapters/client_adapter.rs
  3. 3 2
      src/wallet/walletdb.rs

+ 1 - 1
src/cli/drk_cli.rs

@@ -93,7 +93,7 @@ impl DrkCli {
                 Arg::with_name("key")
                     .short("k")
                     .long("key")
-                    .help("Test key")
+                    .help("Generate new keypair")
                     .takes_value(false),
             )
             .arg(

+ 2 - 4
src/rpc/adapters/client_adapter.rs

@@ -67,11 +67,9 @@ impl RpcClientAdapter {
     }
 
     async fn key_gen_process(client: Arc<Mutex<Client>>) -> Result<String> {
-        let client =  client.lock().await;
-        let (public, private) = client.state.wallet.key_gen();
-        debug!(target: "RPC USER ADAPTER", "Created keypair...");
+        debug!(target: "RPC USER ADAPTER", "Generating keypair...");
         debug!(target: "RPC USER ADAPTER", "Attempting to write to database...");
-        client.state.wallet.put_keypair(public, private)?;
+        client.lock().await.state.wallet.key_gen()?;
         Ok("key generation successful".into())
     }
 

+ 3 - 2
src/wallet/walletdb.rs

@@ -186,13 +186,14 @@ impl WalletDb {
         Ok(())
     }
 
-    pub fn key_gen(&self) -> (Vec<u8>, Vec<u8>) {
+    pub fn key_gen(&self) -> Result<(Vec<u8>, Vec<u8>)>  {
         debug!(target: "WALLETDB", "Attempting to generate keys...");
         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);
-        (pubkey, privkey)
+        self.put_keypair(pubkey.clone(), privkey.clone())?;
+        Ok((pubkey, privkey))
     }
 
     pub fn put_keypair(&self, key_public: Vec<u8>, key_private: Vec<u8>) -> Result<()> {