在Corda,我定义了以下流程:
object Flow {
@InitiatingFlow
@StartableByRPC
class Initiator(val otherParty: Party) : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
@Suspendable
override fun call() {
val otherPartyFlow = initiateFlow(otherParty)
otherPartyFlow.send(MyClass())
}
}
@InitiatedBy(Initiator::class)
class Acceptor(val otherPartyFlow: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val unregisteredClassInstance = otherPartyFlow.receive<MyClass>()
}
}
}
但是,当我尝试运行流程时,出现以下错误:
类com.example.flow.MyClass未注释或在白名单上, 所以不能用于序列化
如何对类进行注释或列入白名单以允许在流中发送?为什么我需要这样做?
答案 0 :(得分:3)
默认情况下,出于安全考虑,只能在流程内或通过RPC发送default serialization whitelist上的类。
有两种方法可以将特定类添加到序列化白名单中:
<强> 1。将该类注释为@CordaSerializable:
@CordaSerializable
class MyClass
<强> 2。创建序列化白名单插件:
按如下方式定义序列化插件:
class TemplateSerializationWhitelist : SerializationWhitelist {
override val whitelist: List<Class<*>> = listOf(MyClass::class.java)
}
然后在CorDapp的com.example.TemplateSerializationWhitelist
文件夹中列出序列化白名单插件的完全限定类名(例如net.corda.core.serialization.SerializationWhitelist
)。
为什么有两种方法可以将类添加到序列化白名单中?
第一种方法更容易,但如果您无法将注释添加到要发送的课程中,则无法实现。