Skip to content

Commit

Permalink
Merge pull request #8 from KomodoPlatform/mm2_extras
Browse files Browse the repository at this point in the history
make lib komodefi compatible
  • Loading branch information
shamardy authored Nov 7, 2023
2 parents e75a5ea + 8c97f56 commit debae77
Show file tree
Hide file tree
Showing 15 changed files with 1,258 additions and 244 deletions.
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
13 changes: 12 additions & 1 deletion zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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"] }
Expand All @@ -27,10 +28,15 @@ proptest = { version = "0.10.1", optional = true }
protobuf = "2.20"
rand_core = "0.5.1"
subtle = "2.2.3"
time = "0.3"
zcash_note_encryption = { version = "0.0", path = "../components/zcash_note_encryption" }
zcash_primitives = { version = "0.5", path = "../zcash_primitives" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
time = "0.3.20"

[target.'cfg(target_arch = "wasm32")'.dependencies]
time = { version = "0.3.20", features = ["wasm-bindgen"]}

[build-dependencies]
protobuf-codegen-pure = "2.20"

Expand All @@ -40,8 +46,13 @@ rand_core = "0.5.1"
rand_xorshift = "0.2"
tempfile = "3.1.0"
zcash_client_sqlite = { version = "0.3", path = "../zcash_client_sqlite" }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
zcash_proofs = { version = "0.5", path = "../zcash_proofs" }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
zcash_proofs = { version = "0.5", path = "../zcash_proofs", default-features = false, features = ["local-prover"]}

[features]
test-dependencies = ["proptest", "zcash_primitives/test-dependencies"]

Expand Down
8 changes: 5 additions & 3 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
//! Functions for scanning the chain and extracting relevant information.
use std::fmt::Debug;

use zcash_primitives::consensus::NetworkUpgrade;
use zcash_primitives::transaction::Transaction;
use zcash_primitives::{
consensus::{self, BranchId, NetworkUpgrade},
consensus::{self, BranchId},
memo::MemoBytes,
sapling::prover::TxProver,
transaction::{
builder::Builder,
components::{amount::DEFAULT_FEE, Amount},
Transaction,
},
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey},
};

use crate::data_api::ReceivedTransaction;
use crate::{
address::RecipientAddress,
data_api::{error::Error, ReceivedTransaction, SentTransaction, WalletWrite},
data_api::{error::Error, SentTransaction, WalletWrite},
decrypt_transaction,
wallet::{AccountId, OvkPolicy},
};
Expand Down
5 changes: 4 additions & 1 deletion zcash_client_sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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"
Expand All @@ -22,8 +23,10 @@ protobuf = "2.20"
rand_core = "0.5.1"
rusqlite = { version = "0.28", features = ["time"] }
libsqlite3-sys= { version = "0.25.2", features = ["bundled"] }
time = "0.3"
time = "0.3.20"
tokio = { version = "1.20", features = ["rt", "rt-multi-thread"] }
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]
Expand Down
6 changes: 2 additions & 4 deletions zcash_client_sqlite/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@ mod tests {
chain::{scan_cached_blocks, validate_chain},
error::{ChainInvalid, Error},
};
use zcash_extras::{fake_compact_block, fake_compact_block_spending};

use crate::{
chain::init::init_cache_database,
error::SqliteClientError,
tests::{
self, fake_compact_block, fake_compact_block_spending, insert_into_cache,
sapling_activation_height,
},
tests::{self, insert_into_cache, sapling_activation_height},
wallet::{
get_balance,
init::{init_accounts_table, init_wallet_db},
Expand Down
56 changes: 56 additions & 0 deletions zcash_client_sqlite/src/for_async/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::error::SqliteClientError;
use crate::for_async::{async_blocking, WalletDbAsync};
use crate::wallet;
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();
async_blocking(move || {
let wdb = wdb.lock().unwrap();
wallet::init::init_wallet_db(&wdb)
})
.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();
let extfvks = extfvks.to_vec();
async_blocking(move || {
let wdb = wdb.lock().unwrap();
wallet::init::init_accounts_table(&wdb, &extfvks)
})
.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();
let sapling_tree = sapling_tree.to_vec();
async_blocking(move || {
let wdb = wdb.lock().unwrap();
wallet::init::init_blocks_table(&wdb, height, hash, time, &sapling_tree)
})
.await
}
Loading

0 comments on commit debae77

Please sign in to comment.