Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make lib komodefi compatible #8

Merged
merged 43 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
07ebc40
save dev state — added mm2_ext modules to sqlite_client and backend
borngraced Aug 14, 2023
d1158fe
save dev state — create async fn version of data_api functions
borngraced Aug 22, 2023
8819ec2
save dev state — modified async BlockSource trait
borngraced Aug 22, 2023
c3ab476
use aync-ware mutex
borngraced Aug 22, 2023
924c418
save dev state — ported wallet_Write and Read
borngraced Aug 25, 2023
3b1122b
save dev state — impl inner fn for WalletDbAsync
borngraced Aug 25, 2023
34799ce
save dev state — impl for_path fn for WalletDbAsync
borngraced Aug 25, 2023
9d2c681
save dev state — make BlockSource Send
borngraced Aug 25, 2023
329e249
save dev state — finish modification
borngraced Aug 27, 2023
ecb0295
save dev state — finish modification
borngraced Aug 27, 2023
624ed96
save dev state — minor changes
borngraced Aug 27, 2023
e473d79
save dev state — zcash extras
borngraced Aug 27, 2023
7fa620c
Merge remote-tracking branch 'origin/mm2_extras' into mm2_extras
borngraced Aug 27, 2023
bafac3a
make NoteRef not Copy
borngraced Aug 31, 2023
3c21128
move ShieldedOutput
borngraced Aug 31, 2023
5d5d822
fix review notes and add doc comments
borngraced Sep 5, 2023
d3d81c9
Revert "move ShieldedOutput"
borngraced Sep 5, 2023
8c12241
async init
borngraced Sep 7, 2023
e89819f
move WalletShieldedOutput
borngraced Sep 7, 2023
0c20210
make fake_compact_block and fake_compact_block_spending public
borngraced Sep 14, 2023
3d07af9
move fake_compact_block and fake_compact_block_spending public
borngraced Sep 14, 2023
9837e10
minor changes
borngraced Sep 14, 2023
6ab22ea
copy decrypt_and_store_transaction and create_spend_to_address as async
borngraced Sep 15, 2023
8f4b5e1
make db initializations async
borngraced Sep 15, 2023
809fc70
minor changes
borngraced Sep 18, 2023
985d47d
rename module
borngraced Sep 18, 2023
becd9d0
remove unused
borngraced Sep 18, 2023
ef13898
make LocalTxProver field pub
borngraced Sep 19, 2023
1901f09
move NoteId structure
borngraced Sep 25, 2023
bde9aab
fix review notes
borngraced Oct 5, 2023
37623e3
update time crate
borngraced Oct 6, 2023
496d255
fix review notes
borngraced Oct 11, 2023
af14c33
remove redundancy
borngraced Oct 11, 2023
99998ef
minor fix
borngraced Oct 11, 2023
cf057b9
change `zcash_extra` edition to 2018
borngraced Oct 11, 2023
7039054
delete NoteId from sqlite crate
borngraced Oct 11, 2023
b381253
remove redundancy crate decl
borngraced Oct 27, 2023
04e7b51
fix review notes
borngraced Nov 1, 2023
1b20142
fix review notes
borngraced Nov 1, 2023
97a64ea
make LocalTxProver fields private
borngraced Nov 2, 2023
cfbe0a0
fix sql init module review notes
borngraced Nov 2, 2023
faed2b8
remove decrypt_and_store_transaction
borngraced Nov 2, 2023
8c97f56
fix review notes
borngraced Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"zcash_client_backend",
"zcash_client_sqlite",
"zcash_extensions",
"zcash_extras",
"zcash_history",
"zcash_primitives",
"zcash_proofs",
Expand Down
2 changes: 2 additions & 0 deletions zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ license = "MIT OR Apache-2.0"
edition = "2018"

