首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >( net.corda.core.contracts.WhitelistedByZoneAttachmentConstraint@1f102389 Corda4.8)选定的输出约束:R3不满足

( net.corda.core.contracts.WhitelistedByZoneAttachmentConstraint@1f102389 Corda4.8)选定的输出约束:R3不满足
EN

Stack Overflow用户
提问于 2022-01-11 13:22:38
回答 1查看 96关注 0票数 0

我克隆了cordapp-kotlin-模板。我定义了一个名为LoadState的状态,如下所示:

代码语言:javascript
运行
复制
@BelongsToContract(LoadContract::class)
data class LoadState(
    val loadId: String,
    val transporterName: String? = null,
    val vehicleModel: String? = null,
    val regLicenseNo: String? = null,
    val totalWeight: Int? = null,
    val notes: String? = null,
    val suppliers: MutableList<SupplierDetailsModel> = mutableListOf(),
    val recycler: Party,
    override val participants: List<AbstractParty> = listOf(recycler)
) : QueryableState {
    override fun generateMappedObject(schema: MappedSchema): PersistentState {
        if (schema is LoadSchemaV1) {
            return PersistentLoadState(this.loadId)
        } else {
            throw IllegalArgumentException("Unsupported Schema.")
        }
    }

    override fun supportedSchemas(): Iterable<MappedSchema> {
        return listOf(LoadSchemaV1())
    }
}

当我第一次使用这个应用程序并发布一个LoadState,比如LO123时,它工作得很好。国家也被发布并记录在保险库中。这就是我的LoadState问题流的样子:

代码语言:javascript
运行
复制
@Suspendable
    override fun call(): SignedTransaction {
        val notary = serviceHub.networkMapCache.getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"))
        progressTracker.currentStep = TX_COMPONENTS

        val recyclerName = CordaX500Name(
            organisation = "MyRecycler",
            locality = "Mumbai",
            country = "IN"
        )

        val recycler = serviceHub.identityService.wellKnownPartyFromX500Name(recyclerName)
            ?: throw IllegalArgumentException("Could not find party Recycler.")

        val outputState = LoadState(
            loadId = req.loadId,
            loadDate = req.loadDate,
            transporterName = req.transporterName,
            vehicleModel = req.vehicleModel,
            regLicenseNo = req.regLicenseNo,
            totalWeight = req.totalWeight,
            assets = req.assets,
            suppliers = req.suppliers,
            recycler = recycler,
            notes = req.notes
        )

        val command = Command(LoadContract.Commands.Create(), listOf(ourIdentity.owningKey))

        progressTracker.currentStep = TX_BUILDING

        val txBuilder = TransactionBuilder(notary = notary)
            .addOutputState(outputState, LoadContract.ID)
            .addCommand(command)

        // signing the transaction
        progressTracker.currentStep = TX_SIGNING
        val signedTx = serviceHub.signInitialTransaction(txBuilder)

        // verifying the transaction
        progressTracker.currentStep = TX_VERIFICATION
        txBuilder.verify(serviceHub)

        // We finalise the transaction and then send it to the counterparty.
        progressTracker.currentStep = FINALIZATION

        val recyclerSession = initiateFlow(recycler)

        return subFlow(FinalityFlow(signedTx, listOf()))
    }

现在需要在我们的LoadState中添加一个新字段:

val myNewField: String?= null

在将这个新字段添加到LoadState之后,我将运行deployNodes命令。生成生成文件夹后,我将Node/cordapp文件夹的内容复制到旧的build /cordapp文件夹中。

现在,在启动节点时,我正在运行迁移命令(核心模式和应用模式)。一旦迁移过程完成,节点运行完毕,我将调用一个api端点,该端点调用一个以L0123作为输入的流,复制它,并修改一些参数并创建一个新的LoadState类型的输出状态。在我的txBuilder.verify(serviceHub)中,错误抛给: UpdateLoadFlow。我的更新流程是这样的:

代码语言:javascript
运行
复制
@Suspendable
    override fun call(): SignedTransaction {
        val notary = serviceHub.networkMapCache.getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"))

        progressTracker.currentStep = TX_COMPONENTS

        val recyclerName = CordaX500Name(
            organisation = "MyRecycler",
            locality = "Mumbai",
            country = "IN"
        )

        val recycler = serviceHub.identityService.wellKnownPartyFromX500Name(recyclerName)
            ?: throw IllegalArgumentException("Could not find party Recycler.")

        val inputState = QueryVault().queryLoadById(req.loadId, Vault.StateStatus.UNCONSUMED, serviceHub.vaultService)
            ?: throw Exception("Load ${req.loadId} not found.")

        val vaultData = inputState.state.data
        var outputState = vaultData.copy(myNewField = "some new value");
        
        val command = Command(LoadContract.Commands.Update(), listOf(ourIdentity.owningKey))

        progressTracker.currentStep = TX_BUILDING

        val txBuilder = TransactionBuilder(notary = notary)
            .addInputState(inputState)
            .addOutputState(outputState, LoadContract.ID)
            .addCommand(command)

        txBuilder.verify(serviceHub)
        // signing the transaction
        progressTracker.currentStep = TX_SIGNING
        val signedTx = serviceHub.signInitialTransaction(txBuilder)
        // verifying the transaction
        progressTracker.currentStep = TX_VERIFICATION

        // We finalise the transaction and then send it to the counterparty.
        progressTracker.currentStep = FINALIZATION
        val recyclerSession = initiateFlow(recycler)
        return subFlow(FinalityFlow(signedTx, listOf()))
    }

请帮我解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-24 04:23:25

经过我们在上述评论部分的讨论,您的州似乎已经使用白名单区域约束发布了。

此外,查看代码,很明显您还没有显式地为您的州添加白名单区域约束。然后,还有两种使用白名单区域约束来发出状态的可能性。

其中之一是您在4之前使用了一些Corda版本,或者您已经包含了必要的信任,以便在网络引导程序中作为指定的这里包含白列表区域约束。您有两种选择--要么从头开始,然后确保使用Corda 4。

如果您不能从头开始,那么在运行UpdateLoadFlow之前,按照此路径首先将白名单区域约束迁移到签名约束。您可以参考有关约束迁移的博客。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70667564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档