Revert unnecessary refactoring.

This commit is contained in:
josecoll 2019-02-14 16:30:28 +00:00 committed by Mike Hearn
parent 758c855493
commit a17ab0d547
2 changed files with 9 additions and 16 deletions

View File

@ -7,7 +7,6 @@ import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.isFulfilledBy import net.corda.core.crypto.isFulfilledBy
import net.corda.core.internal.AttachmentWithContext import net.corda.core.internal.AttachmentWithContext
import net.corda.core.internal.isUploaderTrusted import net.corda.core.internal.isUploaderTrusted
import net.corda.core.internal.warnOnce
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
@ -52,19 +51,12 @@ data class HashAttachmentConstraint(val attachmentId: SecureHash) : AttachmentCo
val disableHashConstraints = System.getProperty("net.corda.node.disableHashConstraints")?.toBoolean() ?: false val disableHashConstraints = System.getProperty("net.corda.node.disableHashConstraints")?.toBoolean() ?: false
} }
override fun isSatisfiedBy(attachment: Attachment): Boolean { override fun isSatisfiedBy(attachment: Attachment): Boolean {
return when { return if (attachment is AttachmentWithContext) {
disableHashConstraints -> { log.debug("Checking attachment uploader ${attachment.contractAttachment.uploader} is trusted")
log.warnOnce("Skipping hash constraints verification.") attachment.id == attachmentId && isUploaderTrusted(attachment.contractAttachment.uploader)
true } else {
} log.warn("Hash constraint check failed: $attachmentId does not match contract attachment JAR ${attachment.id} or contract attachment JAR is untrusted")
attachment is AttachmentWithContext -> { false
log.debug("Checking attachment uploader ${attachment.contractAttachment.uploader} is trusted")
attachment.id == attachmentId && isUploaderTrusted(attachment.contractAttachment.uploader)
}
else -> {
log.warn("Hash constraint check failed: $attachmentId does not match contract attachment JAR ${attachment.id} or contract attachment JAR is untrusted")
false
}
} }
} }
} }

View File

@ -338,9 +338,10 @@ class Verifier(val ltx: LedgerTransaction,
val constraintAttachment = AttachmentWithContext(contractAttachment, contract, ltx.networkParameters!!.whitelistedContractImplementations) val constraintAttachment = AttachmentWithContext(contractAttachment, contract, ltx.networkParameters!!.whitelistedContractImplementations)
if (!constraint.isSatisfiedBy(constraintAttachment)) { if (HashAttachmentConstraint.disableHashConstraints && constraint is HashAttachmentConstraint)
logger.warnOnce("Skipping hash constraints verification.")
else if (!constraint.isSatisfiedBy(constraintAttachment))
throw TransactionVerificationException.ContractConstraintRejection(ltx.id, contract) throw TransactionVerificationException.ContractConstraintRejection(ltx.id, contract)
}
} }
} }