Skip to content

Commit

Permalink
remove do_shield and verify that cargo nextest run -p zingolib passes…
Browse files Browse the repository at this point in the history
… all tests
  • Loading branch information
zancas committed Jun 3, 2024
1 parent 622d4ea commit 86f7522
Showing 1 changed file with 0 additions and 77 deletions.
77 changes: 0 additions & 77 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
//! TODO: Add Mod Description Here!
use zcash_client_backend::{address::Address, PoolType, ShieldedProtocol};
use zcash_primitives::consensus::BlockHeight;
use zcash_primitives::transaction::fees::zip317::MINIMUM_FEE;
use zcash_primitives::transaction::TxId;
use zcash_proofs::prover::LocalTxProver;

use crate::utils::conversion::zatoshis_from_u64;

use super::LightClient;
use super::LightWalletSendProgress;
Expand All @@ -28,77 +22,6 @@ impl LightClient {
interrupt_sync: *self.interrupt_sync.read().await,
})
}

/// Shield funds. Send transparent or sapling funds to a unified address.
/// Defaults to the unified address of the capability if `address` is `None`.
pub async fn do_shield(
&self,
pools_to_shield: &[PoolType],
address: Option<Address>,
) -> Result<TxId, String> {
let transaction_submission_height = self.get_submission_height().await?;
let fee = u64::from(MINIMUM_FEE); // TODO: This can no longer be hard coded, and must be calced
// as a fn of the transactions structure.
let tbal = self
.wallet
.tbalance(None)
.await
.expect("to receive a balance");
let sapling_bal = self
.wallet
.spendable_sapling_balance(None)
.await
.unwrap_or(0);

// Make sure there is a balance, and it is greater than the amount
let balance_to_shield =
if pools_to_shield.contains(&PoolType::Transparent) {
tbal
} else {
0
} + if pools_to_shield.contains(&PoolType::Shielded(ShieldedProtocol::Sapling)) {
sapling_bal
} else {
0
};
if balance_to_shield <= fee {
return Err(format!(
"Not enough transparent/sapling balance to shield. Have {} zats, need more than {} zats to cover tx fee",
balance_to_shield, fee
));
}

let recipient_address = address.unwrap_or(Address::from(
self.wallet.wallet_capability().addresses()[0].clone(),
));
let amount = zatoshis_from_u64(balance_to_shield - fee)
.expect("balance cannot be outside valid range of zatoshis");
let receivers = vec![crate::data::receivers::Receiver {
recipient_address,
amount,
memo: None,
}];

let _lock = self.sync_lock.lock().await;
let (sapling_output, sapling_spend) = crate::wallet::utils::read_sapling_params()?;

let sapling_prover = LocalTxProver::from_bytes(&sapling_spend, &sapling_output);

self.wallet
.send_to_addresses(
sapling_prover,
pools_to_shield.to_vec(),
receivers,
transaction_submission_height,
|transaction_bytes| {
crate::grpc_connector::send_transaction(
self.get_server_uri(),
transaction_bytes,
)
},
)
.await
}
}

/// patterns for newfangled propose flow
Expand Down

0 comments on commit 86f7522

Please sign in to comment.