ENT-11355: Cleanup of TransactionBuilder and CorDapp loading

This is code refactoring and cleanup that is required to add a new WireTransaction component group for 4.12+ attachments, and for supporting legacy (4.11 or older) contract CorDapps in the node.
This commit is contained in:
Shams Asari
2024-02-08 17:54:04 +00:00
parent c7514e1c60
commit 8fd3139df1
33 changed files with 665 additions and 700 deletions

View File

@ -6,7 +6,11 @@ import net.corda.core.contracts.ContractClassName
import net.corda.core.contracts.UpgradedContract
import net.corda.core.contracts.UpgradedContractWithLegacyConstraint
import net.corda.core.crypto.SecureHash
import net.corda.core.internal.*
import net.corda.core.internal.copyTo
import net.corda.core.internal.hash
import net.corda.core.internal.logElapsedTime
import net.corda.core.internal.pooledScan
import net.corda.core.internal.read
import org.slf4j.LoggerFactory
import java.io.InputStream
import java.nio.file.Files
@ -17,7 +21,7 @@ import kotlin.io.path.deleteIfExists
// When scanning of the CorDapp Jar is performed without "corda-core.jar" being in the classpath, there is no way to appreciate
// relationships between those interfaces, therefore they have to be listed explicitly.
val coreContractClasses = setOf(Contract::class, UpgradedContractWithLegacyConstraint::class, UpgradedContract::class)
val coreContractClasses = setOf(Contract::class.java, UpgradedContractWithLegacyConstraint::class.java, UpgradedContract::class.java)
interface ContractsJar {
val hash: SecureHash
@ -32,7 +36,8 @@ class ContractsJarFile(private val file: Path) : ContractsJar {
return scanResult.use { result ->
coreContractClasses
.flatMap { result.getClassesImplementing(it.qualifiedName)}
.asSequence()
.flatMap(result::getClassesImplementing)
.filterNot { it.isAbstract }
.filterNot { it.isInterface }
.map { it.name }

View File

@ -1,15 +1,14 @@
package net.corda.nodeapi.internal.cordapp
import net.corda.core.cordapp.Cordapp
import net.corda.core.flows.FlowLogic
import net.corda.core.internal.cordapp.CordappImpl
import net.corda.core.internal.flatMapToSet
import net.corda.core.schemas.MappedSchema
/**
* Handles loading [Cordapp]s.
*/
interface CordappLoader : AutoCloseable {
/**
* Returns all [Cordapp]s found.
*/
@ -19,15 +18,10 @@ interface CordappLoader : AutoCloseable {
* Returns a [ClassLoader] containing all types from all [Cordapp]s.
*/
val appClassLoader: ClassLoader
}
/**
* Returns a map between flow class and owning [Cordapp].
* The mappings are unique, and the node will not start otherwise.
*/
val flowCordappMap: Map<Class<out FlowLogic<*>>, Cordapp>
/**
* Returns all [MappedSchema] found inside the [Cordapp]s.
*/
val cordappSchemas: Set<MappedSchema>
}
/**
* Returns all [MappedSchema] found inside the [Cordapp]s.
*/
val CordappLoader.cordappSchemas: Set<MappedSchema>
get() = cordapps.flatMapToSet { it.customSchemas }