From cb670dcb6255aa07c2b06fe1e381d0c4d032634c Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 3 Apr 2018 12:14:53 +0100 Subject: [PATCH] ENT-1463: Instantiate all contract classes before verifying any of them. (#2906) --- .../corda/core/transactions/LedgerTransaction.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 4128e0b6c5..1f86e50b27 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/LedgerTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/LedgerTransaction.kt @@ -119,19 +119,26 @@ data class LedgerTransaction @JvmOverloads constructor( * If any contract fails to verify, the whole transaction is considered to be invalid. */ private fun verifyContracts() { + val contractInstances = ArrayList(contracts.size) for ((key, result) in contracts) { when (result) { is Try.Failure -> throw TransactionVerificationException.ContractCreationError(id, key, result.exception) is Try.Success -> { try { - val contract = result.value.newInstance() - contract.verify(this) + contractInstances.add(result.value.newInstance()) } catch (e: Throwable) { - throw TransactionVerificationException.ContractRejection(id, result.value.name, e) + throw TransactionVerificationException.ContractCreationError(id, result.value.name, e) } } } } + contractInstances.forEach { contract -> + try { + contract.verify(this) + } catch (e: Throwable) { + throw TransactionVerificationException.ContractRejection(id, contract, e) + } + } } /**