lib: fix balance for pending transfers to own wallet

This commit is contained in:
Oscar Mira 2024-03-04 13:27:07 +01:00
parent 4cf0059739
commit ec4ebe6f78
3 changed files with 15 additions and 5 deletions

View File

@ -428,6 +428,13 @@ void Wallet::captureTxHistorySnapshot(std::vector<TxInfo>& snapshot) {
for (const auto& pair: upds) {
const auto& upd = pair.second.m_pd;
bool double_spend_seen = pair.second.m_double_spend_seen; // Unused
// Skip unconfirmed transfers sent to our own wallet.
auto it = std::find_if(
utxs.begin(), utxs.end(),
[&](const std::pair<crypto::hash, wallet2::unconfirmed_transfer_details>& utx) {
return utx.first == upd.m_tx_hash;
});
if (it != utxs.end()) continue;
// Denormalize individual amounts sent to a single subaddress in a single tx.
for (uint64_t amount: upd.m_amounts) {
snapshot.emplace_back(upd.m_tx_hash, TxInfo::INCOMING);
@ -435,7 +442,6 @@ void Wallet::captureTxHistorySnapshot(std::vector<TxInfo>& snapshot) {
recv.m_subaddress_major = upd.m_subaddr_index.major;
recv.m_subaddress_minor = upd.m_subaddr_index.minor;
recv.m_amount = amount;
recv.m_height = upd.m_block_height;
recv.m_unlock_time = upd.m_unlock_time;
recv.m_timestamp = upd.m_timestamp;
recv.m_fee = upd.m_fee;

View File

@ -176,6 +176,10 @@ internal class WalletNative private constructor(
}
override fun createPayment(request: PaymentRequest, callback: ITransferCallback) {
if (request.paymentDetails.any { it.recipientAddress.network != network }) {
callback.onUnexpectedError("Recipient address is on a different network")
return
}
scope.launch(singleThreadedDispatcher) {
val (amounts, addresses) = request.paymentDetails.map {
it.amount.atomicUnits to it.recipientAddress.address

View File

@ -117,12 +117,12 @@ private fun List<TxInfo>.createTransaction(
else blockchainContext.resolveUnlockTime(unlockTime)
}
val receivedEnotes = enoteByTxId.getOrDefault(txHash, emptyList()).toSet()
val receivedEnotes = enoteByTxId.getOrDefault(txHash, emptyList())
val outTxs = filter { !it.incoming }
val spentKeyImages = outTxs.mapNotNull { it.keyImage }
val sentEnotes = enoteByKeyImage.filterKeys { ki -> ki in spentKeyImages }.values.toSet()
val sentEnotes = enoteByKeyImage.filterKeys { ki -> ki in spentKeyImages }.values
val payments = outTxs.mapNotNull { it.toPaymentDetail() }
@ -131,8 +131,8 @@ private fun List<TxInfo>.createTransaction(
state = determineTxState(),
network = blockchainContext.network,
timeLock = timeLock,
sent = sentEnotes,
received = receivedEnotes,
sent = sentEnotes.toSet(),
received = receivedEnotes.toSet(),
payments = payments,
fee = MoneroAmount(atomicUnits = fee),
change = MoneroAmount(atomicUnits = change),