Skip to content

Commit

Permalink
solved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Dec 3, 2024
2 parents af8a5fe + 3d0a36e commit 255abde
Show file tree
Hide file tree
Showing 25 changed files with 111 additions and 155 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.

2 changes: 1 addition & 1 deletion libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn check_view_capability_bounds(
sent_t_value: Option<u64>,
notes: &JsonValue,
) {
let UnifiedKeyStore::View(ufvk) = watch_wc.unified_key_store() else {
let UnifiedKeyStore::View(ufvk) = &watch_wc.unified_key_store else {
panic!("should be viewing key!")
};
//Orchard
Expand Down
8 changes: 4 additions & 4 deletions libtonode-tests/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ async fn sync_mainnet_test() {
.await
.unwrap();

dbg!(lightclient.wallet.wallet_blocks());
dbg!(lightclient.wallet.nullifier_map());
dbg!(lightclient.wallet.sync_state());
dbg!(lightclient.wallet.wallet_blocks);
dbg!(lightclient.wallet.nullifier_map);
dbg!(lightclient.wallet.sync_state);
}

#[tokio::test]
Expand Down Expand Up @@ -90,7 +90,7 @@ async fn sync_test() {
.await
.unwrap();

dbg!(recipient.wallet.wallet_transactions());
dbg!(&recipient.wallet.wallet_transactions);
// dbg!(recipient.wallet.wallet_blocks());
// dbg!(recipient.wallet.nullifier_map());
// dbg!(recipient.wallet.outpoint_map());
Expand Down
1 change: 0 additions & 1 deletion zingolib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dirs.workspace = true
enum_dispatch = { workspace = true }
ff = { workspace = true }
futures = { workspace = true }
getset = { workspace = true }
group = { workspace = true }
hex = { workspace = true }
http.workspace = true
Expand Down
15 changes: 7 additions & 8 deletions zingolib/src/blaze/trial_decryptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ impl TrialDecryptions {
let mut workers = FuturesUnordered::new();
let mut cbs = vec![];

let sapling_ivk = sapling_crypto::zip32::DiversifiableFullViewingKey::try_from(
wc.unified_key_store(),
)
.ok()
.map(|key| key.derive_ivk());
let orchard_ivk = orchard::keys::FullViewingKey::try_from(wc.unified_key_store())
let sapling_ivk =
sapling_crypto::zip32::DiversifiableFullViewingKey::try_from(&wc.unified_key_store)
.ok()
.map(|key| key.derive_ivk());
let orchard_ivk = orchard::keys::FullViewingKey::try_from(&wc.unified_key_store)
.ok()
.map(|key| key.derive_ivk());

Expand Down Expand Up @@ -317,7 +316,7 @@ impl TrialDecryptions {
let config = config.clone();

workers.push(tokio::spawn(async move {
let Ok(fvk) = D::unified_key_store_to_fvk(wc.unified_key_store()) else {
let Ok(fvk) = D::unified_key_store_to_fvk(&wc.unified_key_store) else {
// skip any scanning if the wallet doesn't have viewing capability
return Ok::<_, String>(());
};
Expand Down Expand Up @@ -452,7 +451,7 @@ where
transaction_id,
Some(output_index),
position + i as u64,
&D::unified_key_store_to_fvk(wc.unified_key_store()).unwrap(),
&D::unified_key_store_to_fvk(&wc.unified_key_store).unwrap(),
)?;
}
nodes_retention.push((node, retention));
Expand Down
16 changes: 6 additions & 10 deletions zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Command for WalletKindCommand {
}
.pretty(4)
} else {
match lightclient.wallet.wallet_capability().unified_key_store() {
match &lightclient.wallet.wallet_capability().unified_key_store {
UnifiedKeyStore::Spend(_) => object! {
"kind" => "Loaded from unified spending key",
"transparent" => true,
Expand Down Expand Up @@ -746,15 +746,11 @@ impl Command for ExportUfvkCommand {
}

fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
let ufvk: UnifiedFullViewingKey = match lightclient
.wallet
.wallet_capability()
.unified_key_store()
.try_into()
{
Ok(ufvk) => ufvk,
Err(e) => return e.to_string(),
};
let ufvk: UnifiedFullViewingKey =
match (&lightclient.wallet.wallet_capability().unified_key_store).try_into() {
Ok(ufvk) => ufvk,
Err(e) => return e.to_string(),
};
object! {
"ufvk" => ufvk.encode(&lightclient.config().chain),
"birthday" => RT.block_on(lightclient.wallet.get_birthday())
Expand Down
12 changes: 6 additions & 6 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ pub mod send_with_proposal {
.await
.map_err(RecordCachedTransactionsError::Height)?;
let mut transactions_to_record = vec![];
if let Some(spending_data) = tx_map.spending_data_mut() {
for (_txid, raw_tx) in spending_data.cached_raw_transactions().iter() {
if let Some(spending_data) = &mut tx_map.spending_data {
for (_txid, raw_tx) in spending_data.cached_raw_transactions.iter() {
transactions_to_record.push(Transaction::read(
raw_tx.as_slice(),
zcash_primitives::consensus::BranchId::for_height(
Expand Down Expand Up @@ -206,12 +206,12 @@ pub mod send_with_proposal {
.await
.map_err(BroadcastCachedTransactionsError::Height)?;
let calculated_tx_cache = tx_map
.spending_data()
.spending_data
.as_ref()
.ok_or(BroadcastCachedTransactionsError::Cache(
TransactionCacheError::NoSpendCapability,
))?
.cached_raw_transactions()
.cached_raw_transactions
.clone();
let mut txids = vec![];
for (txid, raw_tx) in calculated_tx_cache {
Expand Down Expand Up @@ -251,12 +251,12 @@ pub mod send_with_proposal {
}

tx_map
.spending_data_mut()
.spending_data
.as_mut()
.ok_or(BroadcastCachedTransactionsError::Cache(
TransactionCacheError::NoSpendCapability,
))?
.cached_raw_transactions_mut()
.cached_raw_transactions
.clear();

Ok(txids)
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ pub mod regtest;
/// TODO: Add Doc Comment Here!
pub fn build_fvks_from_wallet_capability(wallet_capability: &WalletCapability) -> [Fvk; 3] {
let orchard_vk: orchard::keys::FullViewingKey =
wallet_capability.unified_key_store().try_into().unwrap();
(&wallet_capability.unified_key_store).try_into().unwrap();
let sapling_vk: sapling_crypto::zip32::DiversifiableFullViewingKey =
wallet_capability.unified_key_store().try_into().unwrap();
(&wallet_capability.unified_key_store).try_into().unwrap();
let transparent_vk: zcash_primitives::legacy::keys::AccountPubKey =
wallet_capability.unified_key_store().try_into().unwrap();
(&wallet_capability.unified_key_store).try_into().unwrap();

let mut transparent_vk_bytes = [0u8; 65];
transparent_vk_bytes.copy_from_slice(&transparent_vk.serialize());
Expand Down
23 changes: 7 additions & 16 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use error::KeyError;
use getset::{Getters, MutGetters};
use zcash_keys::keys::UnifiedFullViewingKey;
#[cfg(feature = "sync")]
use zcash_primitives::consensus::BlockHeight;
Expand Down Expand Up @@ -190,7 +189,6 @@ impl WalletBase {
}

/// In-memory wallet data struct
#[derive(Getters, MutGetters)]
pub struct LightWallet {
// The block at which this wallet was born. Rescans
// will start from here.
Expand Down Expand Up @@ -222,38 +220,31 @@ pub struct LightWallet {

/// Wallet compact blocks
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
wallet_blocks: BTreeMap<BlockHeight, WalletBlock>,
pub wallet_blocks: BTreeMap<BlockHeight, WalletBlock>,

/// Wallet transactions
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
wallet_transactions: HashMap<zcash_primitives::transaction::TxId, WalletTransaction>,
pub wallet_transactions: HashMap<zcash_primitives::transaction::TxId, WalletTransaction>,

/// Nullifier map
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
nullifier_map: NullifierMap,
pub nullifier_map: NullifierMap,

/// Outpoint map
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
outpoint_map: OutPointMap,

/// Shard trees
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
shard_trees: ShardTrees,

/// Sync state
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
sync_state: SyncState,
pub sync_state: SyncState,

/// Transparent addresses
#[cfg(feature = "sync")]
#[getset(get = "pub", get_mut = "pub")]
transparent_addresses: BTreeMap<TransparentAddressId, String>,
pub transparent_addresses: BTreeMap<TransparentAddressId, String>,
}

impl LightWallet {
Expand Down Expand Up @@ -286,7 +277,7 @@ impl LightWallet {
///TODO: Make this work for orchard too
pub async fn decrypt_message(&self, enc: Vec<u8>) -> Result<Message, String> {
let ufvk: UnifiedFullViewingKey =
match self.wallet_capability().unified_key_store().try_into() {
match (&self.wallet_capability().unified_key_store).try_into() {
Ok(ufvk) => ufvk,
Err(e) => return Err(e.to_string()),
};
Expand Down Expand Up @@ -398,7 +389,7 @@ impl LightWallet {
format!("could not create initial address: {e}"),
));
};
let transaction_metadata_set = if wc.unified_key_store().is_spending_key() {
let transaction_metadata_set = if wc.unified_key_store.is_spending_key() {
Arc::new(RwLock::new(TxMap::new_with_witness_trees(
wc.transparent_child_addresses().clone(),
wc.get_rejection_addresses().clone(),
Expand Down
8 changes: 4 additions & 4 deletions zingolib/src/wallet/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl LightWallet {
<D as Domain>::Recipient: Recipient,
{
// For the moment we encode lack of view capability as None
match self.wallet_capability().unified_key_store() {
match &self.wallet_capability().unified_key_store {
UnifiedKeyStore::Spend(_) => (),
UnifiedKeyStore::View(ufvk) => match D::SHIELDED_PROTOCOL {
ShieldedProtocol::Sapling => {
Expand Down Expand Up @@ -100,15 +100,15 @@ impl LightWallet {
<D as Domain>::Recipient: Recipient,
<D as Domain>::Note: PartialEq + Clone,
{
if let UnifiedKeyStore::Spend(_) = self.wallet_capability().unified_key_store() {
if let UnifiedKeyStore::Spend(_) = self.wallet_capability().unified_key_store {
self.confirmed_balance::<D>().await
} else {
None
}
}
/// Sums the transparent balance (unspent)
pub async fn get_transparent_balance(&self) -> Option<u64> {
match self.wallet_capability().unified_key_store() {
match &self.wallet_capability().unified_key_store {
UnifiedKeyStore::Spend(_) => (),
UnifiedKeyStore::View(ufvk) => {
ufvk.transparent()?;
Expand Down Expand Up @@ -195,7 +195,7 @@ impl LightWallet {
<D as Domain>::Recipient: Recipient,
<D as Domain>::Note: PartialEq + Clone,
{
D::unified_key_store_to_fvk(wallet_capability.unified_key_store()).expect("to get fvk from the unified key store")
D::unified_key_store_to_fvk(&wallet_capability.unified_key_store).expect("to get fvk from the unified key store")
.diversified_address(*note.diversifier())
.and_then(|address| {
D::ua_from_contained_receiver(wallet_capability, &address)
Expand Down
8 changes: 4 additions & 4 deletions zingolib/src/wallet/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl LightWallet {
// There is also the issue that the legacy transparent private key is derived an extra level to the external scope.
if external_version < 29 {
if let Some(mnemonic) = mnemonic.as_ref() {
wallet_capability.set_unified_key_store(UnifiedKeyStore::Spend(Box::new(
wallet_capability.unified_key_store = UnifiedKeyStore::Spend(Box::new(
UnifiedSpendingKey::from_seed(
&config.chain,
&mnemonic.0.to_seed(""),
Expand All @@ -238,8 +238,8 @@ impl LightWallet {
),
)
})?,
)));
} else if let UnifiedKeyStore::Spend(_) = wallet_capability.unified_key_store() {
));
} else if let UnifiedKeyStore::Spend(_) = &wallet_capability.unified_key_store {
return Err(io::Error::new(
ErrorKind::Other,
"loading from legacy spending keys with no seed phrase to recover",
Expand All @@ -248,7 +248,7 @@ impl LightWallet {
}

info!("Keys in this wallet:");
match wallet_capability.unified_key_store() {
match &wallet_capability.unified_key_store {
UnifiedKeyStore::Spend(_) => {
info!(" - orchard spending key");
info!(" - sapling extended spending key");
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/wallet/disk/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ pub async fn assert_wallet_capability_matches_seed(
let wc = wallet.wallet_capability();

// Compare USK
let UnifiedKeyStore::Spend(usk) = &wc.unified_key_store() else {
let UnifiedKeyStore::Spend(usk) = &wc.unified_key_store else {
panic!("Expected Unified Spending Key");
};
assert_eq!(
usk.to_bytes(Era::Orchard),
UnifiedSpendingKey::try_from(expected_wc.unified_key_store())
UnifiedSpendingKey::try_from(&expected_wc.unified_key_store)
.unwrap()
.to_bytes(Era::Orchard)
);
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/disk/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ async fn reload_wallet_from_buffer() {
.unwrap();
let wc = wallet.wallet_capability();

let UnifiedKeyStore::Spend(usk) = wc.unified_key_store() else {
let UnifiedKeyStore::Spend(usk) = &wc.unified_key_store else {
panic!("should be spending key!")
};
let UnifiedKeyStore::Spend(expected_usk) = expected_wc.unified_key_store() else {
let UnifiedKeyStore::Spend(expected_usk) = &expected_wc.unified_key_store else {
panic!("should be spending key!")
};

Expand Down Expand Up @@ -289,7 +289,7 @@ async fn reload_wallet_from_buffer() {
)
.unwrap();
let v_wc = view_wallet.wallet_capability();
let UnifiedKeyStore::View(v_ufvk) = v_wc.unified_key_store() else {
let UnifiedKeyStore::View(v_ufvk) = &v_wc.unified_key_store else {
panic!("should be viewing key!");
};
let v_ufvk_string = v_ufvk.encode(&wallet.transaction_context.config.chain);
Expand Down
Loading

0 comments on commit 255abde

Please sign in to comment.