Skip to content

Commit

Permalink
Merge pull request #1505 from AloeareV/fix_diversified_address_shield
Browse files Browse the repository at this point in the history
fix shield when wallet contains more than one transparent address
  • Loading branch information
fluidvanadium authored Nov 11, 2024
2 parents c13b638 + e37f527 commit bb44853
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
33 changes: 33 additions & 0 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,39 @@ mod fast {
// Orchard action and dummy, plus 4 transparent inputs
let expected_fee = 30_000;

assert_eq!(proposal.steps().len(), 1);
assert_eq!(only_step.transparent_inputs().len(), 4);
assert_eq!(
only_step.balance().fee_required(),
NonNegativeAmount::const_from_u64(expected_fee)
);
// Only one change item. I guess change could be split between pools?
assert_eq!(only_step.balance().proposed_change().len(), 1);
assert_eq!(
only_step
.balance()
.proposed_change()
.first()
.unwrap()
.value(),
NonNegativeAmount::const_from_u64((block_rewards::CANOPY * 4) - expected_fee)
)
}
#[tokio::test]
async fn mine_to_transparent_and_propose_shielding_with_div_addr() {
let regtest_network = RegtestNetwork::all_upgrades_active();
let (regtest_manager, _cph, faucet, _recipient) =
scenarios::faucet_recipient(PoolType::Transparent, regtest_network).await;
increase_height_and_wait_for_client(&regtest_manager, &faucet, 1)
.await
.unwrap();
faucet.do_new_address("zto").await.unwrap();
let proposal = faucet.propose_shield().await.unwrap();
let only_step = proposal.steps().first();

// Orchard action and dummy, plus 4 transparent inputs
let expected_fee = 30_000;

assert_eq!(proposal.steps().len(), 1);
assert_eq!(only_step.transparent_inputs().len(), 4);
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use zcash_client_backend::{
wallet::{ReceivedNote, WalletTransparentOutput},
ShieldedProtocol,
};
use zcash_keys::encoding::AddressCodec;
use zcash_primitives::{
legacy::Script,
transaction::{
Expand Down Expand Up @@ -288,7 +289,7 @@ impl InputSource for TransactionRecordsById {

fn get_spendable_transparent_outputs(
&self,
_address: &zcash_primitives::legacy::TransparentAddress,
address: &zcash_primitives::legacy::TransparentAddress,
target_height: zcash_primitives::consensus::BlockHeight,
_min_confirmations: u32,
) -> Result<Vec<WalletTransparentOutput>, Self::Error> {
Expand All @@ -302,7 +303,12 @@ impl InputSource for TransactionRecordsById {
})
.flat_map(|tx| {
tx.transparent_outputs().iter().filter_map(|output| {
if output.spending_tx_status().is_none() {
if output.spending_tx_status().is_none()
&& (output.address
== address.encode(&zcash_primitives::consensus::MAIN_NETWORK)
|| output.address
== address.encode(&zcash_primitives::consensus::TEST_NETWORK))
{
WalletTransparentOutput::from_parts(
output.to_outpoint(),
TxOut {
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/wallet/tx_map/trait_stub_inputsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ impl InputSource for TxMap {

fn get_spendable_transparent_outputs(
&self,
_address: &zcash_primitives::legacy::TransparentAddress,
address: &zcash_primitives::legacy::TransparentAddress,
target_height: zcash_primitives::consensus::BlockHeight,
_min_confirmations: u32,
) -> Result<Vec<zcash_client_backend::wallet::WalletTransparentOutput>, Self::Error> {
self.transaction_records_by_id
.get_spendable_transparent_outputs(_address, target_height, _min_confirmations)
.get_spendable_transparent_outputs(address, target_height, _min_confirmations)
.map_err(TxMapTraitError::InputSource)
}
}

0 comments on commit bb44853

Please sign in to comment.