在Corda中回溯OwnableState [英] Back tracking OwnableState in Corda

查看:65
本文介绍了在Corda中回溯OwnableState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Corda文档时,我在以下链接中遇到了以下片段.

While going through Corda docs, I came across the below snippet at this link.

默认保管库实现基于以下规则做出决定:

The default vault implementation makes the decision based on the following rules:

如果状态是 OwnableState ,则当节点是状态的所有者时,保管库将存储状态.否则,如果是参与者之一,则保管库将存储状态

If the state is an OwnableState, the vault will store the state if the node is the state’s owner Otherwise, the vault will store the state if it is one of the participants

在我的流程中,

  1. 我正在使用实现OwnableState的状态类将现金从节点A发行/发送到节点B.
  2. 我将节点B设置为所有者.
  3. 我用节点A和节点B都填充了参与者字段.

我可以在节点B 中看到新状态,而在节点A 中则看不到.我尝试通过添加条件为 status = vault.StateStatus.ALL .来在终端上查询状态(仅显示未消耗状态),并使用Vault查询API.

I am able to see the new state in Node B but not in Node A. I tried to query the states on terminal (where it only shows unconsumed states) as well as using vault query API by adding criteria as status = vault.StateStatus.ALL.

这是否意味着我永远做不到

Does this mean, I would never be able

  • 跟踪现金来自节点B的位置?
  • 要跟踪节点A中的现金流向何处?

代码示例如下:州级:

package com.shailesh

import net.corda.core.contracts.CommandAndState
import net.corda.core.contracts.OwnableState
import net.corda.core.identity.AbstractParty
import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState
import net.corda.core.serialization.CordaSerializable
import net.corda.finance.contracts.asset.Cash

@CordaSerializable
data class MyPersistentState(val amount: Int, val sender : AbstractParty, val receiver : AbstractParty) : OwnableState {

    override val owner: AbstractParty
        get() = receiver

    override val participants: List<AbstractParty> = listOf(sender, receiver)
}

流分类:

package com.shailesh

import co.paralleluniverse.fibers.Suspendable
import com.shailesh.PersistenceDemoContract.Companion.id
import net.corda.core.contracts.Contract
import net.corda.core.flows.FinalityFlow
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.InitiatingFlow
import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.Party
import net.corda.core.node.services.Vault
import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.ProgressTracker
import net.corda.finance.DOLLARS
import net.corda.finance.contracts.asset.CASH
import net.corda.finance.contracts.asset.Cash

@InitiatingFlow
@StartableByRPC
class PersistenceDemoFlow(val amount: Int, val receiver : Party) : FlowLogic<Unit>() {

    override val progressTracker: ProgressTracker = ProgressTracker()

    @Suspendable
    override fun call() {
        val notary = serviceHub.networkMapCache.notaryIdentities.first()

        val qc = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.ALL)

        // I expect that result should show me the states in Node A when A issues state to B
        val result: Vault.Page<MyPersistentState> = serviceHub.vaultService.queryBy(contractStateType = MyPersistentState::class.java, criteria = qc)

        val outputState = MyPersistentState(amount, ourIdentity, receiver)
        val tx = TransactionBuilder(notary).addOutputState(outputState, id).addCommand(Cash.Commands.Issue(), listOf(ourIdentity.owningKey))
        tx.verify(serviceHub)
        val signedTx = serviceHub.signInitialTransaction(tx)
        subFlow(FinalityFlow(signedTx))
    }
}

@CordaSerializable
class PersistenceDemoContract: Contract {
    companion object {
        val id = "com.shailesh.PersistenceDemoContract"
    }
    override fun verify(tx: LedgerTransaction) {

    }
}

查询和发布状态的命令:

Commands to query and issue states:

// Check states
run vaultQuery contractStateType: com.shailesh.MyPersistentState
// Start the issue flow on Node A
flow start com.shailesh.PersistenceDemoFlow amount: 100, receiver: "O=PartyB,L=New York,C=US"

推荐答案

在对Adrian的回答进行扩展时,原始问题询问对于 OwnableState :

Expanding on Adrian's answer, the original question asks whether, for an OwnableState:

我永远做不到

跟踪现金来自节点B的位置?

to track from where the cash came in Node B ?

以跟踪节点A中的现金流向何处?

to track to where the cash in Node A goes ?

此外,在评论中,询问参与者字段对于 OwnableState 的重要性是什么.

Additionally, in the comments, it is asked what is the importance of the participants field for an OwnableState.

参与者字段的重要性在于,所有参与者都将接收并记录交易副本,并创建新状态作为 FinalityFlow 的一部分.代码>.正是这种交易,而不是国家本身,才允许随着时间的流逝建立一系列现金流动.

The importance of the participants field is that all the participants will receive and record a copy of the transaction creating the new state as part of FinalityFlow. It is this transaction, and not the state itself, that allows a chain of cash movements to be established over time.

在Corda中,区分谁记录交易(所有参与者)和谁记录状态(所有者 OwnableState )很重要.代码>,否则所有参与者).

It is important in Corda to distinguish between who records a transaction (all the participants) and who records a state (the owner for an OwnableState, and otherwise all the participants).

这篇关于在Corda中回溯OwnableState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