Skip to content

Commit

Permalink
Merge pull request #1333 from fluidvanadium/trim_code
Browse files Browse the repository at this point in the history
remove uri struct field
  • Loading branch information
Oscar-Pepper authored Aug 28, 2024
2 parents bc35946 + 2aedda3 commit a0ccae4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
6 changes: 6 additions & 0 deletions zingolib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- `lightclient.bsync_data.uri()`

## [mobile-release-1.4.3-0-g9fa99407]

### Deprecated

- `lightclient::LightClient::do_list_transactions`
Expand Down
5 changes: 3 additions & 2 deletions zingolib/src/blaze/block_management_reorg_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl BlockManagementData {
/// currently of the opinion that this function should be factored into separate concerns.
pub(crate) async fn get_note_witness<D: DomainWalletExt>(
&self,
uri: Uri,
lightwalletd_uri: Uri,
height: BlockHeight,
transaction_num: usize,
output_num: usize,
Expand All @@ -521,7 +521,8 @@ impl BlockManagementData {
let tree = if prev_height < activation_height {
frontier::CommitmentTree::<<D::WalletNote as ShieldedNoteInterface>::Node, 32>::empty()
} else {
let tree_state = crate::grpc_connector::get_trees(uri, prev_height).await?;
let tree_state =
crate::grpc_connector::get_trees(lightwalletd_uri, prev_height).await?;
let tree = hex::decode(D::get_tree(&tree_state)).unwrap();
self.unverified_treestates.write().await.push(tree_state);
read_commitment_tree(&tree[..]).map_err(|e| format!("{}", e))?
Expand Down
10 changes: 1 addition & 9 deletions zingolib/src/blaze/syncdata.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
use std::sync::Arc;

use http::Uri;
use tokio::sync::RwLock;
use zcash_client_backend::proto::service::TreeState;

use super::{block_management_reorg_detection::BlockManagementData, sync_status::BatchSyncStatus};
use crate::config::ZingoConfig;
use crate::wallet::data::BlockData;
use crate::wallet::WalletOptions;

pub struct BlazeSyncData {
pub(crate) block_data: BlockManagementData,
uri: Arc<std::sync::RwLock<Uri>>,
pub(crate) wallet_options: WalletOptions,
}

impl BlazeSyncData {
pub fn new(config: &ZingoConfig) -> Self {
pub fn new() -> Self {
let sync_status = Arc::new(RwLock::new(BatchSyncStatus::default()));

Self {
uri: config.lightwalletd_uri.clone(),
block_data: BlockManagementData::new(sync_status),
wallet_options: WalletOptions::default(),
}
}

pub fn uri(&self) -> Uri {
self.uri.read().unwrap().clone()
}

pub async fn setup_nth_batch(
&mut self,
start_block: u64,
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/blaze/trial_decryptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ impl TrialDecryptions {
.collect::<Vec<_>>();
let maybe_decrypted_outputs =
zcash_note_encryption::batch::try_compact_note_decryption(&[ivk], &outputs);

for maybe_decrypted_output in maybe_decrypted_outputs.into_iter().enumerate() {
let (output_num, witnessed) =
if let (i, Some(((note, to), _ivk_num))) = maybe_decrypted_output {
Expand All @@ -321,15 +322,14 @@ impl TrialDecryptions {

//TODO: Wrong. We don't have fvk import, all our keys are spending
let have_spending_key = true;
let uri = bsync_data.read().await.uri().clone();

// Get the witness for the note
let witness = bsync_data
.read()
.await
.block_data
.get_note_witness::<D>(
uri,
config.get_lightwalletd_uri(),
height,
transaction_num,
i,
Expand Down
8 changes: 5 additions & 3 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub struct UserBalances {
pub incoming_dust: u64,
}

/// The LightClient provides a unified interface to the separate concerns that the zingolib library manages.
/// The LightClient connects one LightWallet to one lightwalletd server via gRPC.
/// 1. initialization of stored state
/// * from seed
/// * from keys
Expand All @@ -226,6 +226,8 @@ pub struct UserBalances {
/// 2. synchronization of the client with the state of the blockchain via a gRPC server
/// *
pub struct LightClient {
// / the LightClient connects to one server.
// pub(crate) server_uri: Arc<RwLock<Uri>>,
pub(crate) config: ZingoConfig,
/// TODO: Add Doc Comment Here!
pub wallet: LightWallet,
Expand All @@ -242,7 +244,7 @@ pub struct LightClient {
save_buffer: ZingoSaveBuffer,
}

/// This is the omnibus interface to the library, we are currently in the process of refining this typez broad definition!
/// all the wonderfully intertwined ways to conjure a LightClient
pub mod instantiation {
use log::debug;
use std::{
Expand Down Expand Up @@ -275,7 +277,7 @@ pub mod instantiation {
config: config.clone(),
mempool_monitor: std::sync::RwLock::new(None),
sync_lock: Mutex::new(()),
bsync_data: Arc::new(RwLock::new(BlazeSyncData::new(&config))),
bsync_data: Arc::new(RwLock::new(BlazeSyncData::new())),
interrupt_sync: Arc::new(RwLock::new(false)),
latest_proposal: Arc::new(RwLock::new(None)),
save_buffer: ZingoSaveBuffer::new(buffer),
Expand Down
8 changes: 8 additions & 0 deletions zingolib/src/wallet/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,16 @@ impl LightWallet {
WalletZecPriceInfo::read(&mut reader)?
};

// this initialization combines two types of data
let transaction_context = TransactionContext::new(
// Config data could be used differently based on the circumstances
// hardcoded?
// entered at init by user?
// stored on disk in a separate location and connected by a descendant library (such as zingo-mobile)?
config,
// Saveable Arc data
// - Arcs allow access between threads.
// - This data is loaded from the wallet file and but needs multithreaded access during sync.
Arc::new(wallet_capability),
Arc::new(RwLock::new(transactions)),
);
Expand Down

0 comments on commit a0ccae4

Please sign in to comment.