CORDA-2128: Moved reference to internal NotaryService class out of public API (#4389)

This commit is contained in:
Shams Asari 2018-12-10 12:05:51 +00:00 committed by GitHub
parent feae71e401
commit 426db6c2f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 12 deletions

View File

@ -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<String>
val jarHash: SecureHash.SHA256
val notaryService: Class<out NotaryService>?
}

View File

@ -27,7 +27,7 @@ data class CordappImpl(
override val jarPath: URL,
val info: Info,
override val jarHash: SecureHash.SHA256,
override val notaryService: Class<out NotaryService>? = null,
val notaryService: Class<out NotaryService>?,
/** 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)

View File

@ -22,7 +22,13 @@ class MockCordappProvider(
private val cordappRegistry = mutableListOf<Pair<Cordapp, AttachmentId>>()
fun addMockCordapp(contractClassName: ContractClassName, attachments: MockAttachmentStorage, contractHash: AttachmentId? = null, signers: List<PublicKey> = emptyList(), jarManifestAttributes: Map<String,String> = emptyMap()): AttachmentId {
fun addMockCordapp(
contractClassName: ContractClassName,
attachments: MockAttachmentStorage,
contractHash: AttachmentId? = null,
signers: List<PublicKey> = emptyList(),
jarManifestAttributes: Map<String,String> = 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<ContractClassName>, data: ByteArray, attachments: MockAttachmentStorage, contractHash: AttachmentId?, signers: List<PublicKey>): AttachmentId {
val existingAttachment = attachments.files.filter { (attachmentId, content) ->
private fun findOrImportAttachment(
contractClassNames: List<ContractClassName>,
data: ByteArray,
attachments: MockAttachmentStorage,
contractHash: AttachmentId?,
signers: List<PublicKey>
): AttachmentId {
val existingAttachment = attachments.files.filter { (attachmentId, _) ->
contractHash == attachmentId
}
return if (!existingAttachment.isEmpty()) {
@ -60,7 +85,9 @@ class MockCordappProvider(
}
private val attachmentsCache = mutableMapOf<String, ByteArray>()
private fun fakeAttachmentCached(contractClass: String, manifestAttributes: Map<String,String> = emptyMap()): ByteArray = attachmentsCache.computeIfAbsent(contractClass + manifestAttributes.toSortedMap()) {
fakeAttachment(contractClass, contractClass, manifestAttributes)
private fun fakeAttachmentCached(contractClass: String, manifestAttributes: Map<String,String> = emptyMap()): ByteArray {
return attachmentsCache.computeIfAbsent(contractClass + manifestAttributes.toSortedMap()) {
fakeAttachment(contractClass, contractClass, manifestAttributes)
}
}
}