调用BroadcastTransaction时会引发以下错误:
Party C=GB,L=London,O=Controller rejected session request:
class ee.ut.cs.examples.parking.flows.BroadcastTransaction is not registered
这是我的FlowLogic想要调用BroadcastTransaction
package ee.ut.cs.examples.parking.flows
import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.Command
import net.corda.core.contracts.StateAndContract
import net.corda.core.flows.FinalityFlow
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.Party
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import ee.ut.cs.examples.parking.contracts.ParkingSpaceContract
import ee.ut.cs.examples.parking.structures.ParkingSpace
@StartableByRPC
class CreateParkingSpace(private val dayRate: Double, private val nightRate: Double) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary: Party = serviceHub.networkMapCache.notaryIdentities.first()
val parkingSpace = ParkingSpace(owner = ourIdentity, dayRate = dayRate, nightRate = nightRate)
val createCommand = Command(ParkingSpaceContract.Commands.Create(), listOf(ourIdentity.owningKey))
val outputState = StateAndContract(parkingSpace, ParkingSpaceContract.CONTRACT_REF)
val utx = TransactionBuilder(notary = notary).withItems(outputState, createCommand)
val stx = serviceHub.signInitialTransaction(utx)
val ftx = subFlow(FinalityFlow(stx))
subFlow(BroadcastTransaction(ftx))
return ftx
}
}
这是BroadcastTransaction:
import co.paralleluniverse.fibers.Suspendable
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.InitiatingFlow
import net.corda.core.flows.SendTransactionFlow
import net.corda.core.transactions.SignedTransaction
/**
* Filters out any notary identities and removes our identity, then broadcasts the [SignedTransaction] to all the
* remaining identities.
*/
@InitiatingFlow
class BroadcastTransaction(val stx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// Get a list of all identities from the network map cache.
val everyone = serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentities }
// Filter out the notary identities and remove our identity.
val everyoneButMeAndNotary = everyone.filter { serviceHub.networkMapCache.isNotary(it).not() } - ourIdentity
// Create a session for each remaining party.
val sessions = everyoneButMeAndNotary.map { initiateFlow(it) }
// Send the transaction to all the remaining parties.
sessions.forEach { subFlow(SendTransactionFlow(it, stx)) }
}
}
答案 0 :(得分:1)
这是SessionRejectException
。
这是因为从BroadcastTransaction
接收消息的节点没有注册响应BroadcastTransaction
的流。
您需要在表单的接收节点上安装响应者流:
@InitiatedBy(BroadcastTransaction::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// TODO: Flow logic here.
}
}