mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 11:35:40 +01:00
Preserve noncedb outcomes when adding oracle (#3273)
This commit is contained in:
parent
e63a12e47f
commit
ca2ddbb7ec
2 changed files with 46 additions and 15 deletions
|
@ -14,13 +14,7 @@ import org.bitcoins.core.protocol.dlc.models.{
|
|||
EnumContractDescriptor,
|
||||
NumericContractDescriptor
|
||||
}
|
||||
import org.bitcoins.core.protocol.tlv.{
|
||||
ContractInfoV0TLV,
|
||||
OracleAttestmentTLV,
|
||||
OracleAttestmentV0TLV,
|
||||
OracleEventV0TLV,
|
||||
OracleInfoV0TLV
|
||||
}
|
||||
import org.bitcoins.core.protocol.tlv._
|
||||
import org.bitcoins.core.script.interpreter.ScriptInterpreter
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte
|
||||
import org.bitcoins.crypto.CryptoUtil
|
||||
|
@ -390,4 +384,31 @@ class DLCExecutionTest extends BitcoinSDualWalletTest {
|
|||
s"Got length=${announcementVec2.length}")
|
||||
} yield succeed
|
||||
}
|
||||
|
||||
it must "be able to construct an offer of the same contract info of a closed DLC" in {
|
||||
wallets =>
|
||||
val walletA = wallets._1.wallet
|
||||
val walletB = wallets._2.wallet
|
||||
|
||||
for {
|
||||
contractId <- getContractId(walletA)
|
||||
status <- getDLCStatus(walletB)
|
||||
(_, sig) = getSigs(status.contractInfo)
|
||||
func = (wallet: DLCWallet) => wallet.executeDLC(contractId, sig)
|
||||
|
||||
result <- dlcExecutionTest(wallets = wallets,
|
||||
asInitiator = true,
|
||||
func = func,
|
||||
expectedOutputs = 1)
|
||||
_ = assert(result)
|
||||
|
||||
_ <- walletA.createDLCOffer(status.contractInfo,
|
||||
status.localCollateral.satoshis,
|
||||
None,
|
||||
UInt32.zero,
|
||||
UInt32.one)
|
||||
|
||||
_ <- walletA.listDLCs()
|
||||
} yield succeed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,15 +312,20 @@ abstract class DLCWallet
|
|||
groupedAnnouncements.newAnnouncements)
|
||||
allAnnouncementDbs =
|
||||
announcementDataDbs ++ groupedAnnouncements.existingAnnouncements
|
||||
announcementsWithId = announcements.map { tlv =>
|
||||
|
||||
newAnnouncements = announcements.filter(a =>
|
||||
groupedAnnouncements.newAnnouncements.exists(
|
||||
_.announcementSignature == a.announcementSignature))
|
||||
|
||||
newAnnouncementsWithId = newAnnouncements.map { tlv =>
|
||||
val idOpt: Option[Long] =
|
||||
allAnnouncementDbs
|
||||
announcementDataDbs
|
||||
.find(_.announcementSignature == tlv.announcementSignature)
|
||||
.flatMap(_.id)
|
||||
(tlv, idOpt.get)
|
||||
}
|
||||
nonceDbs = OracleNonceDbHelper.fromAnnouncements(announcementsWithId)
|
||||
_ <- oracleNonceDAO.upsertAll(nonceDbs)
|
||||
nonceDbs = OracleNonceDbHelper.fromAnnouncements(newAnnouncementsWithId)
|
||||
_ <- oracleNonceDAO.createAll(nonceDbs)
|
||||
chainType = HDChainType.External
|
||||
|
||||
account <- getDefaultAccountForType(AddressType.SegWit)
|
||||
|
@ -505,14 +510,19 @@ abstract class DLCWallet
|
|||
announcementDataDbs =
|
||||
createdDbs ++ groupedAnnouncements.existingAnnouncements
|
||||
|
||||
announcementsWithId = announcements.map { tlv =>
|
||||
val idOpt = announcementDataDbs
|
||||
newAnnouncements = announcements.filter(a =>
|
||||
groupedAnnouncements.newAnnouncements.exists(
|
||||
_.announcementSignature == a.announcementSignature))
|
||||
|
||||
newAnnouncementsWithId = newAnnouncements.map { tlv =>
|
||||
val idOpt = createdDbs
|
||||
.find(_.announcementSignature == tlv.announcementSignature)
|
||||
.flatMap(_.id)
|
||||
(tlv, idOpt.get)
|
||||
}
|
||||
nonceDbs = OracleNonceDbHelper.fromAnnouncements(announcementsWithId)
|
||||
_ <- oracleNonceDAO.upsertAll(nonceDbs)
|
||||
nonceDbs = OracleNonceDbHelper.fromAnnouncements(
|
||||
newAnnouncementsWithId)
|
||||
_ <- oracleNonceDAO.createAll(nonceDbs)
|
||||
|
||||
dlcAnnouncementDbs = announcementDataDbs.zipWithIndex.map {
|
||||
case (a, index) =>
|
||||
|
|
Loading…
Add table
Reference in a new issue