diff --git a/core/src/main/kotlin/net/corda/core/contracts/ContractsDSL.kt b/core/src/main/kotlin/net/corda/core/contracts/ContractsDSL.kt index 0737f9d498..0711228d38 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/ContractsDSL.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/ContractsDSL.kt @@ -93,13 +93,14 @@ inline fun Collection filter { if (parties == null) true else it.signingParties.containsAll(parties) }. map { AuthenticatedObject(it.signers, it.signingParties, it.value as T) } +/** Ensures that a transaction has only one command that is of the given type, otherwise throws an exception. */ inline fun Collection>.requireSingleCommand() = try { select().single() } catch (e: NoSuchElementException) { throw IllegalStateException("Required ${T::class.qualifiedName} command") // Better error message. } -// For Java +/** Ensures that a transaction has only one command that is of the given type, otherwise throws an exception. */ fun Collection>.requireSingleCommand(klass: Class) = mapNotNull { @Suppress("UNCHECKED_CAST") if (klass.isInstance(it.value)) it as AuthenticatedObject else null }.single()