Skip to content

Commit

Permalink
zcash_client_sqlite: Clarify TransferType matches in `store_decrypt…
Browse files Browse the repository at this point in the history
…ed_tx`
  • Loading branch information
nuttycom committed Mar 25, 2024
1 parent 151e6e5 commit 531d21b
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,16 +1062,25 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>

for output in d_tx.sapling_outputs() {
match output.transfer_type() {
TransferType::Outgoing | TransferType::WalletInternal => {
let recipient = if output.transfer_type() == TransferType::Outgoing {
//TODO: Recover the UA, if possible.
Recipient::Sapling(output.note().recipient())
} else {
Recipient::InternalAccount {
receiving_account: *output.account(),
external_address: None,
note: Note::Sapling(output.note().clone()),
}
TransferType::Outgoing => {

Check warning on line 1065 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1065

Added line #L1065 was not covered by tests
//TODO: Recover the UA, if possible.
let recipient = Recipient::Sapling(output.note().recipient());
wallet::put_sent_output(
wdb.conn.0,
&wdb.params,
*output.account(),
tx_ref,
output.index(),
&recipient,
output.note_value(),
Some(output.memo()),
)?;
}
TransferType::WalletInternal => {

Check warning on line 1079 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1079

Added line #L1079 was not covered by tests
let recipient = Recipient::InternalAccount {
receiving_account: *output.account(),
external_address: None,
note: Note::Sapling(output.note().clone()),
};

wallet::put_sent_output(
Expand All @@ -1085,9 +1094,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
Some(output.memo()),
)?;

if matches!(recipient, Recipient::InternalAccount { .. }) {
wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?;
}
wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?;
}
TransferType::Incoming => {
wallet::sapling::put_received_note(wdb.conn.0, output, tx_ref, None)?;
Expand Down Expand Up @@ -1118,24 +1125,34 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
#[cfg(feature = "orchard")]
for output in d_tx.orchard_outputs() {
match output.transfer_type() {
TransferType::Outgoing | TransferType::WalletInternal => {
let recipient = if output.transfer_type() == TransferType::Outgoing {
// TODO: Recover the actual UA, if possible.
Recipient::Unified(
UnifiedAddress::from_receivers(
Some(output.note().recipient()),
None,
None,
)
.expect("UA has an Orchard receiver by construction."),
PoolType::Shielded(ShieldedProtocol::Orchard),
TransferType::Outgoing => {

Check warning on line 1128 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1128

Added line #L1128 was not covered by tests
// TODO: Recover the actual UA, if possible.
let recipient = Recipient::Unified(
UnifiedAddress::from_receivers(
Some(output.note().recipient()),
None,
None,

Check warning on line 1134 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1130-L1134

Added lines #L1130 - L1134 were not covered by tests
)
} else {
Recipient::InternalAccount {
receiving_account: *output.account(),
external_address: None,
note: Note::Orchard(*output.note()),
}
.expect("UA has an Orchard receiver by construction."),
PoolType::Shielded(ShieldedProtocol::Orchard),

Check warning on line 1137 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1136-L1137

Added lines #L1136 - L1137 were not covered by tests
);

wallet::put_sent_output(
wdb.conn.0,
&wdb.params,
*output.account(),
tx_ref,
output.index(),
&recipient,
output.note_value(),
Some(output.memo()),

Check warning on line 1148 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1140-L1148

Added lines #L1140 - L1148 were not covered by tests
)?;
}
TransferType::WalletInternal => {
let recipient = Recipient::InternalAccount {
receiving_account: *output.account(),
external_address: None,
note: Note::Orchard(*output.note()),

Check warning on line 1155 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1151-L1155

Added lines #L1151 - L1155 were not covered by tests
};

wallet::put_sent_output(
Expand All @@ -1149,9 +1166,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
Some(output.memo()),
)?;

if matches!(recipient, Recipient::InternalAccount { .. }) {
wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?;
}
wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?;

Check warning on line 1169 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L1169

Added line #L1169 was not covered by tests
}
TransferType::Incoming => {
wallet::orchard::put_received_note(wdb.conn.0, output, tx_ref, None)?;
Expand Down

0 comments on commit 531d21b

Please sign in to comment.