mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 23:27:56 -05:00
wallet: Reintroduce sqlcipher.
This commit is contained in:
@@ -128,9 +128,6 @@ libsqlite3-sys = {version = "0.26.0", features = ["bundled-sqlcipher-vendored-op
|
||||
sled = {version = "0.34.7", optional = true}
|
||||
sled-overlay = {version = "0.0.7", optional = true}
|
||||
|
||||
# Temporary version lock
|
||||
#curve25519-dalek = {version = "=4.0.0-rc.3", default-features = false, optional = true}
|
||||
|
||||
[dev-dependencies]
|
||||
clap = {version = "4.3.11", features = ["derive"]}
|
||||
halo2_proofs = {version = "0.3.0", features = ["dev-graph", "gadget-traces", "sanity-checks"]}
|
||||
|
||||
@@ -301,7 +301,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
||||
}
|
||||
|
||||
// Initialize or load wallet
|
||||
let wallet = WalletDb::new(Some(expand_path(&args.wallet_path)?), &args.wallet_pass).await?;
|
||||
let wallet = WalletDb::new(Some(expand_path(&args.wallet_path)?), Some(&args.wallet_pass))?;
|
||||
|
||||
// Initialize or open sled database
|
||||
let db_path =
|
||||
|
||||
@@ -622,7 +622,7 @@ async fn prune_airdrop_maps(rate_map: AirdropMap, challenge_map: ChallengeMap, t
|
||||
async_daemonize!(realmain);
|
||||
async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
||||
// Initialize or load wallet
|
||||
let wallet = WalletDb::new(Some(expand_path(&args.wallet_path)?), &args.wallet_pass).await?;
|
||||
let wallet = WalletDb::new(Some(expand_path(&args.wallet_path)?), Some(&args.wallet_pass))?;
|
||||
|
||||
// Initialize or open sled database
|
||||
let db_path =
|
||||
|
||||
@@ -859,7 +859,7 @@ mod tests {
|
||||
#[async_std::test]
|
||||
async fn calc_sigmas_test() -> Result<()> {
|
||||
// Generate dummy state
|
||||
let wallet = WalletDb::new(None, "foo").await?;
|
||||
let wallet = WalletDb::new(None, None)?;
|
||||
let sled_db = sled::Config::new().temporary(true).open()?;
|
||||
let blockchain = Blockchain::new(&sled_db)?;
|
||||
let state = ConsensusState::new(
|
||||
|
||||
@@ -131,7 +131,7 @@ impl Wallet {
|
||||
genesis_block: &BlockInfo,
|
||||
faucet_pubkeys: &[PublicKey],
|
||||
) -> Result<Self> {
|
||||
let wallet = WalletDb::new(None, "foo").await?;
|
||||
let wallet = WalletDb::new(None, None)?;
|
||||
let sled_db = sled::Config::new().temporary(true).open()?;
|
||||
|
||||
// Use pregenerated vks
|
||||
|
||||
@@ -27,7 +27,6 @@ use crate::Result;
|
||||
pub type WalletPtr = Arc<WalletDb>;
|
||||
|
||||
/// Types we want to allow to query from the SQL wallet
|
||||
#[repr(u8)]
|
||||
pub enum QueryType {
|
||||
/// Integer gets decoded into `u64`
|
||||
Integer = 0x00,
|
||||
@@ -64,12 +63,15 @@ pub struct WalletDb {
|
||||
|
||||
impl WalletDb {
|
||||
/// Create a new wallet. If `path` is `None`, create it in memory.
|
||||
pub async fn new(path: Option<PathBuf>, _password: &str) -> Result<WalletPtr> {
|
||||
pub fn new(path: Option<PathBuf>, password: Option<&str>) -> Result<WalletPtr> {
|
||||
let conn = match path.clone() {
|
||||
Some(p) => Connection::open(p)?,
|
||||
None => Connection::open_in_memory()?,
|
||||
};
|
||||
|
||||
if let Some(password) = password {
|
||||
conn.pragma_update(None, "key", password)?;
|
||||
}
|
||||
conn.pragma_update(None, "foreign_keys", "ON")?;
|
||||
|
||||
info!(target: "wallet::walletdb", "[WalletDb] Opened Sqlite connection at \"{:?}\"", path);
|
||||
@@ -80,8 +82,26 @@ impl WalletDb {
|
||||
/// Therefore it's best to use it for initializing a table or similar things.
|
||||
pub async fn exec_sql(&self, query: &str) -> Result<()> {
|
||||
info!(target: "wallet::walletdb", "[WalletDb] Executing SQL query");
|
||||
debug!(target: "wallet::walletdb", "\n{}", query);
|
||||
self.conn.lock().await.execute(query, ())?;
|
||||
debug!(target: "wallet::walletdb", "[WalletDb] Query:\n{}", query);
|
||||
let _ = self.conn.lock().await.execute(query, ())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_mem_wallet() {
|
||||
let wallet = WalletDb::new(None, Some("foobar")).unwrap();
|
||||
wallet.exec_sql("CREATE TABLE mista ( numba INTEGER );").await.unwrap();
|
||||
wallet.exec_sql("INSERT INTO mista ( numba ) VALUES ( 42 );").await.unwrap();
|
||||
|
||||
let conn = wallet.conn.lock().await;
|
||||
let mut stmt = conn.prepare("SELECT numba FROM mista").unwrap();
|
||||
let numba: u64 = stmt.query_row((), |row| Ok(row.get("numba").unwrap())).unwrap();
|
||||
stmt.finalize().unwrap();
|
||||
assert!(numba == 42);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user