Skip to content

Commit

Permalink
Merge pull request #1269 from fluidvanadium/remove_send_to_addresses
Browse files Browse the repository at this point in the history
Remove send_to_addresses
  • Loading branch information
zancas authored Jul 21, 2024
2 parents b2d92a3 + 849ee58 commit bdc834f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 796 deletions.
2 changes: 2 additions & 0 deletions zingolib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `fix_spent_at_height`
- `TransactionRecord::net_spent`
- `TransactionRecord::get_transparent_value_spent()`
- `LightWallet`:
- `send_to_addresses`
151 changes: 76 additions & 75 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,92 +109,93 @@ pub mod send_with_proposal {
&self,
proposal: &Proposal<zcash_primitives::transaction::fees::zip317::FeeRule, NoteRef>,
) -> Result<NonEmpty<TxId>, CompleteAndBroadcastError> {
let result = {
if self
.wallet
.transaction_context
.transaction_metadata_set
.read()
.await
.witness_trees()
.is_none()
{
return Err(CompleteAndBroadcastError::NoSpendCapability);
}
let submission_height = self
.get_submission_height()
.await
.map_err(CompleteAndBroadcastError::SubmissionHeight)?;
if self
.wallet
.transaction_context
.transaction_metadata_set
.read()
.await
.witness_trees()
.is_none()
{
return Err(CompleteAndBroadcastError::NoSpendCapability);
}

let (sapling_output, sapling_spend): (Vec<u8>, Vec<u8>) =
read_sapling_params().map_err(CompleteAndBroadcastError::SaplingParams)?;
let sapling_prover = LocalTxProver::from_bytes(&sapling_spend, &sapling_output);
let unified_spend_key =
UnifiedSpendingKey::try_from(self.wallet.wallet_capability().as_ref())
.map_err(CompleteAndBroadcastError::UnifiedSpendKey)?;
// Reset the progress to start. Any errors will get recorded here
self.wallet.reset_send_progress().await;

// We don't support zip320 yet. Only one step.
if proposal.steps().len() != 1 {
return Err(CompleteAndBroadcastError::ExchangeAddressesNotSupported);
}
let submission_height = self
.get_submission_height()
.await
.map_err(CompleteAndBroadcastError::SubmissionHeight)?;

let (sapling_output, sapling_spend): (Vec<u8>, Vec<u8>) =
read_sapling_params().map_err(CompleteAndBroadcastError::SaplingParams)?;
let sapling_prover = LocalTxProver::from_bytes(&sapling_spend, &sapling_output);
let unified_spend_key =
UnifiedSpendingKey::try_from(self.wallet.wallet_capability().as_ref())
.map_err(CompleteAndBroadcastError::UnifiedSpendKey)?;

// We don't support zip320 yet. Only one step.
if proposal.steps().len() != 1 {
return Err(CompleteAndBroadcastError::ExchangeAddressesNotSupported);
}

let step = proposal.steps().first();
let step = proposal.steps().first();

// The 'UnifiedSpendingKey' we create is not a 'proper' USK, in that the
// transparent key it contains is not the account spending key, but the
// externally-scoped derivative key. The goal is to fix this, but in the
// interim we use this special-case logic.
fn usk_to_tkey(
unified_spend_key: &UnifiedSpendingKey,
t_metadata: &TransparentAddressMetadata,
) -> SecretKey {
hdwallet::ExtendedPrivKey::deserialize(
&unified_spend_key.transparent().to_bytes(),
)
// The 'UnifiedSpendingKey' we create is not a 'proper' USK, in that the
// transparent key it contains is not the account spending key, but the
// externally-scoped derivative key. The goal is to fix this, but in the
// interim we use this special-case logic.
fn usk_to_tkey(
unified_spend_key: &UnifiedSpendingKey,
t_metadata: &TransparentAddressMetadata,
) -> SecretKey {
hdwallet::ExtendedPrivKey::deserialize(&unified_spend_key.transparent().to_bytes())
.expect("This a hack to do a type conversion, and will not fail")
.derive_private_key(t_metadata.address_index().into())
// This is unwrapped in librustzcash, so I'm not too worried about it
.expect("private key derivation failed")
.private_key
}
}

let build_result =
zcash_client_backend::data_api::wallet::calculate_proposed_transaction(
self.wallet
.transaction_context
.transaction_metadata_set
.write()
.await
.deref_mut(),
&self.wallet.transaction_context.config.chain,
&sapling_prover,
&sapling_prover,
&unified_spend_key,
zcash_client_backend::wallet::OvkPolicy::Sender,
proposal.fee_rule(),
proposal.min_target_height(),
&[],
step,
Some(usk_to_tkey),
Some(self.wallet.wallet_capability().first_sapling_address()),
)
.map_err(CompleteAndBroadcastError::Calculation)?;
let build_result =
zcash_client_backend::data_api::wallet::calculate_proposed_transaction(
self.wallet
.transaction_context
.transaction_metadata_set
.write()
.await
.deref_mut(),
&self.wallet.transaction_context.config.chain,
&sapling_prover,
&sapling_prover,
&unified_spend_key,
zcash_client_backend::wallet::OvkPolicy::Sender,
proposal.fee_rule(),
proposal.min_target_height(),
&[],
step,
Some(usk_to_tkey),
Some(self.wallet.wallet_capability().first_sapling_address()),
)
.map_err(CompleteAndBroadcastError::Calculation)?;

self.wallet
.send_to_addresses_inner(
build_result.transaction(),
submission_height,
|transaction_bytes| {
crate::grpc_connector::send_transaction(
self.get_server_uri(),
transaction_bytes,
)
},
)
.await
.map_err(CompleteAndBroadcastError::Broadcast)
.map(NonEmpty::singleton)
};
let result = self
.wallet
.send_to_addresses_inner(
build_result.transaction(),
submission_height,
|transaction_bytes| {
crate::grpc_connector::send_transaction(
self.get_server_uri(),
transaction_bytes,
)
},
)
.await
.map_err(CompleteAndBroadcastError::Broadcast)
.map(NonEmpty::singleton);

self.wallet
.set_send_result(
Expand Down
Loading

0 comments on commit bdc834f

Please sign in to comment.