Merge pull request #669 from corda/chrisr3-merge-os

ENT-1463: Instantiate all contract classes before verifying any of them.
This commit is contained in:
Chris Rankin 2018-04-03 16:34:48 +01:00 committed by GitHub
commit 626ff5ec77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,17 +129,24 @@ data class LedgerTransaction @JvmOverloads constructor(
* If any contract fails to verify, the whole transaction is considered to be invalid. * If any contract fails to verify, the whole transaction is considered to be invalid.
*/ */
private fun verifyContracts() { private fun verifyContracts() {
val contractInstances = ArrayList<Contract>(contracts.size)
for ((key, result) in contracts) { for ((key, result) in contracts) {
when (result) { when (result) {
is Try.Failure -> throw TransactionVerificationException.ContractCreationError(id, key, result.exception) is Try.Failure -> throw TransactionVerificationException.ContractCreationError(id, key, result.exception)
is Try.Success -> { is Try.Success -> {
try { try {
val contract = result.value.newInstance() contractInstances.add(result.value.newInstance())
} catch (e: Throwable) {
throw TransactionVerificationException.ContractCreationError(id, result.value.name, e)
}
}
}
}
contractInstances.forEach { contract ->
try {
contract.verify(this) contract.verify(this)
} catch (e: Throwable) { } catch (e: Throwable) {
throw TransactionVerificationException.ContractRejection(id, result.value.name, e) throw TransactionVerificationException.ContractRejection(id, contract, e)
}
}
} }
} }
} }