mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
Fix bug where we couldn't execute a DLC twice (#3426)
This commit is contained in:
parent
59963156bc
commit
a295b363bd
@ -217,6 +217,18 @@ class DLCExecutionTest extends BitcoinSDualWalletTest {
|
||||
}
|
||||
}
|
||||
|
||||
it must "execute a DLC twice and get the same transaction" in { wallets =>
|
||||
val wallet = wallets._1.wallet
|
||||
for {
|
||||
contractId <- getContractId(wallet)
|
||||
status <- getDLCStatus(wallet)
|
||||
(sig, _) = getSigs(status.contractInfo)
|
||||
|
||||
tx1 <- wallet.executeDLC(contractId, sig)
|
||||
tx2 <- wallet.executeDLC(contractId, sig)
|
||||
} yield assert(tx1 == tx2)
|
||||
}
|
||||
|
||||
it must "execute a losing dlc" in { wallets =>
|
||||
val dlcA = wallets._1.wallet
|
||||
|
||||
|
@ -1199,6 +1199,28 @@ abstract class DLCWallet
|
||||
contractId: ByteVector,
|
||||
oracleSigs: Vector[OracleSignatures]): Future[Transaction] = {
|
||||
require(oracleSigs.nonEmpty, "Must provide at least one oracle signature")
|
||||
dlcDAO.findByContractId(contractId).flatMap {
|
||||
case None =>
|
||||
Future.failed(
|
||||
new IllegalArgumentException(
|
||||
s"No DLC found with contractId $contractId"))
|
||||
case Some(db) =>
|
||||
db.closingTxIdOpt match {
|
||||
case Some(txId) =>
|
||||
transactionDAO.findByTxId(txId).flatMap {
|
||||
case Some(tx) => Future.successful(tx.transaction)
|
||||
case None => createDLCExecutionTx(contractId, oracleSigs)
|
||||
}
|
||||
case None =>
|
||||
createDLCExecutionTx(contractId, oracleSigs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def createDLCExecutionTx(
|
||||
contractId: ByteVector,
|
||||
oracleSigs: Vector[OracleSignatures]): Future[Transaction] = {
|
||||
require(oracleSigs.nonEmpty, "Must provide at least one oracle signature")
|
||||
for {
|
||||
(executor, setup) <- executorAndSetupFromDb(contractId)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user