added wallet connect functions to rpc adapter

This commit is contained in:
rachel-rose
2021-05-26 13:50:31 +02:00
parent 83485d8a01
commit eb26a44a2e
2 changed files with 38 additions and 5 deletions

View File

@@ -1,6 +1,13 @@
// Adapter class goes here
//use crate::rpc::jsonserver::JsonRpcInterface;
#[macro_use]
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
pub struct RpcAdapter {}
@@ -10,9 +17,32 @@ impl RpcAdapter {
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() {}
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)
}
// 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() {}

View File

@@ -155,7 +155,10 @@ impl RpcInterface {
Ok(jsonrpc_core::Value::Null)
});
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)
});
debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");