Kotlin Corda-包含该软件包的CorDapp不止一个
我正在构建一个需要多个应用程序的应用程序;让我们称它们为LibCorDapp和AppCorDapp,其中AppCorDapp取决于LibCorDapp(就像CorDapp可能取决于帐户或代币SDK) LibCorDapp-合同 此CorDapp的目的是定义状态和契约的对象模型,这些对象模型可以开箱即用,但也可以从中派生,以创建更明确的状态和契约类型 build.gradleKotlin Corda-包含该软件包的CorDapp不止一个,kotlin,corda,Kotlin,Corda,我正在构建一个需要多个应用程序的应用程序;让我们称它们为LibCorDapp和AppCorDapp,其中AppCorDapp取决于LibCorDapp(就像CorDapp可能取决于帐户或代币SDK) LibCorDapp-合同 此CorDapp的目的是定义状态和契约的对象模型,这些对象模型可以开箱即用,但也可以从中派生,以创建更明确的状态和契约类型 build.gradle cordapp { targetPlatformVersion cordapp_platform_version
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name cordapp_contract_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
workflow {
name cordapp_workflow_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name "Test CorDapp Contract"
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
implementation "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
示例状态
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name cordapp_contract_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
workflow {
name cordapp_workflow_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name "Test CorDapp Contract"
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
implementation "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
package com.example.libcordapp.contract
@BelongsToContract(示例contract::class)
开放类示例状态(
覆盖val参与者:List=emptyList(),
val值:T
):ContractState{…}
合同示例
package com.example.libcordapp.contract
开放类范例合同{
最终覆盖验证(tx:LedgerTransaction){…}
受保护的open fun onVerifyCreate(tx:LedgerTransaction,签名者:Set)=单位
}
注意ExampleState
和ExampleContract
之间的关系。它们都是open
,并且ExampleContract
包含一个可重写的函数,允许派生类在创建时指定额外的契约逻辑
LibCorDapp-工作流
此CorDapp的目的是定义允许创建、更新和使用示例状态的流。这些流还应适用于从ExampleState
和examplestract
派生的状态和契约
build.gradle
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name cordapp_contract_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
workflow {
name cordapp_workflow_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name "Test CorDapp Contract"
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
implementation "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
示例流
package com.example.libcordapp.workflow
类ExampleFlow(val状态:ExampleState):FlowLogic(){
@暂停
重写趣味调用():SignedTransaction{
val tx=与(TransactionBuilder(公证人)){
addOutputState(状态)
addCommand(例如contract.Issue、signers)
}
}
}
注意,我没有为输出状态显式定义契约ID,因为它应该在运行时为每个契约/状态对确定
AppCorDapp-合同
本CorDapp的目的是演示一个应用程序的示例,该应用程序使用LibCorDapp,创建和测试派生状态和契约
build.gradle
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name cordapp_contract_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
workflow {
name cordapp_workflow_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name "Test CorDapp Contract"
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
implementation "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
问候状态
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name cordapp_contract_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
workflow {
name cordapp_workflow_name
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
cordaCompile "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
cordapp {
targetPlatformVersion cordapp_platform_version
minimumPlatformVersion cordapp_platform_version
contract {
name "Test CorDapp Contract"
vendor cordapp_vendor_name
licence cordapp_license
versionId cordapp_version_id
}
signing {
enabled = cordapp_signing_enabled
}
}
dependencies {
implementation "$kotlin_group:kotlin-stdlib-jdk8:$kotlin_version"
implementation "$corda_group:corda-core:$corda_release_version"
cordapp project(":libcordapp-contract")
testRuntimeOnly "$junit_group:junit-jupiter-engine:$junit_version"
testImplementation "$junit_group:junit-jupiter-api:$junit_version"
testImplementation "$kotlin_group:kotlin-test:$kotlin_version"
testImplementation "$corda_group:corda-node-driver:$corda_release_version"
}
package com.example.appcordapp.contract
@BelongsToContract(GreetingContract::class)
类问候状态(
参与者:List=emptyList()
value:String=“你好,世界!”
):ExampleState(参与者、值)
问候合同
package com.example.appcordapp.contract
类迎宾合同:示例合同{
override fun onVerifyCreate(tx:LedgerTransaction,signers:Set)=requireThat{…}
}
请注意,GreetingContract
扩展了ExampleContract
和GreetingState
扩展了ExampleContract
,并将GreetingContract
定义为相关合同,因此在使用ExampleFlow
创建GreetingState
时,它应该选择此合同
实际上,AppCorDapp-Workflow模块中没有定义流,因为我明确希望测试我是否可以将ExampleFlow
与我的派生状态/契约对一起使用
测试与问题
对于我的测试,我定义了以下应用程序:
cordappsForAllNodes=listOf(
TestCordapp.findCordapp(“com.example.libcordapp.contract”),
TestCordapp.findCordapp(“com.example.libcordapp.workflow”),
TestCordapp.findCordapp(“com.example.appcordapp.contract”)
)
尝试使用ExampleFlow
创建GreetingClaim
时
ExampleFlow(欢迎索赔(参与者=listOf(partyA)))
…我得到以下异常:
java.lang.IllegalArgumentException:类路径[/…/libcordapp-contract-0.1.jar,/…/libcordapp-workflow-0.1.jar]上有多个包含包com.example.appcordapp.contract的CorDapp。指定CorDapp唯一的程序包名称
我假设这要么是因为gradle,要么是因为我使用的是派生状态和契约?阅读有关的官方文档,然后阅读;我建议您将
AppCorDapp-contract的build.gradle
内部cordapp项目(“:libcordapp-contract”)更改为cordaCompile项目(“:libcordapp-contract”)
在当前的依赖项设置(即使用cordapp
)中,libcordapp-contract
包含在cordapp的jar文件中,因此当您运行测试时,可以在两个位置找到包:libcordapp-contract
和AppCorDapp-contract
CorDapps;如果将依赖项更改为cordaCompile
,则该包将仅包含在LibCorDapp-Contract
CorDapp的jar文件中。阅读有关的官方文档,并阅读;我建议您将AppCorDapp-contract的build.gradle
内部cordapp项目(“:libcordapp-contract”)更改为cordaCompile项目(“:libcordapp-contract”)
在当前的依赖项设置(即使用cordapp
)中,libcordapp-contract
包含在cordapp的jar文件中,因此当您运行测试时,可以在两个位置找到包:libcordapp-contract
和AppCorDapp-contract
CorDapps;如果将依赖项更改为cordaCompile
,则该包将仅包含在LibCorDapp-Contract
CorDapp的jar文件中。遗憾的是,我得到了与cordaCompile
相同的结果:(如果