From 399cd3c94c7fa5f7733b855e1ffdf2c3ca292fab Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 4 May 2021 10:37:40 +0200 Subject: [PATCH 1/6] added wallet test code to /bin --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9e012172f..d7a8ad6e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,6 +108,9 @@ path = "src/bin/dfg.rs" name = "compile-shaders" path = "src/bin/compile-shaders.rs" +name = "wallet" +path = "src/bin/wallet.rs" + [profile.release] debug = 1 From 8b3a30b6d364d35c270337c79032e7c1f11902d3 Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 4 May 2021 10:45:21 +0200 Subject: [PATCH 2/6] rusqlite and rocksdb test code --- src/bin/wallet/src/main.rs | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/bin/wallet/src/main.rs diff --git a/src/bin/wallet/src/main.rs b/src/bin/wallet/src/main.rs new file mode 100644 index 000000000..c881776f8 --- /dev/null +++ b/src/bin/wallet/src/main.rs @@ -0,0 +1,83 @@ +// rocksdb is the blockchain database +// it is a key value store +// sqlite is the encrypted wallet + +use rusqlite::{Connection, Result}; +use rocksdb::DB; + +fn main() -> Result<()> { + wallet()?; + blockchain()?; + Ok(()) +} + +fn wallet() -> Result<()> { + let connector = connect()?; + encrypt(&connector)?; + println!("Created encrypted database."); + decrypt(&connector)?; + println!("Decrypted database."); + Ok(()) +} + +fn connect() -> Result { + println!("Attempting to establish a connection..."); + let path = "/home/x/src/dbtest/src/wallet.db"; + let connector = Connection::open(&path); + println!("Path created at {}", path); + println!("Connection established"); + connector +} + +fn encrypt(conn: &Connection) -> Result<()> { + println!("Attempting to create an encrypted database..."); + conn.execute_batch( + "ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey'; + SELECT sqlcipher_export('encrypted'); + DETACH DATABASE encrypted;", + ) +} + +fn decrypt(conn: &Connection) -> Result<()> { + println!("Attempting to decrypt database..."); + conn.execute_batch( + "ATTACH DATABASE 'plaintext.db' AS plaintext KEY 'testkey'; + SELECT sqlcipher_export('plaintext'); + DETACH DATABASE plaintext;", + ) +} + +fn blockchain() -> Result<()> { + let db = create_db(); + write_db(&db)?; + test_db(&db); + Ok(()) +} + +fn create_db() -> DB { + println!("Creating a blockchain database..."); + let path = "/home/x/src/dbtest/blockchain.db"; + let db = DB::open_default(path).unwrap(); + db +} + +fn write_db(db: &DB) -> Result<()> { + println!("Writing to the blockchain..."); + db.put(b"test-value", b"test-key").unwrap(); + Ok(()) +} + +fn test_db(db: &DB) { + println!("Testing if write was successful..."); + match db.get(b"test-value") { + Ok(Some(value)) => println!("retrieved value {}", String::from_utf8(value).unwrap()), + Ok(None) => println!("value not found"), + Err(e) => println!("operational problem encountered: {}", e), + } +} + +//fn configure_blockchain() { +// let mut opts = Options::default(); +// let mut block_opts = BlockBasedOptions::default(); +// block_opts.set_index_type(BlockBasedIndexType::HashSearch); +//} From d968741d41c5eaecca625ab7e1e3fa01b9e4dc49 Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 4 May 2021 10:48:44 +0200 Subject: [PATCH 3/6] toml file for wallet dependencies --- src/bin/wallet/Cargo.toml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/wallet/Cargo.toml diff --git a/src/bin/wallet/Cargo.toml b/src/bin/wallet/Cargo.toml new file mode 100644 index 000000000..452d06ec7 --- /dev/null +++ b/src/bin/wallet/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "dbtest" +version = "0.1.0" +authors = ["rachel-rose "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rocksdb = "0.16.0" + +[dependencies.rusqlite] +version = "0.25.1" +features = ["bundled", "sqlcipher"] + From aeab062f15901435fd42a91f1008ef39c7c53362 Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 4 May 2021 11:05:06 +0200 Subject: [PATCH 4/6] migrated test code to sapvi directory --- src/bin/wallet/test.rs | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/bin/wallet/test.rs diff --git a/src/bin/wallet/test.rs b/src/bin/wallet/test.rs new file mode 100644 index 000000000..16522dfb2 --- /dev/null +++ b/src/bin/wallet/test.rs @@ -0,0 +1,83 @@ +// rocksdb is the blockchain database +// it is a key value store +// sqlite is the encrypted wallet + +use rusqlite::{Connection, Result}; +use rocksdb::DB; + +fn main() -> Result<()> { + wallet()?; + blockchain()?; + Ok(()) +} + +fn wallet() -> Result<()> { + let connector = connect()?; + encrypt(&connector)?; + println!("Created encrypted database."); + decrypt(&connector)?; + println!("Decrypted database."); + Ok(()) +} + +fn connect() -> Result { + println!("Attempting to establish a connection..."); + let path = "/home/x/src/sapvi/src/bin/wallet/wallet.db"; + let connector = Connection::open(&path); + println!("Path created at {}", path); + println!("Connection established"); + connector +} + +fn encrypt(conn: &Connection) -> Result<()> { + println!("Attempting to create an encrypted database..."); + conn.execute_batch( + "ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey'; + SELECT sqlcipher_export('encrypted'); + DETACH DATABASE encrypted;", + ) +} + +fn decrypt(conn: &Connection) -> Result<()> { + println!("Attempting to decrypt database..."); + conn.execute_batch( + "ATTACH DATABASE 'plaintext.db' AS plaintext KEY 'testkey'; + SELECT sqlcipher_export('plaintext'); + DETACH DATABASE plaintext;", + ) +} + +fn blockchain() -> Result<()> { + let db = create_db(); + write_db(&db)?; + test_db(&db); + Ok(()) +} + +fn create_db() -> DB { + println!("Creating a blockchain database..."); + let path = "/home/x/src/sapvi/src/bin/wallet/blockchain.db"; + let db = DB::open_default(path).unwrap(); + db +} + +fn write_db(db: &DB) -> Result<()> { + println!("Writing to the blockchain..."); + db.put(b"test-value", b"test-key").unwrap(); + Ok(()) +} + +fn test_db(db: &DB) { + println!("Testing if write was successful..."); + match db.get(b"test-value") { + Ok(Some(value)) => println!("retrieved value {}", String::from_utf8(value).unwrap()), + Ok(None) => println!("value not found"), + Err(e) => println!("operational problem encountered: {}", e), + } +} + +//fn configure_blockchain() { +// let mut opts = Options::default(); +// let mut block_opts = BlockBasedOptions::default(); +// block_opts.set_index_type(BlockBasedIndexType::HashSearch); +//} From baedbb16600be781e7b24565967ce30066cce02f Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 4 May 2021 11:05:59 +0200 Subject: [PATCH 5/6] added wallet build info --- Cargo.toml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 25a67fb5d..f2fb2fe0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,12 @@ tobj = "2.0.4" fs_extra = "1.2" glob = "0.3" +# wallet deps +rocksdb = "0.16.0" +[dependencies.rusqlite] +version = "0.25.1" +features = ["bundled", "sqlcipher"] + [[bin]] name = "lisp" path = "lisp/lisp.rs" @@ -115,8 +121,9 @@ path = "src/bin/dfg.rs" name = "compile-shaders" path = "src/bin/compile-shaders.rs" +[[bin]] name = "wallet" -path = "src/bin/wallet.rs" +path = "src/bin/wallet/test.rs" [profile.release] debug = 1 From 77e0d905b490a01822c07eaa37fd0b54ae47349c Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Tue, 4 May 2021 11:07:53 +0200 Subject: [PATCH 6/6] cleaned up wallet repo --- src/bin/wallet/Cargo.toml | 15 ------- src/bin/wallet/src/main.rs | 83 -------------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 src/bin/wallet/Cargo.toml delete mode 100644 src/bin/wallet/src/main.rs diff --git a/src/bin/wallet/Cargo.toml b/src/bin/wallet/Cargo.toml deleted file mode 100644 index 452d06ec7..000000000 --- a/src/bin/wallet/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "dbtest" -version = "0.1.0" -authors = ["rachel-rose "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rocksdb = "0.16.0" - -[dependencies.rusqlite] -version = "0.25.1" -features = ["bundled", "sqlcipher"] - diff --git a/src/bin/wallet/src/main.rs b/src/bin/wallet/src/main.rs deleted file mode 100644 index c881776f8..000000000 --- a/src/bin/wallet/src/main.rs +++ /dev/null @@ -1,83 +0,0 @@ -// rocksdb is the blockchain database -// it is a key value store -// sqlite is the encrypted wallet - -use rusqlite::{Connection, Result}; -use rocksdb::DB; - -fn main() -> Result<()> { - wallet()?; - blockchain()?; - Ok(()) -} - -fn wallet() -> Result<()> { - let connector = connect()?; - encrypt(&connector)?; - println!("Created encrypted database."); - decrypt(&connector)?; - println!("Decrypted database."); - Ok(()) -} - -fn connect() -> Result { - println!("Attempting to establish a connection..."); - let path = "/home/x/src/dbtest/src/wallet.db"; - let connector = Connection::open(&path); - println!("Path created at {}", path); - println!("Connection established"); - connector -} - -fn encrypt(conn: &Connection) -> Result<()> { - println!("Attempting to create an encrypted database..."); - conn.execute_batch( - "ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey'; - SELECT sqlcipher_export('encrypted'); - DETACH DATABASE encrypted;", - ) -} - -fn decrypt(conn: &Connection) -> Result<()> { - println!("Attempting to decrypt database..."); - conn.execute_batch( - "ATTACH DATABASE 'plaintext.db' AS plaintext KEY 'testkey'; - SELECT sqlcipher_export('plaintext'); - DETACH DATABASE plaintext;", - ) -} - -fn blockchain() -> Result<()> { - let db = create_db(); - write_db(&db)?; - test_db(&db); - Ok(()) -} - -fn create_db() -> DB { - println!("Creating a blockchain database..."); - let path = "/home/x/src/dbtest/blockchain.db"; - let db = DB::open_default(path).unwrap(); - db -} - -fn write_db(db: &DB) -> Result<()> { - println!("Writing to the blockchain..."); - db.put(b"test-value", b"test-key").unwrap(); - Ok(()) -} - -fn test_db(db: &DB) { - println!("Testing if write was successful..."); - match db.get(b"test-value") { - Ok(Some(value)) => println!("retrieved value {}", String::from_utf8(value).unwrap()), - Ok(None) => println!("value not found"), - Err(e) => println!("operational problem encountered: {}", e), - } -} - -//fn configure_blockchain() { -// let mut opts = Options::default(); -// let mut block_opts = BlockBasedOptions::default(); -// block_opts.set_index_type(BlockBasedIndexType::HashSearch); -//}