Skip to content

Commit

Permalink
Scaffolding for introducing a LedgerCapability
Browse files Browse the repository at this point in the history
  • Loading branch information
pacu committed Nov 19, 2024
1 parent 39255ca commit 3edfed2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 9 additions & 1 deletion zingolib/src/wallet/keys/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ impl ReadableWriteable for LedgerKeys {
}
}

impl InternalCapability for LedgerKeys {
#[derive(Debug)]
pub (crate) struct LedgerCapability {}

impl LedgerCapability {
pub(crate) fn new() -> LedgerCapability {
LedgerCapability {}
}
}
impl InternalCapability for LedgerCapability {
fn get_ua_from_contained_transparent_receiver(
&self,
capability: &super::unified::WalletCapability,
Expand Down
22 changes: 9 additions & 13 deletions zingolib/src/wallet/keys/unified.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! TODO: Add Mod Description Here!
use std::sync::atomic;
use std::{
collections::{HashMap, HashSet},
io::{self, Read, Write},
Expand All @@ -20,13 +19,10 @@ use zcash_client_backend::address::UnifiedAddress;
use zcash_client_backend::keys::{Era, UnifiedSpendingKey};
use zcash_client_backend::wallet::TransparentAddressMetadata;
use zcash_encoding::{CompactSize, Vector};
use zcash_keys::keys::{DerivationError, UnifiedFullViewingKey};
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::consensus::{NetworkConstants, Parameters};
use zcash_primitives::legacy::{
keys::{AccountPubKey, IncomingViewingKey, NonHardenedChildIndex},
TransparentAddress,
};
use zcash_primitives::zip32::{AccountId, DiversifierIndex};
use zcash_primitives::legacy::TransparentAddress;
use zcash_primitives::zip32::AccountId;

use crate::wallet::error::KeyError;
use crate::wallet::traits::{DomainWalletExt, ReadableWriteable, Recipient};
Expand All @@ -36,8 +32,7 @@ use crate::{
};

use super::ledger::LedgerKeys;
use super::legacy::{generate_transparent_address_from_legacy_key, legacy_sks_to_usk, Capability};
use super::ToBase58Check;
use super::legacy::{legacy_sks_to_usk, Capability};

use crate::wallet::keys::capability::{InternalCapability, InMemoryWallet};

Expand Down Expand Up @@ -435,13 +430,16 @@ impl WalletCapability {
#[cfg(feature = "ledger-support")]
/// initializes a new wallet with a ledger
pub fn new_with_ledger(config: &ZingoConfig) -> Result<Self, KeyError> {
use super::ledger::LedgerCapability;

if !config.use_ledger {
return Err(KeyError::LedgerNotSet)
}

let mut wc = WalletCapability::default();

wc.ledger = Some(LedgerKeys::new());
wc.capability = Box::new(LedgerCapability::new());

Ok(wc)
}
Expand All @@ -450,12 +448,10 @@ impl WalletCapability {
pub(crate) fn get_taddrs(&self, chain: &crate::config::ChainType) -> HashSet<String> {
self.capability.get_taddrs(&self, chain)
}

/// TODO: Add Doc Comment Here!
pub fn first_sapling_address(&self) -> sapling_crypto::PaymentAddress {
// This index is dangerous, but all ways to instantiate a UnifiedSpendAuthority
// create it with a suitable first address
*self.addresses()[0].sapling().unwrap()
self.capability.first_sapling_address(&self)
}

/// TODO: Add Doc Comment Here!
Expand Down

0 comments on commit 3edfed2

Please sign in to comment.