我是Corda的新手。当直接调用CashPaymentFlow中的接收节点时,是否有直接的方式将另一方的子流作为一个子流返回给一定数量的现金的发送方,例如,像这样的东西:
recipient.run {
subFlow(CashPaymentFlow(amount, sender ,anonymous))
}
(这不起作用,这只是一个例子)。我需要一个更加动态的解决方案,在demobench中使用它。从demobench UI中选择用于初始支付的接收节点。问题是当从发送方执行初始支付时,自动呼叫或引用另一方的节点并要求其执行还款(通过使用例如cashPaymentFlow)。我现在可以手动“转”到接收者节点并通过UI或终端向发送者执行付款,但这不是意图。
答案 0 :(得分:1)
您可以通过将还款部分与初始付款相同的流程实现此目的,如下所示:
@InitiatingFlow
@StartableByRPC
class Payer(val initialAmount: Amount<Currency>, val changeAmount: Amount<Currency>, val recipient: Party) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(CashPaymentFlow(initialAmount, recipient))
val sessionWithRecipient = initiateFlow(recipient)
sessionWithRecipient.send(changeAmount)
}
}
@InitiatedBy(Payer::class)
class Recipient(val payerSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val changeAmount = payerSession.receive<Amount<Currency>>().unwrap { it }
subFlow(CashPaymentFlow(changeAmount, payerSession.counterparty))
}
}
答案 1 :(得分:0)
我想传递另一个变量和'changeAmount'。这可能吗?我试着这样做:
@InitiatingFlow
@StartableByRPC
class Payer(val initialAmount: Amount<Currency>, val changeAmount:Amount<Currency>, val recipient: Party) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(CashPaymentFlow(initialAmount, recipient))
val sessionWithRecipient = initiateFlow(recipient)
sessionWithRecipient.send(changeAmount)
sessionWithRecipient.send(delay) //second variable
}
}
@InitiatedBy(Payer::class)
class Recipient(val payerSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val changeAmount = payerSession.receive<Amount<Currency>>().unwrap { it }
val delay = payerSession.receive<Duration>().unwrap { it }
for (i in 1..10) //the 10 automated paybacks
{subFlow(CashPaymentFlow(changeAmount, payerSession.counterparty))
sleep(delay)} //usage of the second variable
}
}