CORDA-1670 fix multiple CorDapps for flow check (#3436)

* CORDA-1670 fix multiple CorDapps for flow check

* CORDA-1670 fix multiple CorDapps for flow check

* CORDA-1670 address code review comment
This commit is contained in:
Tudor Malene 2018-06-26 11:32:49 +01:00 committed by GitHub
parent 1d95ffba3a
commit 4ea8091667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import net.corda.node.NodeRegistrationOption
import net.corda.node.SerialFilter
import net.corda.node.VersionInfo
import net.corda.node.defaultSerialFilter
import net.corda.node.internal.cordapp.MultipleCordappsForFlowException
import net.corda.node.services.config.NodeConfiguration
import net.corda.node.services.config.NodeConfigurationImpl
import net.corda.node.services.config.shouldStartLocalShell
@ -135,6 +136,9 @@ open class NodeStartup(val args: Array<String>) {
try {
cmdlineOptions.baseDirectory.createDirectories()
startNode(conf, versionInfo, startTime, cmdlineOptions)
} catch (e: MultipleCordappsForFlowException) {
logger.error(e.message)
return false
} catch (e: CouldNotCreateDataSourceException) {
logger.error(e.message, e.cause)
return false

View File

@ -50,7 +50,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
cordapps.flatMap { corDapp -> corDapp.allFlows.map { flow -> flow to corDapp } }
.groupBy { it.first }
.mapValues {
require(it.value.size == 1) { "There are multiple CorDapp jars on the classpath for flow ${it.value.first().first.name}: ${it.value.map { it.second.name }.joinToString()}." }
if(it.value.size > 1) { throw MultipleCordappsForFlowException("There are multiple CorDapp JARs on the classpath for flow ${it.value.first().first.name}: [ ${it.value.joinToString { it.second.name }} ].") }
it.value.single().second
}
}
@ -363,3 +363,8 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
}
}
}
/**
* Thrown when scanning CorDapps.
*/
class MultipleCordappsForFlowException(message: String) : Exception(message)

View File

@ -41,6 +41,9 @@ open class CordappProviderImpl(private val cordappLoader: CordappLoader,
private fun verifyInstalledCordapps(attachmentStorage: AttachmentStorage) {
// This will invoke the lazy flowCordappMap property, thus triggering the MultipleCordappsForFlow check.
cordappLoader.flowCordappMap
if (whitelistedContractImplementations.isEmpty()) {
log.warn("The network parameters don't specify any whitelisted contract implementations. Please contact your zone operator. See https://docs.corda.net/network-map.html")
return