[dependencies]
async-trait = "0.1.52"
bech32 = "0.9.1"
bls12_381 = "0.3.1"
bs58 = { version = "0.4", features = ["check"] }
base64 = "0.13"
ff = "0.8"
futures = { version = "0.3", package = "futures", features = ["compat", "async-await"] }
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
group = "0.8"
hex = "0.4"
jubjub = "0.5.1"
Expand Down
2 changes: 2 additions & 0 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub trait WalletRead {

/// The subset of information that is relevant to this wallet that has been
/// decrypted and extracted from a [CompactBlock].
#[derive(Clone)]
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
pub struct PrunedBlock<'a> {
pub block_height: BlockHeight,
pub block_hash: BlockHash,
Expand All @@ -201,6 +202,7 @@ pub struct ReceivedTransaction<'a> {
/// The purpose of this struct is to permit atomic updates of the
/// wallet database when transactions are created and submitted
/// to the network.
#[derive(Clone)]
shamardy marked this conversation as resolved.
Show resolved Hide resolved
pub struct SentTransaction<'a> {
pub tx: &'a Transaction,
pub created: time::OffsetDateTime,
Expand Down
7 changes: 6 additions & 1 deletion zcash_client_sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ license = "MIT OR Apache-2.0"
edition = "2018"

[dependencies]
async-trait = "0.1.52"
bech32 = "0.9.1"
bs58 = { version = "0.4", features = ["check"] }
ff = "0.8"
futures = { version = "0.3", package = "futures", features = ["compat", "async-await"] }
group = "0.8"
jubjub = "0.5.1"
protobuf = "2.20"
rand_core = "0.5.1"
rusqlite = { version = "0.28", features = ["time"] }
rusqlite = { version = "0.28", features = ["bundled", "time"] }
onur-ozkan marked this conversation as resolved.
Show resolved Hide resolved
libsqlite3-sys= { version = "0.25.2", features = ["bundled"] }
time = "0.3"
tokio = { version = "1.20", features = ["full"] }
onur-ozkan marked this conversation as resolved.
Show resolved Hide resolved
zcash_client_backend = { version = "0.5", path = "../zcash_client_backend" }
zcash_extras = { version = "0.1", path = "../zcash_extras" }
zcash_primitives = { version = "0.5", path = "../zcash_primitives" }


[dev-dependencies]
rand_core = "0.5.1"
tempfile = "3"
Expand Down
182 changes: 182 additions & 0 deletions zcash_client_sqlite/src/for_async/init.rs
shamardy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
use crate::address_from_extfvk;
use crate::error::SqliteClientError;
use crate::for_async::{async_blocking, WalletDbAsync};
use rusqlite::ToSql;
use zcash_client_backend::encoding::encode_extended_full_viewing_key;
use zcash_primitives::block::BlockHash;
use zcash_primitives::consensus;
use zcash_primitives::consensus::BlockHeight;
use zcash_primitives::zip32::ExtendedFullViewingKey;

pub async fn init_wallet_db<P: consensus::Parameters + 'static>(
wdb: &WalletDbAsync<P>,
) -> Result<(), rusqlite::Error>
where
P: Clone + Send + Sync,
{
let wdb = wdb.inner.clone();
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
async_blocking(move || {
let wdb = wdb.lock().unwrap();

wdb.conn.execute(
"CREATE TABLE IF NOT EXISTS accounts (
account INTEGER PRIMARY KEY,
extfvk TEXT NOT NULL,
address TEXT NOT NULL
)",
[],
)?;
wdb.conn.execute(
"CREATE TABLE IF NOT EXISTS blocks (
height INTEGER PRIMARY KEY,
hash BLOB NOT NULL,
time INTEGER NOT NULL,
sapling_tree BLOB NOT NULL
)",
[],
)?;
wdb.conn.execute(
"CREATE TABLE IF NOT EXISTS transactions (
id_tx INTEGER PRIMARY KEY,
txid BLOB NOT NULL UNIQUE,
created TEXT,
block INTEGER,
tx_index INTEGER,
expiry_height INTEGER,
raw BLOB,
FOREIGN KEY (block) REFERENCES blocks(height)
)",
[],
)?;
wdb.conn.execute(
"CREATE TABLE IF NOT EXISTS received_notes (
id_note INTEGER PRIMARY KEY,
tx INTEGER NOT NULL,
output_index INTEGER NOT NULL,
account INTEGER NOT NULL,
diversifier BLOB NOT NULL,
value INTEGER NOT NULL,
rcm BLOB NOT NULL,
nf BLOB NOT NULL UNIQUE,
is_change INTEGER NOT NULL,
memo BLOB,
spent INTEGER,
FOREIGN KEY (tx) REFERENCES transactions(id_tx),
FOREIGN KEY (account) REFERENCES accounts(account),
FOREIGN KEY (spent) REFERENCES transactions(id_tx),
CONSTRAINT tx_output UNIQUE (tx, output_index)
)",
[],
)?;
wdb.conn.execute(
"CREATE TABLE IF NOT EXISTS sapling_witnesses (
id_witness INTEGER PRIMARY KEY,
note INTEGER NOT NULL,
block INTEGER NOT NULL,
witness BLOB NOT NULL,
FOREIGN KEY (note) REFERENCES received_notes(id_note),
FOREIGN KEY (block) REFERENCES blocks(height),
CONSTRAINT witness_height UNIQUE (note, block)
)",
[],
)?;
wdb.conn.execute(
"CREATE TABLE IF NOT EXISTS sent_notes (
id_note INTEGER PRIMARY KEY,
tx INTEGER NOT NULL,
output_index INTEGER NOT NULL,
from_account INTEGER NOT NULL,
address TEXT NOT NULL,
value INTEGER NOT NULL,
memo BLOB,
FOREIGN KEY (tx) REFERENCES transactions(id_tx),
FOREIGN KEY (from_account) REFERENCES accounts(account),
CONSTRAINT tx_output UNIQUE (tx, output_index)
)",
[],
)?;
Ok(())
shamardy marked this conversation as resolved.
Show resolved Hide resolved
})
.await
}

