Only unreserve our utxos when canceling a DLC (#3250)

This commit is contained in:
benthecarman 2021-06-12 06:01:24 -07:00 committed by GitHub
parent 65f096f65a
commit c2237ab6fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -252,22 +252,23 @@ abstract class DLCWallet
*/
override def cancelDLC(dlcId: Sha256Digest): Future[Unit] = {
for {
inputs <- dlcInputsDAO.findByDLCId(dlcId)
dbs <- spendingInfoDAO.findByOutPoints(inputs.map(_.outPoint))
// allow this to fail in the case they have already been unreserved
_ <- unmarkUTXOsAsReserved(dbs).recover { case _: Throwable => () }
dlcOpt <- dlcDAO.read(dlcId)
_ = dlcOpt match {
dlcDb = dlcOpt match {
case Some(db) =>
require(
db.state == DLCState.Offered || db.state == DLCState.Accepted || db.state == DLCState.Signed,
"Cannot cancel a DLC after it has been signed")
db
case None =>
throw new IllegalArgumentException(
s"No DLC Found with dlc id ${dlcId.hex}")
}
inputs <- dlcInputsDAO.findByDLCId(dlcId, dlcDb.isInitiator)
dbs <- spendingInfoDAO.findByOutPoints(inputs.map(_.outPoint))
// allow this to fail in the case they have already been unreserved
_ <- unmarkUTXOsAsReserved(dbs).recover { case _: Throwable => () }
_ <- dlcSigsDAO.deleteByDLCId(dlcId)
_ <- dlcRefundSigDAO.deleteByDLCId(dlcId)
_ <- dlcInputsDAO.deleteByDLCId(dlcId)