mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-19 21:45:36 +01:00
Use written txDbs in TransactionProcessing (#2449)
This commit is contained in:
parent
00e6a81a2a
commit
1d701c48a3
1 changed files with 15 additions and 12 deletions
|
@ -97,16 +97,17 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
feeRate: FeeUnit,
|
feeRate: FeeUnit,
|
||||||
inputAmount: CurrencyUnit,
|
inputAmount: CurrencyUnit,
|
||||||
sentAmount: CurrencyUnit): Future[OutgoingTransactionDb] = {
|
sentAmount: CurrencyUnit): Future[
|
||||||
|
(TransactionDb, OutgoingTransactionDb)] = {
|
||||||
val outgoingDb =
|
val outgoingDb =
|
||||||
OutgoingTransactionDb.fromTransaction(transaction,
|
OutgoingTransactionDb.fromTransaction(transaction,
|
||||||
inputAmount,
|
inputAmount,
|
||||||
sentAmount,
|
sentAmount,
|
||||||
feeRate.calc(transaction))
|
feeRate.calc(transaction))
|
||||||
for {
|
for {
|
||||||
_ <- insertTransaction(transaction)
|
txDb <- insertTransaction(transaction)
|
||||||
written <- outgoingTxDAO.upsert(outgoingDb)
|
written <- outgoingTxDAO.upsert(outgoingDb)
|
||||||
} yield written
|
} yield (txDb, written)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,11 +125,11 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
||||||
logger.info(
|
logger.info(
|
||||||
s"Processing TX from our wallet, transaction=${transaction.txIdBE} with blockHash=$blockHashOpt")
|
s"Processing TX from our wallet, transaction=${transaction.txIdBE} with blockHash=$blockHashOpt")
|
||||||
for {
|
for {
|
||||||
_ <-
|
(txDb, _) <-
|
||||||
insertOutgoingTransaction(transaction, feeRate, inputAmount, sentAmount)
|
insertOutgoingTransaction(transaction, feeRate, inputAmount, sentAmount)
|
||||||
result <- processTransactionImpl(transaction, blockHashOpt, newTags)
|
result <- processTransactionImpl(txDb.transaction, blockHashOpt, newTags)
|
||||||
} yield {
|
} yield {
|
||||||
val txid = transaction.txIdBE
|
val txid = txDb.transaction.txIdBE
|
||||||
val changeOutputs = result.updatedIncoming.length
|
val changeOutputs = result.updatedIncoming.length
|
||||||
val spentOutputs = result.updatedOutgoing.length
|
val spentOutputs = result.updatedOutgoing.length
|
||||||
|
|
||||||
|
@ -402,12 +403,13 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
||||||
|
|
||||||
private[wallet] def insertIncomingTransaction(
|
private[wallet] def insertIncomingTransaction(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
incomingAmount: CurrencyUnit): Future[IncomingTransactionDb] = {
|
incomingAmount: CurrencyUnit): Future[
|
||||||
|
(TransactionDb, IncomingTransactionDb)] = {
|
||||||
val incomingDb = IncomingTransactionDb(transaction.txIdBE, incomingAmount)
|
val incomingDb = IncomingTransactionDb(transaction.txIdBE, incomingAmount)
|
||||||
for {
|
for {
|
||||||
_ <- insertTransaction(transaction)
|
txDb <- insertTransaction(transaction)
|
||||||
written <- incomingTxDAO.upsert(incomingDb)
|
written <- incomingTxDAO.upsert(incomingDb)
|
||||||
} yield written
|
} yield (txDb, written)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getRelevantOutputs(
|
private def getRelevantOutputs(
|
||||||
|
@ -453,7 +455,7 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
||||||
val totalIncoming = outputsWithIndex.map(_.output.value).sum
|
val totalIncoming = outputsWithIndex.map(_.output.value).sum
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- insertIncomingTransaction(transaction, totalIncoming)
|
(txDb, _) <- insertIncomingTransaction(transaction, totalIncoming)
|
||||||
|
|
||||||
addrs <- addressDAO.findAllAddresses()
|
addrs <- addressDAO.findAllAddresses()
|
||||||
ourOutputs = outputsWithIndex.collect {
|
ourOutputs = outputsWithIndex.collect {
|
||||||
|
@ -462,7 +464,8 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
||||||
OutputWithIndex(out, idx)
|
OutputWithIndex(out, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
prevTagDbs <- addressTagDAO.findTx(transaction, networkParameters)
|
prevTagDbs <-
|
||||||
|
addressTagDAO.findTx(txDb.transaction, networkParameters)
|
||||||
prevTags = prevTagDbs.map(_.addressTag)
|
prevTags = prevTagDbs.map(_.addressTag)
|
||||||
tagsToUse =
|
tagsToUse =
|
||||||
prevTags
|
prevTags
|
||||||
|
@ -473,7 +476,7 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
||||||
tagsToUse.map(tag => AddressTagDb(address, tag))
|
tagsToUse.map(tag => AddressTagDb(address, tag))
|
||||||
}
|
}
|
||||||
_ <- addressTagDAO.createAll(newTagDbs.toVector)
|
_ <- addressTagDAO.createAll(newTagDbs.toVector)
|
||||||
utxos <- addUTXOsFut(ourOutputs, transaction, blockHashOpt)
|
utxos <- addUTXOsFut(ourOutputs, txDb.transaction, blockHashOpt)
|
||||||
} yield utxos
|
} yield utxos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue