Skip to content

Commit

Permalink
finished cleaning up public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Feb 14, 2025
1 parent 07f5bcc commit 90e80f2
Show file tree
Hide file tree
Showing 33 changed files with 119 additions and 1,345 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ enum_dispatch = "0.3"
ff = "0.13"
futures = "0.3"
futures-util = "0.3"
getset = "0.1"
group = "0.13"
hex = "0.4"
http = "1"
Expand Down
8 changes: 4 additions & 4 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,24 +2224,24 @@ mod slow {
dbg!(wallet.sync_state.wallet_height());
dbg!(wallet
.shard_trees
.sapling()
.sapling
.store()
.max_checkpoint_id()
.unwrap());
dbg!(wallet
.shard_trees
.orchard()
.orchard
.store()
.max_checkpoint_id()
.unwrap());
dbg!(wallet
.shard_trees
.sapling()
.sapling
.root_at_checkpoint_id(&3.into())
.unwrap());
dbg!(wallet
.shard_trees
.orchard()
.orchard
.root_at_checkpoint_id(&3.into())
.unwrap());
drop(wallet);
Expand Down
3 changes: 0 additions & 3 deletions zingo-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ memuse.workspace = true
crossbeam-channel.workspace = true
rayon.workspace = true

# Minimise boilerplate
getset.workspace = true

# Error handling
thiserror.workspace = true

Expand Down
22 changes: 12 additions & 10 deletions zingo-sync/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use zcash_primitives::{
transaction::{Transaction, TxId},
};

pub mod fetch;
pub(crate) mod fetch;

/// Fetch requests are created and sent to the [`crate::client::fetch::fetch`] task when a connection to the server is required.
///
/// Each variant includes a [`tokio::sync::oneshot::Sender`] for returning the fetched data to the requester.
#[derive(Debug)]
pub enum FetchRequest {
pub(crate) enum FetchRequest {
/// Gets the height of the blockchain from the server.
ChainTip(oneshot::Sender<BlockId>),
/// Gets the specified range of compact blocks from the server (end exclusive).
Expand All @@ -38,6 +38,7 @@ pub enum FetchRequest {
/// Get a full transaction by txid.
Transaction(oneshot::Sender<(Transaction, BlockHeight)>, TxId),
/// Get a list of unspent transparent output metadata for a given list of transparent addresses and start height.
#[allow(dead_code)]
UtxoMetadata(
oneshot::Sender<Vec<GetAddressUtxosReply>>,
(Vec<String>, BlockHeight),
Expand All @@ -59,7 +60,7 @@ pub enum FetchRequest {
/// Gets the height of the blockchain from the server.
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_chain_height(
pub(crate) async fn get_chain_height(
fetch_request_sender: UnboundedSender<FetchRequest>,
) -> Result<BlockHeight, ()> {
let (reply_sender, reply_receiver) = oneshot::channel();
Expand All @@ -74,7 +75,7 @@ pub async fn get_chain_height(
/// Gets the specified range of compact blocks from the server (end exclusive).
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_compact_block_range(
pub(crate) async fn get_compact_block_range(
fetch_request_sender: UnboundedSender<FetchRequest>,
block_range: Range<BlockHeight>,
) -> Result<tonic::Streaming<CompactBlock>, ()> {
Expand All @@ -91,7 +92,7 @@ pub async fn get_compact_block_range(
/// from the server.
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_subtree_roots(
pub(crate) async fn get_subtree_roots(
fetch_request_sender: UnboundedSender<FetchRequest>,
start_index: u32,
shielded_protocol: i32,
Expand All @@ -118,7 +119,7 @@ pub async fn get_subtree_roots(
/// Gets the frontiers for a specified block height.
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_frontiers(
pub(crate) async fn get_frontiers(
fetch_request_sender: UnboundedSender<FetchRequest>,
block_height: BlockHeight,
) -> Result<ChainState, ()> {
Expand All @@ -135,7 +136,7 @@ pub async fn get_frontiers(
/// Gets a full transaction for a specified txid.
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_transaction_and_block_height(
pub(crate) async fn get_transaction_and_block_height(
fetch_request_sender: UnboundedSender<FetchRequest>,
txid: TxId,
) -> Result<(Transaction, BlockHeight), ()> {
Expand All @@ -151,7 +152,8 @@ pub async fn get_transaction_and_block_height(
/// Gets unspent transparent output metadata for a list of `transparent addresses` from the specified `start_height`.
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_utxo_metadata(
#[allow(dead_code)]
pub(crate) async fn get_utxo_metadata(
fetch_request_sender: UnboundedSender<FetchRequest>,
transparent_addresses: Vec<String>,
start_height: BlockHeight,
Expand All @@ -175,7 +177,7 @@ pub async fn get_utxo_metadata(
/// Gets transactions relevant to a given `transparent address` in the specified `block_range`.
///
/// Requires [`crate::client::fetch::fetch`] to be running concurrently, connected via the `fetch_request` channel.
pub async fn get_transparent_address_transactions(
pub(crate) async fn get_transparent_address_transactions(
fetch_request_sender: UnboundedSender<FetchRequest>,
transparent_address: String,
block_range: Range<BlockHeight>,
Expand All @@ -193,7 +195,7 @@ pub async fn get_transparent_address_transactions(
}

/// Gets stream of mempool transactions until the next block is mined.
pub async fn get_mempool_transaction_stream(
pub(crate) async fn get_mempool_transaction_stream(
client: &mut CompactTxStreamerClient<zingo_netutils::UnderlyingService>,
) -> Result<tonic::Streaming<RawTransaction>, ()> {
tracing::debug!("Fetching mempool stream");
Expand Down
2 changes: 1 addition & 1 deletion zingo-sync/src/client/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::client::FetchRequest;
///
/// Allows all requests to the server to be handled from a single task for efficiency and also enables
/// request prioritisation for further performance enhancement
pub async fn fetch(
pub(crate) async fn fetch(
mut fetch_request_receiver: UnboundedReceiver<FetchRequest>,
mut client: CompactTxStreamerClient<zingo_netutils::UnderlyingService>,
consensus_parameters: impl consensus::Parameters,
Expand Down
23 changes: 18 additions & 5 deletions zingo-sync/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::collections::HashMap;

use getset::Getters;
use incrementalmerkletree::Position;
use orchard::{
keys::{FullViewingKey, IncomingViewingKey},
Expand All @@ -13,6 +12,7 @@ use sapling_crypto::{
};
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_note_encryption::Domain;
use zcash_primitives::consensus;
use zip32::Scope;

/// Child index for the `address_index` path level in the BIP44 hierarchy.
Expand Down Expand Up @@ -135,11 +135,9 @@ impl ScanningKeyOps<OrchardDomain, orchard::note::Nullifier>
}

/// A set of keys to be used in scanning for decryptable transaction outputs.
#[derive(Getters)]
#[getset(get = "pub(crate)")]
pub(crate) struct ScanningKeys {
sapling: HashMap<KeyId, ScanningKey<SaplingIvk, NullifierDerivingKey>>,
orchard: HashMap<KeyId, ScanningKey<IncomingViewingKey, FullViewingKey>>,
pub(crate) sapling: HashMap<KeyId, ScanningKey<SaplingIvk, NullifierDerivingKey>>,
pub(crate) orchard: HashMap<KeyId, ScanningKey<IncomingViewingKey, FullViewingKey>>,
}

impl ScanningKeys {
Expand Down Expand Up @@ -188,3 +186,18 @@ impl ScanningKeys {
Self { sapling, orchard }
}
}

pub(crate) fn encode_orchard_receiver(
parameters: &impl consensus::Parameters,
orchard_address: &orchard::Address,
) -> Result<String, ()> {
Ok(zcash_address::unified::Encoding::encode(
&<zcash_address::unified::Address as zcash_address::unified::Encoding>::try_from_items(
vec![zcash_address::unified::Receiver::Orchard(
orchard_address.to_raw_address_bytes(),
)],
)
.unwrap(),
&parameters.network_type(),
))
}
2 changes: 1 addition & 1 deletion zingo-sync/src/keys/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct TransparentAddressId {

impl TransparentAddressId {
/// Construct from parts
pub fn from_parts(
pub fn new(
account_id: zcash_primitives::zip32::AccountId,
scope: TransparentScope,
address_index: AddressIndex,
Expand Down
9 changes: 3 additions & 6 deletions zingo-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
//! of the previous sync, before the server is contacted to update the wallet height to the new chain height.
//! Fully scanned height - block height in which the wallet has completed scanning all blocks equal to and below this height.
pub mod client;
pub(crate) mod client;
pub mod error;
pub mod keys;
#[allow(missing_docs)]
pub mod primitives;
pub(crate) mod scan;
pub mod sync;
pub mod traits;
pub(crate) mod utils;
pub mod witness;
pub mod wallet;
pub(crate) mod witness;

pub use sync::scan_pending_transaction;
pub use sync::sync;
Expand Down
Loading

0 comments on commit 90e80f2

Please sign in to comment.