2022 04 14 dlctxsigner err msg (#4262)

* Improve error messages for invariants in DLCTxSigner

* scalafmt
This commit is contained in:
Chris Stewart 2022-04-14 09:19:03 -05:00 committed by GitHub
parent 0a092e4e03
commit 07209ce670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,9 +44,14 @@ case class DLCTxSigner(
}
if (isInitiator) {
require(fundingKey.publicKey == offer.pubKeys.fundingKey &&
finalAddress == offer.pubKeys.payoutAddress,
"Given keys do not match public key and address in offer")
require(
fundingKey.publicKey == offer.pubKeys.fundingKey,
s"Given keys do not match public key and address in offer, funding.publicKey=${fundingKey.publicKey} offer.pubKeys.fundingKey=${offer.pubKeys.fundingKey}"
)
require(
finalAddress == offer.pubKeys.payoutAddress,
s"Final address and offerer payout address must be identical finalAddress=$finalAddress offer.pubKeys.payoutAddress=${offer.pubKeys.payoutAddress}"
)
val fundingUtxosAsInputs =
fundingUtxos
.sortBy(_.outPoint.bytes)
@ -57,14 +62,21 @@ case class DLCTxSigner(
fund.sequence)
}
.sortBy(_.inputSerialId)
require(fundingUtxosAsInputs == offer.fundingInputs.sortBy(_.inputSerialId),
"Funding ScriptSignatureParams did not match offer funding inputs")
val sortedOfferInputs = offer.fundingInputs.sortBy(_.inputSerialId)
require(
fundingUtxosAsInputs == sortedOfferInputs,
s"Funding ScriptSignatureParams did not match offer funding inputs, fundingUtxosAsInputs=${fundingUtxosAsInputs} sortedOffererInputs=$sortedOfferInputs"
)
} else {
require(
fundingKey.publicKey == accept.pubKeys.fundingKey &&
finalAddress == accept.pubKeys.payoutAddress,
fundingKey.publicKey == accept.pubKeys.fundingKey,
"Given keys do not match public key and address in accept"
)
require(
finalAddress == accept.pubKeys.payoutAddress,
s"Final address and acceptor payout address don't match, finalAddress=$finalAddress accept.pubKeys.payoutAddress=${accept.pubKeys.payoutAddress}"
)
val fundingUtxosAsInputs =
fundingUtxos
.sortBy(_.outPoint.bytes)
@ -75,9 +87,10 @@ case class DLCTxSigner(
fund.sequence)
}
.sortBy(_.inputSerialId)
val sortedAcceptInputs = accept.fundingInputs.sortBy(_.inputSerialId)
require(
fundingUtxosAsInputs == accept.fundingInputs.sortBy(_.inputSerialId),
"Funding ScriptSignatureParams did not match accept funding inputs"
fundingUtxosAsInputs == sortedAcceptInputs,
s"Funding ScriptSignatureParams did not match offer funding inputs, fundingUtxosAsInputs=${fundingUtxosAsInputs} sortedAcceptInputs=$sortedAcceptInputs"
)
}