ENT-2675 Improve error message (#4258)

* ENT-2675 Improve error message

* ENT-2675 Improve error message
This commit is contained in:
Tudor Malene 2018-11-20 14:19:32 +00:00 committed by GitHub
parent 97c1e5babc
commit f321c4c0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -175,7 +175,7 @@ open class TransactionBuilder @JvmOverloads constructor(
val refStateContractAttachments: List<AttachmentId> = referenceStateGroups val refStateContractAttachments: List<AttachmentId> = referenceStateGroups
.filterNot { it.key in allContracts } .filterNot { it.key in allContracts }
.map { refStateEntry -> .map { refStateEntry ->
selectAttachmentThatSatisfiesConstraints(true, refStateEntry.key, refStateEntry.value.map { it.constraint }, services) selectAttachmentThatSatisfiesConstraints(true, refStateEntry.key, refStateEntry.value, services)
} }
// For each contract, resolve the AutomaticPlaceholderConstraint, and select the attachment. // For each contract, resolve the AutomaticPlaceholderConstraint, and select the attachment.
@ -250,7 +250,7 @@ open class TransactionBuilder @JvmOverloads constructor(
fun selectAttachment() = selectAttachmentThatSatisfiesConstraints( fun selectAttachment() = selectAttachmentThatSatisfiesConstraints(
false, false,
contractClassName, contractClassName,
inputsAndOutputs.map { it.constraint }.toSet().filterNot { it in automaticConstraints }, inputsAndOutputs.filterNot { it.constraint in automaticConstraints },
services) services)
// This will contain the hash of the JAR that will be used by this Transaction. // This will contain the hash of the JAR that will be used by this Transaction.
@ -380,10 +380,11 @@ open class TransactionBuilder @JvmOverloads constructor(
* TODO - When the SignatureConstraint and contract version logic is in, this will need to query the attachments table and find the latest one that satisfies all constraints. * TODO - When the SignatureConstraint and contract version logic is in, this will need to query the attachments table and find the latest one that satisfies all constraints.
* TODO - select a version of the contract that is no older than the one from the previous transactions. * TODO - select a version of the contract that is no older than the one from the previous transactions.
*/ */
private fun selectAttachmentThatSatisfiesConstraints(isReference: Boolean, contractClassName: String, constraints: List<AttachmentConstraint>, services: ServicesForResolution): AttachmentId { private fun selectAttachmentThatSatisfiesConstraints(isReference: Boolean, contractClassName: String, states: List<TransactionState<ContractState>>, services: ServicesForResolution): AttachmentId {
val constraints = states.map { it.constraint }
require(constraints.none { it in automaticConstraints }) require(constraints.none { it in automaticConstraints })
require(isReference || constraints.none { it is HashAttachmentConstraint }) require(isReference || constraints.none { it is HashAttachmentConstraint })
return services.cordappProvider.getContractAttachmentID(contractClassName)!! return services.cordappProvider.getContractAttachmentID(contractClassName) ?: throw MissingContractAttachments(states)
} }
private fun useWhitelistedByZoneAttachmentConstraint(contractClassName: ContractClassName, networkParameters: NetworkParameters) = contractClassName in networkParameters.whitelistedContractImplementations.keys private fun useWhitelistedByZoneAttachmentConstraint(contractClassName: ContractClassName, networkParameters: NetworkParameters) = contractClassName in networkParameters.whitelistedContractImplementations.keys