mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 01:40:55 +01:00
Make sure exception is caught by Future inside of UtxoHandling.unmarkUTXOsAsReserved() (#3816)
This commit is contained in:
parent
31ce7cbd77
commit
31e8324522
@ -3,6 +3,7 @@ package org.bitcoins.dlc.wallet
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte
|
||||
import org.bitcoins.core.wallet.utxo.TxoState
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||
import org.bitcoins.testkit.keymanager.KeyManagerTestUtil.bip39PasswordOpt
|
||||
@ -61,4 +62,30 @@ class MultiWalletDLCTest extends BitcoinSWalletTest {
|
||||
assert(dlcsA != dlcsB)
|
||||
}
|
||||
}
|
||||
|
||||
it must "create an offer, out of band unreserve the utxo, and then cancel the offer" in {
|
||||
fundedWallet: FundedDLCWallet =>
|
||||
//see: https://github.com/bitcoin-s/bitcoin-s/issues/3813#issue-1051117559
|
||||
val wallet = fundedWallet.wallet
|
||||
val offerF = wallet.createDLCOffer(contractInfo = sampleContractInfo,
|
||||
collateral = half,
|
||||
feeRateOpt =
|
||||
Some(SatoshisPerVirtualByte.one),
|
||||
locktime = UInt32.zero,
|
||||
refundLocktime = UInt32.one)
|
||||
|
||||
//now unreserve the utxo
|
||||
val reservedUtxoF = for {
|
||||
_ <- offerF
|
||||
utxos <- wallet.listUtxos(TxoState.Reserved)
|
||||
_ <- wallet.unmarkUTXOsAsReserved(utxos)
|
||||
} yield ()
|
||||
|
||||
//now cancel the offer
|
||||
for {
|
||||
offer <- offerF
|
||||
_ <- reservedUtxoF
|
||||
_ <- wallet.cancelDLC(offer.dlcId)
|
||||
} yield succeed
|
||||
}
|
||||
}
|
||||
|
@ -334,14 +334,21 @@ private[wallet] trait UtxoHandling extends WalletLogger {
|
||||
|
||||
override def unmarkUTXOsAsReserved(
|
||||
utxos: Vector[SpendingInfoDb]): Future[Vector[SpendingInfoDb]] = {
|
||||
val unreserved = utxos.filterNot(_.state == TxoState.Reserved)
|
||||
require(unreserved.isEmpty, s"Some utxos are not reserved, got $unreserved")
|
||||
val updatedUtxosF = Future {
|
||||
//make sure exception isn't thrown outside of a future to fix
|
||||
//see: https://github.com/bitcoin-s/bitcoin-s/issues/3813
|
||||
val unreserved = utxos.filterNot(_.state == TxoState.Reserved)
|
||||
require(unreserved.isEmpty,
|
||||
s"Some utxos are not reserved, got $unreserved")
|
||||
|
||||
// unmark all utxos are reserved
|
||||
val updatedUtxos = utxos
|
||||
.map(_.copyWithState(TxoState.PendingConfirmationsReceived))
|
||||
// unmark all utxos are reserved
|
||||
val updatedUtxos = utxos
|
||||
.map(_.copyWithState(TxoState.PendingConfirmationsReceived))
|
||||
updatedUtxos
|
||||
}
|
||||
|
||||
for {
|
||||
updatedUtxos <- updatedUtxosF
|
||||
// update the confirmed utxos
|
||||
updatedConfirmed <- updateUtxoConfirmedStates(updatedUtxos)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user