pub async fn init_accounts_table<P: consensus::Parameters + 'static>(
wdb: &WalletDbAsync<P>,
extfvks: &[ExtendedFullViewingKey],
) -> Result<(), SqliteClientError>
where
P: Clone + Send + Sync,
{
let wdb = wdb.inner.clone();
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
let extfvks = extfvks.to_vec();

async_blocking(move || {
let wdb = wdb.lock().unwrap();

let mut empty_check = wdb.conn.prepare("SELECT * FROM accounts LIMIT 1")?;
if empty_check.exists([])? {
return Err(SqliteClientError::TableNotEmpty);
}

// Insert accounts atomically
wdb.conn.execute("BEGIN IMMEDIATE", [])?;
for (account, extfvk) in extfvks.iter().enumerate() {
let extfvk_str = encode_extended_full_viewing_key(
wdb.params.hrp_sapling_extended_full_viewing_key(),
extfvk,
);

let address_str = address_from_extfvk(&wdb.params, extfvk);

wdb.conn.execute(
"INSERT INTO accounts (account, extfvk, address)
VALUES (?, ?, ?)",
[
(account as u32).to_sql()?,
extfvk_str.to_sql()?,
address_str.to_sql()?,
],
)?;
}
wdb.conn.execute("COMMIT", [])?;

Ok(())
shamardy marked this conversation as resolved.
Show resolved Hide resolved
})
.await
}

pub async fn init_blocks_table<P: consensus::Parameters + 'static>(
wdb: &WalletDbAsync<P>,
height: BlockHeight,
hash: BlockHash,
time: u32,
sapling_tree: &[u8],
) -> Result<(), SqliteClientError>
where
P: Clone + Send + Sync,
{
let wdb = wdb.inner.clone();
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
let sapling_tree = sapling_tree.to_vec().clone();
artemii235 marked this conversation as resolved.
Show resolved Hide resolved

async_blocking(move || {
let wdb = wdb.lock().unwrap();
let mut empty_check = wdb.conn.prepare("SELECT * FROM blocks LIMIT 1")?;
if empty_check.exists([])? {
return Err(SqliteClientError::TableNotEmpty);
}

wdb.conn.execute(
"INSERT INTO blocks (height, hash, time, sapling_tree)
VALUES (?, ?, ?, ?)",
[
u32::from(height).to_sql()?,
hash.0.to_sql()?,
time.to_sql()?,
sapling_tree.as_slice().to_sql()?,
],
)?;

Ok(())
shamardy marked this conversation as resolved.
Show resolved Hide resolved
})
.await
}
Loading