1
0
Fork 0
mirror of https://github.com/bitcoin-s/bitcoin-s.git synced 2025-03-26 21:42:48 +01:00

Calculate correct TxoState when processing a transaction ()

* Calculate correct TxoState when processing a transaction

* Test balance
This commit is contained in:
Ben Carman 2020-08-28 15:31:48 -05:00 committed by GitHub
parent 09556a072d
commit f734e002be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 14 deletions
wallet-test/src/test/scala/org/bitcoins/wallet
wallet/src/main/scala/org/bitcoins/wallet/internal

View file

@ -123,7 +123,7 @@ class RescanHandlingTest extends BitcoinSWalletTest {
//balance doesn't have to exactly equal, as there was money in the
//wallet before hand.
assert(balance >= amt)
assert(balance == unconfirmedBalance)
assert(amt == unconfirmedBalance)
newTxWallet
}
@ -143,8 +143,10 @@ class RescanHandlingTest extends BitcoinSWalletTest {
DEFAULT_ADDR_BATCH_SIZE,
useCreationTime = false)
balance <- newTxWallet.getBalance()
unconfirmedBalance <- newTxWallet.getUnconfirmedBalance()
} yield {
assert(balance == amt)
assert(unconfirmedBalance == Bitcoins(1))
}
}
@ -174,7 +176,7 @@ class RescanHandlingTest extends BitcoinSWalletTest {
//balance doesn't have to exactly equal, as there was money in the
//wallet before hand.
assert(balance >= amt)
assert(balance == unconfirmedBalance)
assert(amt == unconfirmedBalance)
newTxWallet
}
@ -234,7 +236,7 @@ class RescanHandlingTest extends BitcoinSWalletTest {
//balance doesn't have to exactly equal, as there was money in the
//wallet before hand.
assert(balance >= amt)
assert(balance == unconfirmedBalance)
assert(amt == unconfirmedBalance)
newTxWallet
}
@ -246,8 +248,10 @@ class RescanHandlingTest extends BitcoinSWalletTest {
DEFAULT_ADDR_BATCH_SIZE,
useCreationTime = true)
balance <- newTxWallet.getBalance()
unconfirmedBalance <- newTxWallet.getUnconfirmedBalance()
} yield {
assert(balance == Bitcoins(7))
assert(unconfirmedBalance == Bitcoins(1))
}
}

View file

@ -346,16 +346,31 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
transaction: Transaction,
blockHashOpt: Option[DoubleSha256DigestBE]): Future[
Seq[SpendingInfoDb]] = {
FutureUtil.sequentially(outputsWithIndex) { out =>
processUtxo(
transaction,
out.index,
// TODO is this correct?
//we probably need to incorporate what
//what our wallet's desired confirmation number is
state = TxoState.PendingConfirmationsReceived,
blockHash = blockHashOpt
)
val stateF: Future[TxoState] = blockHashOpt match {
case None =>
Future.successful(TxoState.PendingConfirmationsReceived)
case Some(blockHash) =>
chainQueryApi.getNumberOfConfirmations(blockHash).map {
case None =>
TxoState.PendingConfirmationsReceived
case Some(confs) =>
if (confs >= walletConfig.requiredConfirmations) {
TxoState.ConfirmedReceived
} else {
TxoState.PendingConfirmationsReceived
}
}
}
stateF.flatMap { state =>
FutureUtil.sequentially(outputsWithIndex) { out =>
processUtxo(
transaction,
out.index,
state = state,
blockHash = blockHashOpt
)
}
}
}
@ -408,7 +423,7 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
.mkString(", ")
}
logger.trace(
s"Found $count relevant output(s) in transaction=${transaction.txIdBE}: $outputStr")
s"Found $count relevant output(s) in transaction=${transaction.txIdBE.hex}: $outputStr")
val totalIncoming = outputsWithIndex.map(_.output.value).sum