Figure out the account ID for z->t spends.

This commit is contained in:
Kris Nuttycombe 2021-03-29 14:55:15 -06:00
parent 13cd7498b7
commit 665c4c7aff
3 changed files with 26 additions and 16 deletions

View File

@ -206,7 +206,6 @@ pub struct PrunedBlock<'a> {
/// wallet database when transactions are successfully decrypted.
pub struct DecryptedTransaction<'a> {
pub tx: &'a Transaction,
pub account_id: AccountId,
pub sapling_outputs: &'a Vec<DecryptedOutput>,
}

View File

@ -58,7 +58,6 @@ where
if !(sapling_outputs.is_empty() && tx.vout.is_empty()) {
data.store_decrypted_tx(&DecryptedTransaction {
tx,
account_id: AccountId(0), //FIXME
sapling_outputs: &sapling_outputs,
})?;
}

View File

@ -521,6 +521,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
self.transactionally(|up| {
let tx_ref = wallet::put_tx_data(up, d_tx.tx, None)?;
let mut spending_account_id: Option<AccountId> = None;
for output in d_tx.sapling_outputs {
if output.outgoing {
wallet::put_sent_note(
@ -529,12 +530,21 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
output.index,
output.account,
RecipientAddress::Shielded(output.to.clone()),
Amount::from_u64(output.note.value).map_err(|_| {
SqliteClientError::CorruptedData("Note value invalid.".to_string())
})?,
Amount::from_u64(output.note.value)
.map_err(|_| SqliteClientError::CorruptedData("Note value invalid.".to_string()))?,
Some(&output.memo),
)?;
} else {
match spending_account_id {
Some(id) =>
if id != output.account {
panic!("Unable to determine a unique account identifier for z->t spend.");
}
None => {
spending_account_id = Some(output.account);
}
}
wallet::put_received_note(up, output, tx_ref)?;
}
}
@ -544,17 +554,19 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
// as our z->t tx and store the vouts as our sent notes.
// FIXME this is a weird heuristic that is bound to trip us up somewhere.
if d_tx.sapling_outputs.iter().any(|output| !output.outgoing) {
for (i, txout) in d_tx.tx.vout.iter().enumerate() {
// FIXME: We shouldn't be confusing notes and transparent outputs.
wallet::insert_sent_note(
up,
tx_ref,
i,
d_tx.account_id,
&RecipientAddress::Transparent(txout.script_pubkey.address().unwrap()),
txout.value,
None,
)?;
if let Some(account_id) = spending_account_id {
for (i, txout) in d_tx.tx.vout.iter().enumerate() {
// FIXME: We shouldn't be confusing notes and transparent outputs.
wallet::put_sent_note(
up,
tx_ref,
i,
account_id,
RecipientAddress::Transparent(txout.script_pubkey.address().unwrap()),
txout.value,
None,
)?;
}
}
}