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 (#1929)
* Calculate correct TxoState when processing a transaction * Test balance
This commit is contained in:
parent
09556a072d
commit
f734e002be
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
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue