From 1d701c48a3c53f6ba8b27427ac71b87cfe601da5 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Thu, 31 Dec 2020 07:39:24 -0600 Subject: [PATCH] Use written txDbs in TransactionProcessing (#2449) --- .../internal/TransactionProcessing.scala | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/wallet/src/main/scala/org/bitcoins/wallet/internal/TransactionProcessing.scala b/wallet/src/main/scala/org/bitcoins/wallet/internal/TransactionProcessing.scala index 7c950ebdd2..6086eb1162 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/internal/TransactionProcessing.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/internal/TransactionProcessing.scala @@ -97,16 +97,17 @@ private[wallet] trait TransactionProcessing extends WalletLogger { transaction: Transaction, feeRate: FeeUnit, inputAmount: CurrencyUnit, - sentAmount: CurrencyUnit): Future[OutgoingTransactionDb] = { + sentAmount: CurrencyUnit): Future[ + (TransactionDb, OutgoingTransactionDb)] = { val outgoingDb = OutgoingTransactionDb.fromTransaction(transaction, inputAmount, sentAmount, feeRate.calc(transaction)) for { - _ <- insertTransaction(transaction) + txDb <- insertTransaction(transaction) written <- outgoingTxDAO.upsert(outgoingDb) - } yield written + } yield (txDb, written) } /** @@ -124,11 +125,11 @@ private[wallet] trait TransactionProcessing extends WalletLogger { logger.info( s"Processing TX from our wallet, transaction=${transaction.txIdBE} with blockHash=$blockHashOpt") for { - _ <- + (txDb, _) <- insertOutgoingTransaction(transaction, feeRate, inputAmount, sentAmount) - result <- processTransactionImpl(transaction, blockHashOpt, newTags) + result <- processTransactionImpl(txDb.transaction, blockHashOpt, newTags) } yield { - val txid = transaction.txIdBE + val txid = txDb.transaction.txIdBE val changeOutputs = result.updatedIncoming.length val spentOutputs = result.updatedOutgoing.length @@ -402,12 +403,13 @@ private[wallet] trait TransactionProcessing extends WalletLogger { private[wallet] def insertIncomingTransaction( transaction: Transaction, - incomingAmount: CurrencyUnit): Future[IncomingTransactionDb] = { + incomingAmount: CurrencyUnit): Future[ + (TransactionDb, IncomingTransactionDb)] = { val incomingDb = IncomingTransactionDb(transaction.txIdBE, incomingAmount) for { - _ <- insertTransaction(transaction) + txDb <- insertTransaction(transaction) written <- incomingTxDAO.upsert(incomingDb) - } yield written + } yield (txDb, written) } private def getRelevantOutputs( @@ -453,7 +455,7 @@ private[wallet] trait TransactionProcessing extends WalletLogger { val totalIncoming = outputsWithIndex.map(_.output.value).sum for { - _ <- insertIncomingTransaction(transaction, totalIncoming) + (txDb, _) <- insertIncomingTransaction(transaction, totalIncoming) addrs <- addressDAO.findAllAddresses() ourOutputs = outputsWithIndex.collect { @@ -462,7 +464,8 @@ private[wallet] trait TransactionProcessing extends WalletLogger { OutputWithIndex(out, idx) } - prevTagDbs <- addressTagDAO.findTx(transaction, networkParameters) + prevTagDbs <- + addressTagDAO.findTx(txDb.transaction, networkParameters) prevTags = prevTagDbs.map(_.addressTag) tagsToUse = prevTags @@ -473,7 +476,7 @@ private[wallet] trait TransactionProcessing extends WalletLogger { tagsToUse.map(tag => AddressTagDb(address, tag)) } _ <- addressTagDAO.createAll(newTagDbs.toVector) - utxos <- addUTXOsFut(ourOutputs, transaction, blockHashOpt) + utxos <- addUTXOsFut(ourOutputs, txDb.transaction, blockHashOpt) } yield utxos } }