Corda 提供了 Plugins 服務,共識僅驗證唯一性,將有效性交由交易雙方驗證。
這提供了隱私性和具擴展性的交易。
使用者若有自行新增註冊流程的需求,Corda 提供 3 種類型的 Plugins 和 API:
PluginRegistry 類別定義:
abstract class CordaPluginRegistry
(
open val webApis: List<Function<CordaRPCOps, out Any>> = emptyList(),
open val staticServeDirs: Map<String, String> = emptyMap(),
open val requiredFlows: Map<String, Set<String>> = emptyMap(),
open val servicePlugins: List<Function<PluginServiceHub, out Any>> =
emptyList()
)
{
open fun registerRPCKryoTypes(kryo: Kryo): Boolean = false
}
Web APIs:使用 Java API for RESTful Web Services, JAX-RS
@Path("example")
class ExampleApi(val services: CordaRPCOps)
The syntax is as follows:
override val webApis: List<Function<CordaRPCOps, out Any>> =
listOf(Function(::ExampleApi))
靜態內容(Static Content)
override val staticServeDirs: Map<String, String> =
mapOf
(
"example" to javaClass
.classLoader
.getResource("exampleWeb")
.toExternalForm()
)
流程(Flows)
override val requiredFlows: Map<String, Set<String>> =
mapOf
(
ExampleFlow.Initiator::class.java.name to setOf
(
argClass1::class.java.name
, argClass2::class.java.name
, …)
)
Kyro 序列化流程類別
override fun registerRPCKryoTypes(kryo: Kryo): Boolean
{
kryo.register(MyClass::class.java) …
}