mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 22:36:34 +01:00
2022 03 31 collateral invariant (#4232)
* DLCMessage.totalCollateral -> DLCMessage.collateral * Fix bad names of {DLCOfferTLV,DLCAcceptTLV}.totalCollateralSatoshis, its not the total collateral, rather the collateral being contributed by the offerer and acceptor * Fix rebase * Fix appServerTest * Fix docs
This commit is contained in:
parent
8081772b57
commit
f2fa56221d
18 changed files with 98 additions and 96 deletions
|
@ -39,7 +39,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
payoutAddress
|
||||
)
|
||||
|
||||
|
@ -77,7 +77,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
payoutAddress
|
||||
)
|
||||
|
||||
|
@ -111,7 +111,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
txId,
|
||||
payoutAddress
|
||||
)
|
||||
|
@ -146,7 +146,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
fundingTxId,
|
||||
payoutAddress
|
||||
)
|
||||
|
@ -181,7 +181,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
fundingTxId,
|
||||
payoutAddress
|
||||
)
|
||||
|
@ -227,7 +227,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
fundingTxId,
|
||||
closingTxId,
|
||||
sigs.toVector,
|
||||
|
@ -281,7 +281,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
fundingTxId,
|
||||
closingTxId,
|
||||
sig,
|
||||
|
@ -331,7 +331,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
|
|||
offer.timeouts,
|
||||
offer.feeRate,
|
||||
totalCollateral,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
fundingTxId,
|
||||
closingTxId,
|
||||
myPayout = myPayout,
|
||||
|
|
|
@ -341,7 +341,7 @@ object Picklers {
|
|||
|
||||
val acceptTLV = DLCAcceptTLV(
|
||||
tempContractId = tempContractId,
|
||||
totalCollateralSatoshis = acceptCollateral,
|
||||
acceptCollateralSatoshis = acceptCollateral,
|
||||
fundingPubKey = fundingPubKey,
|
||||
payoutSPK = payoutSpk,
|
||||
payoutSerialId = payoutSerialId,
|
||||
|
@ -360,7 +360,7 @@ object Picklers {
|
|||
Obj(
|
||||
PicklerKeys.tempContractIdKey -> Str(accept.tempContractId.hex),
|
||||
PicklerKeys.acceptCollateralKey -> Num(
|
||||
accept.totalCollateralSatoshis.toLong.toDouble),
|
||||
accept.acceptCollateralSatoshis.toLong.toDouble),
|
||||
PicklerKeys.fundingPubKeyKey -> Str(accept.fundingPubKey.hex),
|
||||
PicklerKeys.payoutSpkKey -> Str(accept.payoutSPK.asmHex),
|
||||
PicklerKeys.payoutSerialIdKey -> Str(
|
||||
|
@ -790,7 +790,7 @@ object Picklers {
|
|||
"fundingPubKey" -> Str(fundingPubKey.hex),
|
||||
"payoutSPK" -> Str(payoutSPK.hex),
|
||||
"payoutSerialId" -> Num(payoutSerialId.toBigInt.toDouble),
|
||||
"offerCollateral" -> Num(totalCollateralSatoshis.toLong.toDouble),
|
||||
"offerCollateral" -> Num(offererCollateralSatoshis.toLong.toDouble),
|
||||
"fundingInputs" -> fundingInputs.map(i => writeJs(i)),
|
||||
"changeSPK" -> Str(changeSPK.hex),
|
||||
"changeSerialId" -> Str(changeSerialId.toBigInt.toString()),
|
||||
|
|
|
@ -139,7 +139,7 @@ class AcceptOfferDialog extends CliCommandProducer[AcceptDLCCliCommand] {
|
|||
nextRow += 1
|
||||
|
||||
val yourCol =
|
||||
offer.contractInfo.totalCollateral - offer.totalCollateralSatoshis
|
||||
offer.contractInfo.totalCollateral - offer.offererCollateralSatoshis
|
||||
|
||||
gridPane.add(
|
||||
new Label("Your Collateral") {
|
||||
|
@ -160,7 +160,7 @@ class AcceptOfferDialog extends CliCommandProducer[AcceptDLCCliCommand] {
|
|||
|
||||
gridPane.add(new Label("Counterparty Collateral"), 0, nextRow)
|
||||
gridPane.add(new TextField() {
|
||||
text = offer.totalCollateralSatoshis.toString
|
||||
text = offer.offererCollateralSatoshis.toString
|
||||
editable = false
|
||||
},
|
||||
1,
|
||||
|
|
|
@ -968,7 +968,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = contractInfo,
|
||||
pubKeys = dummyDLCKeys,
|
||||
totalCollateral = Satoshis(2500),
|
||||
collateral = Satoshis(3),
|
||||
fundingInputs =
|
||||
Vector(fundingInput, fundingInput.copy(inputSerialId = UInt64.max)),
|
||||
changeAddress = Bech32Address.fromString(dummyAddress),
|
||||
|
@ -1043,7 +1043,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
|||
}
|
||||
|
||||
val accept = DLCAccept(
|
||||
totalCollateral = Satoshis(1000),
|
||||
collateral = Satoshis(1000),
|
||||
pubKeys = dummyDLCKeys,
|
||||
fundingInputs = Vector(fundingInput),
|
||||
changeAddress = Bech32Address
|
||||
|
|
|
@ -50,7 +50,7 @@ class DLCMessageTest extends BitcoinSJvmTest {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = SingleContractInfo.dummy,
|
||||
pubKeys = DLCPublicKeys(dummyPubKey, dummyAddress),
|
||||
totalCollateral = Satoshis(-1),
|
||||
collateral = Satoshis(-1),
|
||||
fundingInputs = Vector.empty,
|
||||
changeAddress = dummyAddress,
|
||||
payoutSerialId = UInt64.zero,
|
||||
|
@ -67,7 +67,7 @@ class DLCMessageTest extends BitcoinSJvmTest {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = SingleContractInfo.dummy,
|
||||
pubKeys = DLCPublicKeys(dummyPubKey, dummyAddress),
|
||||
totalCollateral = Satoshis(-1),
|
||||
collateral = Satoshis(-1),
|
||||
fundingInputs = Vector.empty,
|
||||
changeAddress = dummyAddress,
|
||||
payoutSerialId = UInt64.zero,
|
||||
|
|
|
@ -48,7 +48,7 @@ trait DLCWalletApi { self: WalletApi =>
|
|||
def registerDLCOffer(dlcOffer: DLCOffer): Future[DLCOffer] = {
|
||||
createDLCOffer(
|
||||
dlcOffer.contractInfo,
|
||||
dlcOffer.totalCollateral,
|
||||
dlcOffer.collateral,
|
||||
Some(dlcOffer.feeRate),
|
||||
dlcOffer.timeouts.contractMaturity.toUInt32,
|
||||
dlcOffer.timeouts.contractTimeout.toUInt32,
|
||||
|
|
|
@ -188,7 +188,7 @@ object DLCUtil {
|
|||
)
|
||||
|
||||
val (fundingTx, fundingOutputIdx) = DLCTxBuilder.buildFundingTransaction(
|
||||
offerInput = offer.totalCollateral,
|
||||
offerInput = offer.collateral,
|
||||
acceptInput = acceptWithoutSigs.totalCollateral,
|
||||
offerFundingInputs = offerFundingInputs,
|
||||
acceptFundingInputs = acceptFundingInputs,
|
||||
|
|
|
@ -53,15 +53,16 @@ object DLCMessage {
|
|||
sealed trait DLCSetupMessage extends DLCMessage {
|
||||
def pubKeys: DLCPublicKeys
|
||||
|
||||
def totalCollateral: Satoshis
|
||||
/** The collateral that the offerer/acceptor is putting up on their side of the DLC */
|
||||
def collateral: Satoshis
|
||||
|
||||
def fundingInputs: Vector[DLCFundingInput]
|
||||
|
||||
def changeAddress: BitcoinAddress
|
||||
|
||||
require(
|
||||
totalCollateral >= Satoshis.zero,
|
||||
s"Cannot have a negative totalCollateral, got: ${totalCollateral.toLong}")
|
||||
collateral >= Satoshis.zero,
|
||||
s"Cannot have a negative totalCollateral, got: ${collateral.toLong}")
|
||||
}
|
||||
|
||||
/** The initiating party starts the protocol by sending an offer message to the other party.
|
||||
|
@ -70,7 +71,7 @@ object DLCMessage {
|
|||
* well as meta information to identify the oracle to be used in the contract,
|
||||
* and a map to be used to create CETs.
|
||||
* @param pubKeys The relevant public keys that the initiator will be using
|
||||
* @param totalCollateral How much the initiator inputs into the contract.
|
||||
* @param collateral How much the initiator inputs into the contract.
|
||||
* @param fundingInputs The set of UTXOs to be used as input to the fund transaction.
|
||||
* @param changeAddress The address to use to send the change for the initiator.
|
||||
* @param feeRate The fee rate to be used when computing fees for the different transactions.
|
||||
|
@ -80,7 +81,7 @@ object DLCMessage {
|
|||
protocolVersionOpt: Option[Int],
|
||||
contractInfo: ContractInfo,
|
||||
pubKeys: DLCPublicKeys,
|
||||
totalCollateral: Satoshis,
|
||||
collateral: Satoshis,
|
||||
fundingInputs: Vector[DLCFundingInput],
|
||||
changeAddress: BitcoinAddress,
|
||||
payoutSerialId: UInt64,
|
||||
|
@ -101,6 +102,10 @@ object DLCMessage {
|
|||
changeSerialId != fundOutputSerialId,
|
||||
s"changeSerialId ($changeSerialId) cannot be equal to fundOutputSerialId ($fundOutputSerialId)")
|
||||
|
||||
require(
|
||||
collateral <= contractInfo.totalCollateral,
|
||||
s"Cannot have more collateral in the DLC than total collateral, collateral=${collateral} totalCollateral=${contractInfo.totalCollateral}"
|
||||
)
|
||||
val oracleInfos: Vector[OracleInfo] = contractInfo.oracleInfos
|
||||
|
||||
val contractDescriptors: Vector[ContractDescriptor] =
|
||||
|
@ -122,7 +127,7 @@ object DLCMessage {
|
|||
fundingPubKey = pubKeys.fundingKey,
|
||||
payoutSPK = pubKeys.payoutAddress.scriptPubKey,
|
||||
payoutSerialId = payoutSerialId,
|
||||
totalCollateralSatoshis = totalCollateral,
|
||||
offererCollateralSatoshis = collateral,
|
||||
fundingInputs = fundingInputs.map(_.toTLV),
|
||||
changeSPK = changeAddress.scriptPubKey,
|
||||
changeSerialId = changeSerialId,
|
||||
|
@ -151,7 +156,7 @@ object DLCMessage {
|
|||
pubKeys = DLCPublicKeys(
|
||||
offer.fundingPubKey,
|
||||
BitcoinAddress.fromScriptPubKey(offer.payoutSPK, network)),
|
||||
totalCollateral = offer.totalCollateralSatoshis,
|
||||
collateral = offer.offererCollateralSatoshis,
|
||||
fundingInputs = offer.fundingInputs.map {
|
||||
case input: FundingInputV0TLV => DLCFundingInput.fromTLV(input)
|
||||
},
|
||||
|
@ -185,7 +190,7 @@ object DLCMessage {
|
|||
|
||||
def withCetSigs(cetSigs: CETSignatures): DLCAccept = {
|
||||
DLCAccept(
|
||||
totalCollateral = totalCollateral,
|
||||
collateral = totalCollateral,
|
||||
pubKeys = pubKeys,
|
||||
fundingInputs = fundingInputs,
|
||||
changeAddress = changeAddress,
|
||||
|
@ -228,7 +233,7 @@ object DLCMessage {
|
|||
cetSigs: CETSignatures,
|
||||
refundSig: PartialSignature): DLCAccept = {
|
||||
DLCAccept(
|
||||
totalCollateral = totalCollateral,
|
||||
collateral = totalCollateral,
|
||||
pubKeys = pubKeys,
|
||||
fundingInputs = fundingInputs,
|
||||
changeAddress = changeAddress,
|
||||
|
@ -243,7 +248,7 @@ object DLCMessage {
|
|||
}
|
||||
|
||||
case class DLCAccept(
|
||||
totalCollateral: Satoshis,
|
||||
collateral: Satoshis,
|
||||
pubKeys: DLCPublicKeys,
|
||||
fundingInputs: Vector[DLCFundingInput],
|
||||
changeAddress: BitcoinAddress,
|
||||
|
@ -263,7 +268,7 @@ object DLCMessage {
|
|||
def toTLV: DLCAcceptTLV = {
|
||||
DLCAcceptTLV(
|
||||
tempContractId = tempContractId,
|
||||
totalCollateralSatoshis = totalCollateral,
|
||||
acceptCollateralSatoshis = collateral,
|
||||
fundingPubKey = pubKeys.fundingKey,
|
||||
payoutSPK = pubKeys.payoutAddress.scriptPubKey,
|
||||
payoutSerialId = payoutSerialId,
|
||||
|
@ -283,7 +288,7 @@ object DLCMessage {
|
|||
|
||||
def withoutSigs: DLCAcceptWithoutSigs = {
|
||||
DLCAcceptWithoutSigs(
|
||||
totalCollateral = totalCollateral,
|
||||
totalCollateral = collateral,
|
||||
pubKeys = pubKeys,
|
||||
fundingInputs = fundingInputs,
|
||||
changeAddress = changeAddress,
|
||||
|
@ -296,7 +301,7 @@ object DLCMessage {
|
|||
|
||||
def withoutCetSigs: DLCAcceptWithoutCetSigs = {
|
||||
DLCAcceptWithoutCetSigs(
|
||||
totalCollateral = totalCollateral,
|
||||
totalCollateral = collateral,
|
||||
pubKeys = pubKeys,
|
||||
fundingInputs = fundingInputs,
|
||||
changeAddress = changeAddress,
|
||||
|
@ -368,7 +373,7 @@ object DLCMessage {
|
|||
accept.refundSignature.bytes.:+(HashType.sigHashAllByte))
|
||||
}
|
||||
DLCAccept(
|
||||
totalCollateral = accept.totalCollateralSatoshis,
|
||||
collateral = accept.acceptCollateralSatoshis,
|
||||
pubKeys = DLCPublicKeys(
|
||||
accept.fundingPubKey,
|
||||
BitcoinAddress.fromScriptPubKey(accept.payoutSPK, network)),
|
||||
|
|
|
@ -1728,7 +1728,7 @@ case class DLCOfferTLV(
|
|||
fundingPubKey: ECPublicKey,
|
||||
payoutSPK: ScriptPubKey,
|
||||
payoutSerialId: UInt64,
|
||||
totalCollateralSatoshis: Satoshis,
|
||||
offererCollateralSatoshis: Satoshis,
|
||||
fundingInputs: Vector[FundingInputTLV],
|
||||
changeSPK: ScriptPubKey,
|
||||
changeSerialId: UInt64,
|
||||
|
@ -1755,7 +1755,7 @@ case class DLCOfferTLV(
|
|||
fundingPubKey.bytes ++
|
||||
TLV.encodeScript(payoutSPK) ++
|
||||
payoutSerialId.bytes ++
|
||||
satBytes(totalCollateralSatoshis) ++
|
||||
satBytes(offererCollateralSatoshis) ++
|
||||
u16PrefixedList(fundingInputs) ++
|
||||
TLV.encodeScript(changeSPK) ++
|
||||
changeSerialId.bytes ++
|
||||
|
@ -1806,7 +1806,7 @@ object DLCOfferTLV extends TLVFactory[DLCOfferTLV] {
|
|||
fundingPubKey = fundingPubKey,
|
||||
payoutSPK = payoutSPK,
|
||||
payoutSerialId = payoutSerialId,
|
||||
totalCollateralSatoshis = totalCollateralSatoshis,
|
||||
offererCollateralSatoshis = totalCollateralSatoshis,
|
||||
fundingInputs = fundingInputs,
|
||||
changeSPK = changeSPK,
|
||||
changeSerialId = changeSerialId,
|
||||
|
@ -1905,7 +1905,7 @@ object NegotiationFieldsV2TLV extends TLVFactory[NegotiationFieldsV2TLV] {
|
|||
|
||||
case class DLCAcceptTLV(
|
||||
tempContractId: Sha256Digest,
|
||||
totalCollateralSatoshis: Satoshis,
|
||||
acceptCollateralSatoshis: Satoshis,
|
||||
fundingPubKey: ECPublicKey,
|
||||
payoutSPK: ScriptPubKey,
|
||||
payoutSerialId: UInt64,
|
||||
|
@ -1920,7 +1920,7 @@ case class DLCAcceptTLV(
|
|||
|
||||
override val value: ByteVector = {
|
||||
tempContractId.bytes ++
|
||||
satBytes(totalCollateralSatoshis) ++
|
||||
satBytes(acceptCollateralSatoshis) ++
|
||||
fundingPubKey.bytes ++
|
||||
TLV.encodeScript(payoutSPK) ++
|
||||
payoutSerialId.bytes ++
|
||||
|
|
|
@ -405,7 +405,7 @@ object DLCTLVGen {
|
|||
changeAddress: BitcoinAddress = address(),
|
||||
changeSerialId: UInt64 = DLCMessage.genSerialId()): DLCAccept = {
|
||||
val totalCollateral =
|
||||
offer.contractInfo.max - offer.totalCollateral + overCollateral
|
||||
offer.contractInfo.max - offer.collateral + overCollateral
|
||||
|
||||
val cetSignatures =
|
||||
cetSigs(
|
||||
|
|
|
@ -42,7 +42,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -57,7 +57,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
assert(dlcA1Opt.get.state == DLCState.Offered)
|
||||
assert(offer.oracleInfos == offerData.oracleInfos)
|
||||
assert(offer.contractInfo == offerData.contractInfo)
|
||||
assert(offer.totalCollateral == offerData.totalCollateral)
|
||||
assert(offer.collateral == offerData.collateral)
|
||||
assert(offer.feeRate == offerData.feeRate)
|
||||
assert(offer.timeouts == offerData.timeouts)
|
||||
assert(offer.fundingInputs.nonEmpty)
|
||||
|
@ -73,9 +73,8 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
assert(
|
||||
accept.fundingInputs
|
||||
.map(_.output.value)
|
||||
.sum >= accept.totalCollateral)
|
||||
assert(
|
||||
accept.totalCollateral == offer.contractInfo.max - offer.totalCollateral)
|
||||
.sum >= accept.collateral)
|
||||
assert(accept.collateral == offer.contractInfo.max - offer.collateral)
|
||||
assert(accept.changeAddress.value.nonEmpty)
|
||||
}
|
||||
|
||||
|
@ -167,7 +166,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
|
||||
val offerData =
|
||||
sampleDLCOffer.copy(contractInfo = contractInfo,
|
||||
totalCollateral = col.satoshis)
|
||||
collateral = col.satoshis)
|
||||
|
||||
val walletA = fundedDLCWallets._1.wallet
|
||||
val walletB = fundedDLCWallets._2.wallet
|
||||
|
@ -185,7 +184,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -226,7 +225,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
|
||||
val offerData =
|
||||
sampleDLCOffer.copy(contractInfo = contractInfo,
|
||||
totalCollateral = col.satoshis)
|
||||
collateral = col.satoshis)
|
||||
|
||||
val walletA = fundedDLCWallets._1.wallet
|
||||
val walletB = fundedDLCWallets._2.wallet
|
||||
|
@ -244,7 +243,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -275,7 +274,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo.toTLV,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -289,7 +288,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
assert(dlcA1Opt.get.state == DLCState.Offered)
|
||||
assert(offer.oracleInfos == offerData.oracleInfos)
|
||||
assert(offer.contractInfo == offerData.contractInfo)
|
||||
assert(offer.totalCollateral == offerData.totalCollateral)
|
||||
assert(offer.collateral == offerData.collateral)
|
||||
assert(offer.feeRate == offerData.feeRate)
|
||||
assert(offer.timeouts == offerData.timeouts)
|
||||
assert(offer.fundingInputs.nonEmpty)
|
||||
|
@ -305,9 +304,8 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
assert(
|
||||
accept.fundingInputs
|
||||
.map(_.output.value)
|
||||
.sum >= accept.totalCollateral)
|
||||
assert(
|
||||
accept.totalCollateral == offer.contractInfo.max - offer.totalCollateral)
|
||||
.sum >= accept.collateral)
|
||||
assert(accept.collateral == offer.contractInfo.max - offer.collateral)
|
||||
assert(accept.changeAddress.value.nonEmpty)
|
||||
}
|
||||
|
||||
|
@ -371,7 +369,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -517,7 +515,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -562,7 +560,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -605,7 +603,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -649,7 +647,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -684,7 +682,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
UInt32.max,
|
||||
|
@ -751,7 +749,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
@ -761,7 +759,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
_ = {
|
||||
assert(offer.oracleInfos == offerData.oracleInfos)
|
||||
assert(offer.contractInfo == offerData.contractInfo)
|
||||
assert(offer.totalCollateral == offerData.totalCollateral)
|
||||
assert(offer.collateral == offerData.collateral)
|
||||
assert(offer.feeRate == offerData.feeRate)
|
||||
assert(offer.timeouts == offerData.timeouts)
|
||||
assert(offer.fundingInputs.nonEmpty)
|
||||
|
@ -773,8 +771,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
accept <- walletB.acceptDLCOffer(offer, None, None)
|
||||
_ = {
|
||||
assert(accept.fundingInputs.nonEmpty)
|
||||
assert(
|
||||
accept.totalCollateral == offer.contractInfo.max - offer.totalCollateral)
|
||||
assert(accept.collateral == offer.contractInfo.max - offer.collateral)
|
||||
assert(accept.changeAddress.value.nonEmpty)
|
||||
}
|
||||
|
||||
|
@ -955,7 +952,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
for {
|
||||
offer <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
UInt32.max,
|
||||
|
@ -978,7 +975,7 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
res <- recoverToSucceededIf[InvalidAnnouncementSignature](
|
||||
walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
UInt32.max,
|
||||
|
@ -1087,13 +1084,13 @@ class WalletDLCSetupTest extends BitcoinSDualWalletTest {
|
|||
val offerData: DLCOffer =
|
||||
DLCWalletUtil.sampleDLCOffer.copy(contractInfo =
|
||||
DLCWalletUtil.sampleContractInfo2,
|
||||
totalCollateral = DLCWalletUtil.amt2)
|
||||
collateral = DLCWalletUtil.amt2)
|
||||
val offerData2 = DLCWalletUtil.sampleDLCOffer
|
||||
|
||||
for {
|
||||
offer1 <- walletA.createDLCOffer(
|
||||
offerData.contractInfo,
|
||||
offerData.totalCollateral,
|
||||
offerData.collateral,
|
||||
Some(offerData.feeRate),
|
||||
offerData.timeouts.contractMaturity.toUInt32,
|
||||
offerData.timeouts.contractTimeout.toUInt32,
|
||||
|
|
|
@ -379,7 +379,7 @@ abstract class DLCWallet
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = contractInfo,
|
||||
pubKeys = dlcPubKeys,
|
||||
totalCollateral = collateral.satoshis,
|
||||
collateral = collateral.satoshis,
|
||||
fundingInputs = utxos,
|
||||
changeAddress = changeAddr,
|
||||
payoutSerialId = payoutSerialId,
|
||||
|
@ -651,7 +651,8 @@ abstract class DLCWallet
|
|||
|
||||
val dlcId = calcDLCId(offer.fundingInputs.map(_.outPoint))
|
||||
|
||||
val collateral = offer.contractInfo.max - offer.totalCollateral
|
||||
val collateral = offer.contractInfo.max - offer.collateral
|
||||
|
||||
logger.debug(s"Checking if Accept (${dlcId.hex}) has already been made")
|
||||
for {
|
||||
dlcAcceptOpt <- DLCAcceptUtil.findDLCAccept(dlcId = dlcId,
|
||||
|
|
|
@ -32,7 +32,7 @@ case class DLCAcceptDb(
|
|||
DLCPublicKeys(fundingKey, payoutAddress)
|
||||
val cetSigs = CETSignatures(outcomeSigs)
|
||||
DLCAccept(
|
||||
totalCollateral = collateral.satoshis,
|
||||
collateral = collateral.satoshis,
|
||||
pubKeys = pubKeys,
|
||||
fundingInputs = fundingInputs,
|
||||
changeAddress = changeAddress,
|
||||
|
@ -72,7 +72,7 @@ object DLCAcceptDbHelper {
|
|||
accept.pubKeys.fundingKey,
|
||||
accept.pubKeys.payoutAddress,
|
||||
accept.payoutSerialId,
|
||||
accept.totalCollateral,
|
||||
accept.collateral,
|
||||
accept.changeAddress,
|
||||
accept.changeSerialId,
|
||||
accept.negotiationFields.toTLV
|
||||
|
|
|
@ -43,7 +43,7 @@ case class DLCOfferDb(
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = contractInfo,
|
||||
pubKeys = dlcPubKeys,
|
||||
totalCollateral = collateral.satoshis,
|
||||
collateral = collateral.satoshis,
|
||||
fundingInputs = fundingInputs,
|
||||
changeAddress = changeAddress,
|
||||
payoutSerialId = payoutSerialId,
|
||||
|
@ -63,7 +63,7 @@ object DLCOfferDbHelper {
|
|||
offer.pubKeys.fundingKey,
|
||||
offer.pubKeys.payoutAddress,
|
||||
offer.payoutSerialId,
|
||||
offer.totalCollateral,
|
||||
offer.collateral,
|
||||
offer.changeAddress,
|
||||
offer.changeSerialId
|
||||
)
|
||||
|
|
|
@ -181,7 +181,7 @@ val offerTLV = DLCOfferTLV(
|
|||
fundingPubKey = ECPublicKey.freshPublicKey,
|
||||
payoutSPK = EmptyScriptPubKey,
|
||||
payoutSerialId = UInt64(1),
|
||||
totalCollateralSatoshis = Satoshis(500),
|
||||
offererCollateralSatoshis = Satoshis(500),
|
||||
fundingInputs = Vector(FundingInputV0TLV.dummy),
|
||||
changeSPK = EmptyScriptPubKey,
|
||||
changeSerialId = UInt64(2),
|
||||
|
|
|
@ -229,7 +229,7 @@ object TestDLCClient {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = offerOutcomes,
|
||||
pubKeys = offerPubKeys,
|
||||
totalCollateral = offerInput.satoshis,
|
||||
collateral = offerInput.satoshis,
|
||||
fundingInputs = offerFundingInputs,
|
||||
changeAddress = offerChangeAddress,
|
||||
payoutSerialId = offerPayoutSerialId,
|
||||
|
|
|
@ -387,6 +387,7 @@ trait TLVGen {
|
|||
payoutAddress <- AddressGenerator.bitcoinAddress
|
||||
payoutSerialId <- NumberGenerator.uInt64
|
||||
totalCollateralSatoshis <- CurrencyUnitGenerator.positiveRealistic
|
||||
.suchThat(_ <= contractInfo.totalCollateral)
|
||||
fundingInputs <- fundingInputV0TLVs(totalCollateralSatoshis)
|
||||
changeAddress <- AddressGenerator.bitcoinAddress
|
||||
changeSerialId <- NumberGenerator.uInt64
|
||||
|
@ -410,7 +411,7 @@ trait TLVGen {
|
|||
fundingPubKey = fundingPubKey,
|
||||
payoutSPK = payoutAddress.scriptPubKey,
|
||||
payoutSerialId = payoutSerialId,
|
||||
totalCollateralSatoshis = totalCollateralSatoshis,
|
||||
offererCollateralSatoshis = totalCollateralSatoshis,
|
||||
fundingInputs = fundingInputs,
|
||||
changeSPK = changeAddress.scriptPubKey,
|
||||
changeSerialId = changeSerialId,
|
||||
|
@ -473,12 +474,10 @@ trait TLVGen {
|
|||
payoutAddress <- AddressGenerator.bitcoinAddress
|
||||
payoutSerialId <- NumberGenerator.uInt64.suchThat(
|
||||
_ != offer.payoutSerialId)
|
||||
totalCollateralSatoshis <- CurrencyUnitGenerator.positiveRealistic
|
||||
totalCollateral = scala.math.max(
|
||||
(contractInfo.max - offer.totalCollateralSatoshis).satoshis.toLong,
|
||||
totalCollateralSatoshis.toLong)
|
||||
acceptCollateral =
|
||||
(contractInfo.totalCollateral - offer.offererCollateralSatoshis).satoshis.toLong
|
||||
fundingInputs <- fundingInputV0TLVs(
|
||||
Satoshis(totalCollateral),
|
||||
Satoshis(acceptCollateral),
|
||||
offer.fundingInputs.map(_.inputSerialId))
|
||||
changeAddress <- AddressGenerator.bitcoinAddress
|
||||
changeSerialId <- NumberGenerator.uInt64.suchThat(num =>
|
||||
|
@ -487,17 +486,17 @@ trait TLVGen {
|
|||
refundSig <- CryptoGenerators.digitalSignature
|
||||
} yield {
|
||||
DLCAcceptTLV(
|
||||
DLCOffer.fromTLV(offer).tempContractId,
|
||||
Satoshis(totalCollateral),
|
||||
fundingPubKey,
|
||||
payoutAddress.scriptPubKey,
|
||||
payoutSerialId,
|
||||
fundingInputs,
|
||||
changeAddress.scriptPubKey,
|
||||
changeSerialId,
|
||||
cetSigs,
|
||||
refundSig,
|
||||
NoNegotiationFieldsTLV
|
||||
tempContractId = DLCOffer.fromTLV(offer).tempContractId,
|
||||
acceptCollateralSatoshis = Satoshis(acceptCollateral),
|
||||
fundingPubKey = fundingPubKey,
|
||||
payoutSPK = payoutAddress.scriptPubKey,
|
||||
payoutSerialId = payoutSerialId,
|
||||
fundingInputs = fundingInputs,
|
||||
changeSPK = changeAddress.scriptPubKey,
|
||||
changeSerialId = changeSerialId,
|
||||
cetSignatures = cetSigs,
|
||||
refundSignature = refundSig,
|
||||
negotiationFields = NoNegotiationFieldsTLV
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ object DLCWalletUtil extends Logging {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = sampleContractInfo,
|
||||
pubKeys = dummyDLCKeys,
|
||||
totalCollateral = half,
|
||||
collateral = half,
|
||||
fundingInputs = Vector(dummyFundingInputs.head),
|
||||
changeAddress = dummyAddress,
|
||||
payoutSerialId = sampleOfferPayoutSerialId,
|
||||
|
@ -189,7 +189,7 @@ object DLCWalletUtil extends Logging {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = sampleContractInfo2,
|
||||
pubKeys = dummyDLCKeys,
|
||||
totalCollateral = sampleContractInfo2.totalCollateral,
|
||||
collateral = sampleContractInfo2.totalCollateral,
|
||||
fundingInputs = Vector(dummyFundingInputs.head),
|
||||
changeAddress = dummyAddress,
|
||||
payoutSerialId = sampleOfferPayoutSerialId,
|
||||
|
@ -203,7 +203,7 @@ object DLCWalletUtil extends Logging {
|
|||
protocolVersionOpt = DLCOfferTLV.currentVersionOpt,
|
||||
contractInfo = invalidContractInfo,
|
||||
pubKeys = dummyDLCKeys,
|
||||
totalCollateral = half,
|
||||
collateral = half,
|
||||
fundingInputs = Vector(dummyFundingInputs.head),
|
||||
changeAddress = dummyAddress,
|
||||
payoutSerialId = sampleOfferPayoutSerialId,
|
||||
|
@ -236,7 +236,7 @@ object DLCWalletUtil extends Logging {
|
|||
Vector(sampleOfferChangeSerialId, sampleFundOutputSerialId))
|
||||
|
||||
lazy val sampleDLCAccept: DLCAccept = DLCAccept(
|
||||
totalCollateral = half,
|
||||
collateral = half,
|
||||
pubKeys = dummyDLCKeys,
|
||||
fundingInputs = Vector(dummyFundingInputs.last),
|
||||
changeAddress = dummyAddress,
|
||||
|
|
Loading…
Add table
Reference in a new issue