diff --git a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt index 19cab5b63a..77c1453c44 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt @@ -212,7 +212,7 @@ open class TransactionBuilder @JvmOverloads constructor( val refStateContractAttachments: List = referenceStateGroups .filterNot { it.key in allContracts } .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. @@ -287,7 +287,7 @@ open class TransactionBuilder @JvmOverloads constructor( fun selectAttachment() = selectAttachmentThatSatisfiesConstraints( false, contractClassName, - inputsAndOutputs.map { it.constraint }.toSet().filterNot { it in automaticConstraints }, + inputsAndOutputs.filterNot { it.constraint in automaticConstraints }, services) // This will contain the hash of the JAR that will be used by this Transaction. @@ -417,10 +417,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 - 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, services: ServicesForResolution): AttachmentId { + private fun selectAttachmentThatSatisfiesConstraints(isReference: Boolean, contractClassName: String, states: List>, services: ServicesForResolution): AttachmentId { + val constraints = states.map { it.constraint } require(constraints.none { it in automaticConstraints }) 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