Skip to content

Commit

Permalink
Merge pull request zingolabs#1248 from fluidvanadium/remove_old_send
Browse files Browse the repository at this point in the history
Remove old send
  • Loading branch information
zancas authored Jun 29, 2024
2 parents ba1d202 + 139174c commit 317aa69
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 139 deletions.
27 changes: 1 addition & 26 deletions zingo-testutils/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn get_fees_paid_by_client(client: &LightClient) -> u64 {
}
/// Helpers to provide raw_receivers to lightclients for send and shield, etc.
pub mod from_inputs {
use zcash_client_backend::PoolType;

use zingolib::lightclient::{send::send_with_proposal::QuickSendError, LightClient};

/// Panics if the address, amount or memo conversion fails.
Expand Down Expand Up @@ -71,31 +71,6 @@ pub mod from_inputs {
.collect()
}

/// In a test give sender a raw_receiver to encode and send to
pub async fn send(
sender: &zingolib::lightclient::LightClient,
raw_receivers: Vec<(&str, u64, Option<&str>)>,
) -> Result<String, String> {
let receivers = receivers_from_send_inputs(raw_receivers, &sender.config().chain);
sender.do_send(receivers).await.map(|txid| txid.to_string())
}

/// Panics if the address conversion fails.
pub async fn shield(
shielder: &LightClient,
pools_to_shield: &[PoolType],
address: Option<&str>,
) -> Result<String, String> {
let address = address.map(|addr| {
zingolib::utils::conversion::address_from_str(addr, &shielder.config().chain)
.expect("should be a valid address")
});
shielder
.do_shield(pools_to_shield, address)
.await
.map(|txid| txid.to_string())
}

/// Creates a [`zcash_client_backend::zip321::TransactionRequest`] from rust primitives for simplified test writing.
pub fn transaction_request_from_send_inputs(
requester: &zingolib::lightclient::LightClient,
Expand Down
2 changes: 2 additions & 0 deletions zingolib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `load_clientconfig` moved to zingoconfig crate
- `lightclient::LightClient`:
- `do_save`
- `do_send`
- `do_shield`
- `do_save_to_buffer`
- `do_save_to_buffer_sync`
- `fix_spent_at_height`
Expand Down
113 changes: 0 additions & 113 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
//! TODO: Add Mod Description Here!
use log::debug;

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::data::receivers::Receivers;
use crate::utils::conversion::zatoshis_from_u64;

use super::LightClient;
use super::LightWalletSendProgress;
Expand All @@ -22,40 +14,6 @@ impl LightClient {
) + 1)
}

/// Send funds
pub async fn do_send(&self, receivers: Receivers) -> Result<TxId, String> {
let transaction_submission_height = self.get_submission_height().await?;
// First, get the consensus branch ID
debug!("Creating transaction");

let _lock = self.sync_lock.lock().await;
// I am not clear on how long this operation may take, but it's
// clearly unnecessary in a send that doesn't include sapling
// TODO: Remove from sends that don't include Sapling
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,
vec![
PoolType::Shielded(ShieldedProtocol::Orchard),
PoolType::Shielded(ShieldedProtocol::Sapling),
], // This policy doesn't allow
// spend from transparent.
receivers,
transaction_submission_height,
|transaction_bytes| {
crate::grpc_connector::send_transaction(
self.get_server_uri(),
transaction_bytes,
)
},
)
.await
}

/// TODO: Add Doc Comment Here!
pub async fn do_send_progress(&self) -> Result<LightWalletSendProgress, String> {
let progress = self.wallet.get_send_progress().await;
Expand All @@ -64,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 = if let Some(tbal) = self.wallet.tbalance().await {
tbal
} else {
return Err("no tbal!".to_string());
};
let sapling_bal = self
.wallet
.spendable_balance::<sapling_crypto::note_encryption::SaplingDomain>()
.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 317aa69

Please sign in to comment.