现金合同 CashIssueFlow 仅允许特定方使用 selfIssueCash
Cash contract CashIssueFlow to enable only specific party to selfIssueCash
我正在测试 corda 的内置 CashIssueFlow
,网络中的参与者可以在其中向自己发行现金。我的问题是我如何在合同层面上执行此操作以仅允许特定方自行发行现金,这样节点中的其他参与者将无法 selfIssueCash?
理论上,您可以编写自己的 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.")
}
...
}
}
我正在测试 corda 的内置 CashIssueFlow
,网络中的参与者可以在其中向自己发行现金。我的问题是我如何在合同层面上执行此操作以仅允许特定方自行发行现金,这样节点中的其他参与者将无法 selfIssueCash?
理论上,您可以编写自己的 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.")
}
...
}
}