|
|
@@ -3,7 +3,7 @@ use crate::serial;
|
|
|
use crate::serial::{deserialize, serialize, Decodable, Encodable};
|
|
|
use crate::Error;
|
|
|
use crate::Result;
|
|
|
-use async_std::sync::Arc;
|
|
|
+use async_std::sync::{Arc, Mutex};
|
|
|
use ff::Field;
|
|
|
use log::*;
|
|
|
use rand::rngs::OsRng;
|
|
|
@@ -17,11 +17,11 @@ pub struct WalletDB {
|
|
|
pub path: PathBuf,
|
|
|
pub secrets: Vec<jubjub::Fr>,
|
|
|
pub cashier_secrets: Vec<jubjub::Fr>,
|
|
|
- //pub coin: Coin,
|
|
|
- //pub note: Note,
|
|
|
- //pub witness: IncrementalWitness<MerkleNode>,
|
|
|
+ pub coins: Mutex<Vec<Coin>>,
|
|
|
+ pub notes: Mutex<Vec<Note>>,
|
|
|
+ pub witnesses: Mutex<Vec<IncrementalWitness<MerkleNode>>>,
|
|
|
// wrap in mutex or read/write lock
|
|
|
- pub own_coins: Vec<(Coin, Note, jubjub::Fr, IncrementalWitness<MerkleNode>)>,
|
|
|
+ //pub own_coins: Vec<(Coin, Note, jubjub::Fr, IncrementalWitness<MerkleNode>)>,
|
|
|
pub cashier_public: jubjub::SubgroupPoint,
|
|
|
pub public: jubjub::SubgroupPoint,
|
|
|
//conn: Arc<Connection>,
|
|
|
@@ -30,7 +30,7 @@ pub struct WalletDB {
|
|
|
impl WalletDB {
|
|
|
pub fn new(wallet: &str) -> Result<Self> {
|
|
|
debug!(target: "walletdb", "new() Constructor called");
|
|
|
- //let path = Self::create_path(wallet)?;
|
|
|
+ let path = Self::create_path(wallet)?;
|
|
|
//let conn = Connection::open(&path)?;
|
|
|
//debug!(target: "walletdb", "OPENED CONNECTION AT PATH {:?}", path);
|
|
|
//let contents = include_str!("../../res/schema.sql");
|
|
|
@@ -38,36 +38,46 @@ impl WalletDB {
|
|
|
let secret = jubjub::Fr::random(&mut OsRng);
|
|
|
let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
|
|
|
let cashier_public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * cashier_secret;
|
|
|
+ let coins = Mutex::new(Vec::new());
|
|
|
+ let notes = Mutex::new(Vec::new());
|
|
|
+ let witnesses = Mutex::new(Vec::new());
|
|
|
//match conn.execute_batch(&contents) {
|
|
|
// Ok(v) => println!("Database initalized successfully {:?}", v),
|
|
|
// Err(err) => println!("Error: {}", err),
|
|
|
//};
|
|
|
debug!(target: "walletdb", "new(): wallet constructor called");
|
|
|
Ok(Self {
|
|
|
- path: Self::create_path(wallet)?,
|
|
|
- own_coins: vec![],
|
|
|
+ path,
|
|
|
+ //own_coins: vec![],
|
|
|
cashier_secrets: vec![cashier_secret.clone()],
|
|
|
secrets: vec![secret.clone()],
|
|
|
cashier_public,
|
|
|
public,
|
|
|
- //coin,
|
|
|
- //note,
|
|
|
- //witness,
|
|
|
+ coins,
|
|
|
+ notes,
|
|
|
+ witnesses,
|
|
|
//conn,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
//coin, serial, value, asset_id, coin_blind, valcom_blind, witness, key_id
|
|
|
- pub async fn put_own_coins(&self) -> Result<()> {
|
|
|
- let coin = self.get_value_serialized(&self.own_coins[0].0.repr).await?;
|
|
|
- let note = &self.own_coins[0].1;
|
|
|
+ pub async fn put_own_coins(
|
|
|
+ &self,
|
|
|
+ coin: Coin,
|
|
|
+ note: Note,
|
|
|
+ witness: IncrementalWitness<MerkleNode>,
|
|
|
+ ) -> Result<()> {
|
|
|
+ let coin = self.get_value_serialized(&coin.repr).await?;
|
|
|
+ //let coin = self.get_value_serialized(&self.own_coins[0].0.repr).await?;
|
|
|
+ //let note = &self.own_coins[0].1;
|
|
|
let serial = self.get_value_serialized(¬e.serial).await?;
|
|
|
let coin_blind = self.get_value_serialized(¬e.coin_blind).await?;
|
|
|
let valcom_blind = self.get_value_serialized(¬e.valcom_blind).await?;
|
|
|
let value = self.get_value_serialized(¬e.value).await?;
|
|
|
let asset_id = self.get_value_serialized(¬e.asset_id).await?;
|
|
|
let conn = Connection::open(&self.path)?;
|
|
|
- let witness = self.get_value_serialized(&self.own_coins[0].3).await?;
|
|
|
+ let witness = self.get_value_serialized(&witness).await?;
|
|
|
+ //let witness = self.get_value_serialized(&self.own_coins[0].3).await?;
|
|
|
conn.execute(
|
|
|
"INSERT INTO coins(coin, serial, value, asset_id, coin_blind, valcom_blind, witness, key_id)
|
|
|
VALUES (NULL, :coin, :serial, :value, :asset_id, :coin_blind, :valcom_blind, :witness, :key_id)",
|