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,19 +129,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<Contract>(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)
}
}
}
/**