Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-15267 Make MemberInfo serializable #5127

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ commonsTextVersion = 1.10.0
bouncycastleVersion=1.76
# Corda API libs revision (change in 4th digit indicates a breaking change)
# Change to 5.1.0.xx-SNAPSHOT to pick up maven local published copy
cordaApiVersion=5.1.0.38-beta+
cordaApiVersion=5.1.0.39-beta+

disruptorVersion=3.4.4
felixConfigAdminVersion=1.9.26
Expand Down
2 changes: 2 additions & 0 deletions libs/membership/membership-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ dependencies {
implementation project(':libs:crypto:crypto-core')
implementation project(":libs:membership:membership-common")
implementation project(":libs:utilities")
implementation project(':libs:sandbox-types')
implementation project(":libs:serialization:serialization-avro")
implementation project(':libs:serialization:serialization-internal')

implementation "net.corda:corda-avro-schema"
implementation "net.corda:corda-base"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package net.corda.membership.lib.impl.serializer.amqp

import net.corda.layeredpropertymap.LayeredPropertyMapFactory
import net.corda.membership.lib.impl.MGMContextImpl
import net.corda.sandbox.type.SandboxConstants
import net.corda.sandbox.type.UsedByFlow
import net.corda.sandbox.type.UsedByPersistence
import net.corda.sandbox.type.UsedByVerification
import net.corda.serialization.BaseProxySerializer
import net.corda.serialization.InternalCustomSerializer
import net.corda.v5.base.exceptions.CordaRuntimeException
import net.corda.v5.base.types.LayeredPropertyMap
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference
import org.osgi.service.component.annotations.ServiceScope

@Component(
service = [ InternalCustomSerializer::class, UsedByFlow::class, UsedByPersistence::class, UsedByVerification::class ],
property = [SandboxConstants.CORDA_UNINJECTABLE_SERVICE],
scope = ServiceScope.PROTOTYPE
)
class MGMContextSerializer @Activate constructor(
@Reference(service = LayeredPropertyMapFactory::class)
private val layeredPropertyMapFactory: LayeredPropertyMapFactory,
) : BaseProxySerializer<MGMContextImpl, MGMContextProxy>(), UsedByFlow, UsedByPersistence, UsedByVerification {
private companion object {
private const val VERSION_1 = 1
}

override fun toProxy(obj: MGMContextImpl): MGMContextProxy {
return MGMContextProxy(
VERSION_1,
obj.toMap()
)
}

override fun fromProxy(proxy: MGMContextProxy): MGMContextImpl {
return when(proxy.version) {
VERSION_1 ->
MGMContextImpl(layeredPropertyMapFactory.createMap(proxy.map))
else ->
throw CordaRuntimeException("Unable to create MGMContextImpl with Version='${proxy.version}'")
}
}

override val proxyType: Class<MGMContextProxy>
get() = MGMContextProxy::class.java

override val type: Class<MGMContextImpl>
get() = MGMContextImpl::class.java

override val withInheritance: Boolean
get() = false

private fun LayeredPropertyMap.toMap() = this.entries.associate { it.key to it.value }

}

/**
* The class that actually gets serialized on the wire.
*/
data class MGMContextProxy(
/**
* Version of container.
*/
val version: Int,
/**
* Properties for [MGMContextImpl] serialization.
*/
val map: Map<String, String?>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package net.corda.membership.lib.impl.serializer.amqp

import net.corda.layeredpropertymap.LayeredPropertyMapFactory
import net.corda.membership.lib.impl.MemberContextImpl
import net.corda.sandbox.type.SandboxConstants.CORDA_UNINJECTABLE_SERVICE
import net.corda.sandbox.type.UsedByFlow
import net.corda.sandbox.type.UsedByPersistence
import net.corda.sandbox.type.UsedByVerification
import net.corda.serialization.BaseProxySerializer
import net.corda.serialization.InternalCustomSerializer
import net.corda.v5.base.exceptions.CordaRuntimeException
import net.corda.v5.base.types.LayeredPropertyMap
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference
import org.osgi.service.component.annotations.ServiceScope

@Component(
service = [ InternalCustomSerializer::class, UsedByFlow::class, UsedByPersistence::class, UsedByVerification::class ],
property = [ CORDA_UNINJECTABLE_SERVICE ],
scope = ServiceScope.PROTOTYPE
)
class MemberContextSerializer @Activate constructor(
@Reference(service = LayeredPropertyMapFactory::class)
private val layeredPropertyMapFactory: LayeredPropertyMapFactory,
) : BaseProxySerializer<MemberContextImpl, MemberContextProxy>(), UsedByFlow, UsedByPersistence, UsedByVerification {
private companion object {
private const val VERSION_1 = 1
}

override fun toProxy(obj: MemberContextImpl): MemberContextProxy {
return MemberContextProxy(
VERSION_1,
obj.toMap()
)
}

override fun fromProxy(proxy: MemberContextProxy): MemberContextImpl {
return when(proxy.version) {
VERSION_1 ->
MemberContextImpl(layeredPropertyMapFactory.createMap(proxy.map))
else ->
throw CordaRuntimeException("Unable to create MemberContextImpl with Version='${proxy.version}'")
}
}

override val proxyType: Class<MemberContextProxy>
get() = MemberContextProxy::class.java

override val type: Class<MemberContextImpl>
get() = MemberContextImpl::class.java

override val withInheritance: Boolean
get() = false

private fun LayeredPropertyMap.toMap() = this.entries.associate { it.key to it.value }

}

/**
* The class that actually gets serialized on the wire.
*/
data class MemberContextProxy(
/**
* Version of container.
*/
val version: Int,
/**
* Properties for [MemberContextImpl] serialization.
*/
val map: Map<String, String?>
)