From 426db6c2f2c5cd11a3e459070b05d211124d7583 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Mon, 10 Dec 2018 12:05:51 +0000 Subject: [PATCH] CORDA-2128: Moved reference to internal NotaryService class out of public API (#4389) --- .../kotlin/net/corda/core/cordapp/Cordapp.kt | 2 - .../core/internal/cordapp/CordappImpl.kt | 2 +- .../testing/internal/MockCordappProvider.kt | 45 +++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt b/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt index 9ca4e04e36..ddf369b668 100644 --- a/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt +++ b/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt @@ -4,7 +4,6 @@ import net.corda.core.DeleteForDJVM import net.corda.core.DoNotImplement import net.corda.core.crypto.SecureHash import net.corda.core.flows.FlowLogic -import net.corda.core.internal.notary.NotaryService import net.corda.core.schemas.MappedSchema import net.corda.core.serialization.SerializationCustomSerializer import net.corda.core.serialization.SerializationWhitelist @@ -49,5 +48,4 @@ interface Cordapp { val jarPath: URL val cordappClasses: List val jarHash: SecureHash.SHA256 - val notaryService: Class? } diff --git a/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt b/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt index 2d6075a5e3..afcaeb0af9 100644 --- a/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt +++ b/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt @@ -27,7 +27,7 @@ data class CordappImpl( override val jarPath: URL, val info: Info, override val jarHash: SecureHash.SHA256, - override val notaryService: Class? = null, + val notaryService: Class?, /** Indicates whether the CorDapp is loaded from external sources, or generated on node startup (virtual). */ val isLoaded: Boolean = true) : Cordapp { override val name: String = jarName(jarPath) diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappProvider.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappProvider.kt index 63af2c3106..5291c124a2 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappProvider.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappProvider.kt @@ -22,7 +22,13 @@ class MockCordappProvider( private val cordappRegistry = mutableListOf>() - fun addMockCordapp(contractClassName: ContractClassName, attachments: MockAttachmentStorage, contractHash: AttachmentId? = null, signers: List = emptyList(), jarManifestAttributes: Map = emptyMap()): AttachmentId { + fun addMockCordapp( + contractClassName: ContractClassName, + attachments: MockAttachmentStorage, + contractHash: AttachmentId? = null, + signers: List = emptyList(), + jarManifestAttributes: Map = emptyMap() + ): AttachmentId { val cordapp = CordappImpl( contractClassNames = listOf(contractClassName), initiatedFlows = emptyList(), @@ -36,20 +42,39 @@ class MockCordappProvider( jarPath = Paths.get("").toUri().toURL(), info = CordappImpl.Info.UNKNOWN, allFlows = emptyList(), - jarHash = SecureHash.allOnesHash) + jarHash = SecureHash.allOnesHash, + notaryService = null + ) val jarManifestAttributesWithObligatoryElement = jarManifestAttributes.toMutableMap() jarManifestAttributesWithObligatoryElement.putIfAbsent(Attributes.Name.MANIFEST_VERSION.toString(), "1.0") if (cordappRegistry.none { it.first.contractClassNames.contains(contractClassName) && it.second == contractHash }) { - cordappRegistry.add(Pair(cordapp, findOrImportAttachment(listOf(contractClassName), fakeAttachmentCached(contractClassName, jarManifestAttributesWithObligatoryElement), attachments, contractHash, signers))) + cordappRegistry.add(Pair( + cordapp, + findOrImportAttachment( + listOf(contractClassName), + fakeAttachmentCached(contractClassName, jarManifestAttributesWithObligatoryElement), + attachments, + contractHash, + signers + ) + )) } return cordappRegistry.findLast { contractClassName in it.first.contractClassNames }?.second!! } - override fun getContractAttachmentID(contractClassName: ContractClassName): AttachmentId? = cordappRegistry.find { it.first.contractClassNames.contains(contractClassName) }?.second - ?: super.getContractAttachmentID(contractClassName) + override fun getContractAttachmentID(contractClassName: ContractClassName): AttachmentId? { + return cordappRegistry.find { it.first.contractClassNames.contains(contractClassName) }?.second + ?: super.getContractAttachmentID(contractClassName) + } - private fun findOrImportAttachment(contractClassNames: List, data: ByteArray, attachments: MockAttachmentStorage, contractHash: AttachmentId?, signers: List): AttachmentId { - val existingAttachment = attachments.files.filter { (attachmentId, content) -> + private fun findOrImportAttachment( + contractClassNames: List, + data: ByteArray, + attachments: MockAttachmentStorage, + contractHash: AttachmentId?, + signers: List + ): AttachmentId { + val existingAttachment = attachments.files.filter { (attachmentId, _) -> contractHash == attachmentId } return if (!existingAttachment.isEmpty()) { @@ -60,7 +85,9 @@ class MockCordappProvider( } private val attachmentsCache = mutableMapOf() - private fun fakeAttachmentCached(contractClass: String, manifestAttributes: Map = emptyMap()): ByteArray = attachmentsCache.computeIfAbsent(contractClass + manifestAttributes.toSortedMap()) { - fakeAttachment(contractClass, contractClass, manifestAttributes) + private fun fakeAttachmentCached(contractClass: String, manifestAttributes: Map = emptyMap()): ByteArray { + return attachmentsCache.computeIfAbsent(contractClass + manifestAttributes.toSortedMap()) { + fakeAttachment(contractClass, contractClass, manifestAttributes) + } } }