我克隆了cordapp-kotlin-模板。我定义了一个名为LoadState的状态,如下所示:
@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问题流的样子:
@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。我的更新流程是这样的:
@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()))
    }请帮我解决这个问题。
发布于 2022-01-24 04:23:25
https://stackoverflow.com/questions/70667564
复制相似问题