现金合约CashIssueFlow仅启用selfIssueCash的特定方

时间:2017-12-04 06:57:11

标签: corda

我正在测试corda的内置CashIssueFlow,其中网络中的参与者可以向自己发放现金。我的问题是如何在合同层面强制执行此操作,只允许特定方自行发放现金,以便节点中的其他参与者无法自我解决?

1 个答案:

答案 0 :(得分:0)

理论上,您可以编写自己的Cash合同,以防止除特定方之外的任何人发放现金:

override fun verify(tx: LedgerTransaction) {
    requireThat {
        val allStates = tx.outputsOfType<Cash.State>() + tx.inputsOfType<Cash.State>()
        "Only DUMMY CASH ISSUER can issue cash" using (allStates.all { it.amount.token.issuer == DUMMY_CASH_ISSUER })
    }
}

但是,不同节点可能希望接受来自不同发行人的现金。一个节点可能只想接受来自银行A,B和C的现金,而另一个节点可能只想接受来自银行X,Y和Z的现金。

您可以通过修改每个节点上安装的流逻辑来实现此目的,以便拒绝涉及特定受信任银行未发行的现金的交易:

@InitiatedBy(Initiator::class)
class Acceptor(val otherPartyFlow: FlowSession) : FlowLogic<SignedTransaction>() {
    @Suspendable
    override fun call(): SignedTransaction {
        val signedTx = otherPartyFlow.receive<SignedTransaction>().unwrap { tx ->
            // TODO: Checking of received transaction.
            tx
        }

        val ledgerTx = signedTx.toLedgerTransaction(serviceHub, false)
        val states = ledgerTx.inputsOfType<Cash.State>() + ledgerTx.outputsOfType<Cash.State>()

        if (!states.all { it.amount.token.issuer == DUMMY_CASH_ISSUER }) {
            throw FlowException("Cash not issued by trusted party.")
        }

        ...
    }
}