diff --git a/core/src/main/kotlin/net/corda/core/transactions/LedgerTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/LedgerTransaction.kt index 5997ce891f..773741dd53 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/LedgerTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/LedgerTransaction.kt @@ -61,19 +61,17 @@ data class LedgerTransaction @JvmOverloads constructor( } private companion object { - private fun createContractFor(className: ContractClassName, classLoader: ClassLoader?): Try { + private fun contractClassFor(className: ContractClassName, classLoader: ClassLoader?): Try> { return Try.on { (classLoader ?: this::class.java.classLoader) .loadClass(className) .asSubclass(Contract::class.java) - .getConstructor() - .newInstance() } } } - private val contracts: Map> = (inputs.map { it.state } + outputs) - .map { it.contract to createContractFor(it.contract, it.data::class.java.classLoader) }.toMap() + private val contracts: Map>> = (inputs.map { it.state } + outputs) + .map { it.contract to contractClassFor(it.contract, it.data::class.java.classLoader) }.toMap() val inputStates: List get() = inputs.map { it.state.data } @@ -135,11 +133,11 @@ data class LedgerTransaction @JvmOverloads constructor( when (result) { is Try.Failure -> throw TransactionVerificationException.ContractCreationError(id, key, result.exception) is Try.Success -> { - val contract = result.value try { + val contract = result.value.newInstance() contract.verify(this) } catch (e: Throwable) { - throw TransactionVerificationException.ContractRejection(id, contract, e) + throw TransactionVerificationException.ContractRejection(id, result.value.name, e) } } }