Skip to content

Commit

Permalink
Merge pull request #825 from fluidvanadium/hotfix_transparent_viewkey…
Browse files Browse the repository at this point in the history
…_missing

Hotfix transparent viewkey missing
  • Loading branch information
Oscar-Pepper authored Mar 8, 2024
2 parents f8c914a + f867077 commit 0d2d458
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
13 changes: 13 additions & 0 deletions integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ fn check_view_capability_bounds(
}

mod fast {
use zcash_address::unified::Encoding;
use zingolib::wallet::WalletBase;

use super::*;
#[tokio::test]
async fn utxos_are_not_prematurely_confirmed() {
Expand Down Expand Up @@ -696,6 +699,16 @@ mod fast {
assert!(addr.transparent().is_some());
}

let ufvk = wc.ufvk().unwrap();
let ufvk_string = ufvk.encode(&config.chain.to_zcash_address_network());
let ufvk_base = WalletBase::Ufvk(ufvk_string.clone());
let view_wallet =
LightWallet::new(config.clone(), ufvk_base, wallet.get_birthday().await).unwrap();
let v_wc = view_wallet.wallet_capability();
let vv = v_wc.ufvk().unwrap();
let vv_string = vv.encode(&config.chain.to_zcash_address_network());
assert_eq!(ufvk_string, vv_string);

let client = LightClient::create_from_wallet_async(wallet, config)
.await
.unwrap();
Expand Down
3 changes: 1 addition & 2 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,7 @@ impl LightClient {
self.get_server_uri(),
last_synced_height,
)
.await
.unwrap();
.await?;
self.wallet.initiate_witness_trees(trees).await;
};

Expand Down
5 changes: 3 additions & 2 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,14 @@ impl LightWallet {
/// Determines the target height for a transaction, and the offset from which to
/// select anchors, based on the current synchronised block chain.
async fn get_target_height_and_anchor_offset(&self) -> Option<(u32, usize)> {
match {
let range = {
let blocks = self.blocks.read().await;
(
blocks.last().map(|block| block.height as u32),
blocks.first().map(|block| block.height as u32),
)
} {
};
match range {
(Some(min_height), Some(max_height)) => {
let target_height = max_height + 1;

Expand Down
26 changes: 12 additions & 14 deletions zingolib/src/wallet/keys/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,22 @@ impl WalletCapability {
}
}

pub(crate) fn ufvk(&self) -> Result<Ufvk, zcash_address::unified::ParseError> {
let o_fvk = Fvk::Orchard(
orchard::keys::FullViewingKey::try_from(self)
.unwrap()
.to_bytes(),
);
pub fn ufvk(&self) -> Result<Ufvk, std::string::String> {
let o_fvk = Fvk::Orchard(orchard::keys::FullViewingKey::try_from(self)?.to_bytes());
let s_fvk = Fvk::Sapling(
zcash_primitives::zip32::sapling::DiversifiableFullViewingKey::try_from(self)
.unwrap()
zcash_primitives::zip32::sapling::DiversifiableFullViewingKey::try_from(self)?
.to_bytes(),
);
let mut t_fvk_bytes = [0u8; 65];
let t_ext_pk: ExtendedPubKey = self.try_into().unwrap();
t_fvk_bytes[0..32].copy_from_slice(&t_ext_pk.chain_code[..]);
t_fvk_bytes[32..65].copy_from_slice(&t_ext_pk.public_key.serialize()[..]);
let t_fvk = Fvk::P2pkh(t_fvk_bytes);
use zcash_address::unified::Encoding as _;
Ufvk::try_from_items(vec![o_fvk, s_fvk, t_fvk])
let possible_transparent_key: Result<ExtendedPubKey, String> = self.try_into();
if let Ok(t_ext_pk) = possible_transparent_key {
t_fvk_bytes[0..32].copy_from_slice(&t_ext_pk.chain_code[..]);
t_fvk_bytes[32..65].copy_from_slice(&t_ext_pk.public_key.serialize()[..]);
let t_fvk = Fvk::P2pkh(t_fvk_bytes);
Ufvk::try_from_items(vec![o_fvk, s_fvk, t_fvk]).map_err(|e| e.to_string())
} else {
Ufvk::try_from_items(vec![o_fvk, s_fvk]).map_err(|e| e.to_string())
}
}

pub fn new_address(
Expand Down

0 comments on commit 0d2d458

Please sign in to comment.