zcash_client_sqlite: Clarify `TransferType` matches in `store_decrypted_tx`

This commit is contained in:
Kris Nuttycombe 2024-03-25 11:51:20 -06:00
parent 151e6e526e
commit 4ba7fbd977
1 changed files with 50 additions and 35 deletions

View File

@ -1062,16 +1062,27 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
for output in d_tx.sapling_outputs() { for output in d_tx.sapling_outputs() {
match output.transfer_type() { match output.transfer_type() {
TransferType::Outgoing | TransferType::WalletInternal => { TransferType::Outgoing => {
let recipient = if output.transfer_type() == TransferType::Outgoing {
//TODO: Recover the UA, if possible. //TODO: Recover the UA, if possible.
Recipient::Sapling(output.note().recipient()) let recipient = Recipient::Sapling(output.note().recipient());
} else { wallet::put_sent_output(
Recipient::InternalAccount { wdb.conn.0,
&wdb.params,
*output.account(),
tx_ref,
output.index(),
&recipient,
output.note_value(),
Some(output.memo()),
)?;
}
TransferType::WalletInternal => {
wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?;
let recipient = Recipient::InternalAccount {
receiving_account: *output.account(), receiving_account: *output.account(),
external_address: None, external_address: None,
note: Note::Sapling(output.note().clone()), note: Note::Sapling(output.note().clone()),
}
}; };
wallet::put_sent_output( wallet::put_sent_output(
@ -1084,10 +1095,6 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
output.note_value(), output.note_value(),
Some(output.memo()), Some(output.memo()),
)?; )?;
if matches!(recipient, Recipient::InternalAccount { .. }) {
wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?;
}
} }
TransferType::Incoming => { TransferType::Incoming => {
wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?; wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?;
@ -1118,10 +1125,9 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
#[cfg(feature = "orchard")] #[cfg(feature = "orchard")]
for output in d_tx.orchard_outputs() { for output in d_tx.orchard_outputs() {
match output.transfer_type() { match output.transfer_type() {
TransferType::Outgoing | TransferType::WalletInternal => { TransferType::Outgoing => {
let recipient = if output.transfer_type() == TransferType::Outgoing {
// TODO: Recover the actual UA, if possible. // TODO: Recover the actual UA, if possible.
Recipient::Unified( let recipient = Recipient::Unified(
UnifiedAddress::from_receivers( UnifiedAddress::from_receivers(
Some(output.note().recipient()), Some(output.note().recipient()),
None, None,
@ -1129,13 +1135,26 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
) )
.expect("UA has an Orchard receiver by construction."), .expect("UA has an Orchard receiver by construction."),
PoolType::Shielded(ShieldedProtocol::Orchard), PoolType::Shielded(ShieldedProtocol::Orchard),
) );
} else {
Recipient::InternalAccount { wallet::put_sent_output(
wdb.conn.0,
&wdb.params,
*output.account(),
tx_ref,
output.index(),
&recipient,
output.note_value(),
Some(output.memo()),
)?;
}
TransferType::WalletInternal => {
wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?;
let recipient = Recipient::InternalAccount {
receiving_account: *output.account(), receiving_account: *output.account(),
external_address: None, external_address: None,
note: Note::Orchard(*output.note()), note: Note::Orchard(*output.note()),
}
}; };
wallet::put_sent_output( wallet::put_sent_output(
@ -1148,10 +1167,6 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
output.note_value(), output.note_value(),
Some(output.memo()), Some(output.memo()),
)?; )?;
if matches!(recipient, Recipient::InternalAccount { .. }) {
wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?;
}
} }
TransferType::Incoming => { TransferType::Incoming => {
wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?; wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?;