Skip to content

Commit

Permalink
zcash_client_sqlite: Ensure we set mined-ness information in `store_d…
Browse files Browse the repository at this point in the history
…ecrypted_tx`
  • Loading branch information
nuttycom committed Aug 16, 2024
1 parent 54f59a8 commit 895d92b
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ use zcash_client_backend::{
scanning::{ScanPriority, ScanRange},
Account, AccountBirthday, AccountPurpose, AccountSource, BlockMetadata,
DecryptedTransaction, InputSource, NullifierQuery, ScannedBlock, SeedRelevance,
SentTransaction, SpendableNotes, TransactionDataRequest, WalletCommitmentTrees, WalletRead,
WalletSummary, WalletWrite, SAPLING_SHARD_HEIGHT,
SentTransaction, SpendableNotes, TransactionDataRequest, TransactionStatus,
WalletCommitmentTrees, WalletRead, WalletSummary, WalletWrite, SAPLING_SHARD_HEIGHT,
},
keys::{
AddressGenerationError, UnifiedAddressRequest, UnifiedFullViewingKey, UnifiedSpendingKey,
Expand All @@ -63,6 +63,7 @@ use zcash_client_backend::{
PoolType, ShieldedProtocol, TransferType,
};
use zcash_keys::address::Receiver;
use zcash_keys::encoding::AddressCodec;
use zcash_primitives::{
block::BlockHash,
consensus::{self, BlockHeight},
Expand All @@ -85,7 +86,6 @@ use {
#[cfg(feature = "transparent-inputs")]
use {
zcash_client_backend::wallet::TransparentAddressMetadata,
zcash_keys::encoding::AddressCodec,
zcash_primitives::{legacy::TransparentAddress, transaction::components::OutPoint},
};

Expand Down Expand Up @@ -1180,6 +1180,10 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
) -> Result<(), Self::Error> {
self.transactionally(|wdb| {
let tx_ref = wallet::put_tx_data(wdb.conn.0, d_tx.tx(), None, None, None)?;
if let Some(height) = d_tx.mined_height() {
wallet::set_transaction_status(wdb.conn.0, d_tx.tx().txid(), TransactionStatus::Mined(height))?;
}

let funding_accounts = wallet::get_funding_accounts(wdb.conn.0, d_tx.tx())?;

// TODO(#1305): Correctly track accounts that fund each transaction output.
Expand Down Expand Up @@ -1403,6 +1407,13 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
.enumerate()
{
if let Some(address) = txout.recipient_address() {
debug!(
"{:?} output {} has recipient {}",
d_tx.tx().txid(),
output_index,
address.encode(&wdb.params)
);

// The transaction is not necessarily mined yet, but we want to record
// that an output to the address was seen in this tx anyway. This will
// advance the gap regardless of whether it is mined, but an output in
Expand All @@ -1417,6 +1428,12 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
&wdb.params,
&address
)? {
debug!(
"{:?} output {} belongs to account {:?}",
d_tx.tx().txid(),
output_index,
account_id
);
put_transparent_output(
wdb.conn.0,
&wdb.params,
Expand Down Expand Up @@ -1445,6 +1462,11 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
tx_ref,
output_index.try_into().unwrap()
)?;
} else {
debug!(
"Address {} is not recognized as belonging to any of our accounts.",
address.encode(&wdb.params)
);
}

// If a transaction we observe contains spends from our wallet, we will
Expand Down Expand Up @@ -1493,6 +1515,12 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
queue_status_retrieval = true;
}
}
} else {
warn!(
"Unable to determine recipient address for tx {:?} output {}",
d_tx.tx().txid(),
output_index
);
}
}
}
Expand Down

0 comments on commit 895d92b

Please sign in to comment.