mirror of
https://github.com/corda/corda.git
synced 2024-12-24 15:16:45 +00:00
ENT-1463: Instantiate the contract class as part of contract verification. (#660)
* Instantiating the contract class should be part of contract verification. We should not instantiate it while building LedgerTransaction. * Also catch any exceptions from instantiating the contract.
This commit is contained in:
parent
10e97f4919
commit
9c07e67100
@ -61,19 +61,17 @@ data class LedgerTransaction @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private fun createContractFor(className: ContractClassName, classLoader: ClassLoader?): Try<Contract> {
|
||||
private fun contractClassFor(className: ContractClassName, classLoader: ClassLoader?): Try<Class<out Contract>> {
|
||||
return Try.on {
|
||||
(classLoader ?: this::class.java.classLoader)
|
||||
.loadClass(className)
|
||||
.asSubclass(Contract::class.java)
|
||||
.getConstructor()
|
||||
.newInstance()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val contracts: Map<ContractClassName, Try<Contract>> = (inputs.map { it.state } + outputs)
|
||||
.map { it.contract to createContractFor(it.contract, it.data::class.java.classLoader) }.toMap()
|
||||
private val contracts: Map<ContractClassName, Try<Class<out Contract>>> = (inputs.map { it.state } + outputs)
|
||||
.map { it.contract to contractClassFor(it.contract, it.data::class.java.classLoader) }.toMap()
|
||||
|
||||
val inputStates: List<ContractState> 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user