Corda:由于请求者尚未注册,所以拒绝会话请求

我有一个Corda应用程序,使用M14来构建和运行corda来运行TwoPartyProtocol,双方可以交换数据以达到数据有效性共识。 我遵循Corda流程食谱来建立一个流程。

此外,从几个不同的corda里程碑阅读文档后,我明白,M14不再需要发行说明中提到的flowSessions,这也消除了需要注册服务。

我的TwoPartyFlow内部FlowLogics:

class TwoPartyFlow{ @InitiatingFlow @StartableByRPC open class Requestor(val price: Long, val otherParty: Party) : FlowLogic<SignedTransaction>(){ @Suspendable override fun call(): SignedTransaction { val notary = serviceHub.networkMapCache.notaryNodes.single().notaryIdentity send(otherParty, price) /*Some code to generate SignedTransaction*/ } } @InitiatedBy(Requestor::class) open class Responder(val requestingParty : Party) : FlowLogic<SignedTransaction>(){ @Suspendable override fun call(): SignedTransaction { val request = receive<Long>(requestor).unwrap { price -> price } println(request) /*Some code to generate SignedTransaction*/ } } } 

但是,从Api运行上述使用startTrackedFlow导致上述错误:

 Party CN=Other,O=Other,L=NY,C=US rejected session request: com.testapp.flow.TwoPartyFlow$Requestor has not been registered 

由于双方流程在Corda的几个里程碑之间发生了变化,我很难从corda文档或日志中找到原因。 有人能帮我理解这里的问题。

我的API调用:

 @GET @Path("start-flow") fun requestOffering(@QueryParam(value = "price") price: String) : Response{ val price : Long = 10L /*Code to get otherParty details*/ val otherPartyHostAndPort = HostAndPort.fromString("localhost:10031") val client = CordaRPCClient(otherPartyHostAndPort) val services : CordaRPCOps = client.start("user1","test").proxy val otherParty: Party = services.nodeIdentity().legalIdentity val (status, message) = try { val flowHandle = services.startTrackedFlow(::Requestor, price, otherParty) val result = flowHandle.use { it.returnValue.getOrThrow() } // Return the response. Response.Status.CREATED to "Transaction id ${result.id} committed to ledger.\n" } catch (e: Exception) { Response.Status.BAD_REQUEST to e.message } return Response.status(status).entity(message).build() } 

我的Gradle的deployNodes任务:

 task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { directory "./build/nodes" networkMap "CN=Controller,O=R3,OU=corda,L=London,C=UK" node { name "CN=Controller,O=R3,OU=corda,L=London,C=UK" advertisedServices = ["corda.notary.validating"] p2pPort 10021 rpcPort 10022 cordapps = [] } node { name "CN=Subject,O=Subject,L=NY,C=US" advertisedServices = [] p2pPort 10027 rpcPort 10028 webPort 10029 cordapps = [] rpcUsers = [[ user: "user1", "password": "test", "permissions": []]] } node { name "CN=Other,O=Other,L=NY,C=US" advertisedServices = [] p2pPort 10030 rpcPort 10031 webPort 10032 cordapps = [] rpcUsers = [[ user: "user1", "password": "test", "permissions": []]] } 

您发布的代码似乎存在一些问题:

  • 注释应该是@StartableByRPC ,而不是@StartableNByRPC
  • 传递给startTrackedFlow的价格应该是很长的,而不是一个int

但是,即使解决了这些问题,我也无法复制你的错误。 你可以应用这些修补程序,干净地重新部署你的节点( gradlew clean deployNodes ),并查看错误是否更改?

您不应该通过RPC连接到另一个节点。 RPC是一个节点的所有者对节点的说话方式。 在现实世界中,您将不具有其他节点的RPC凭据,并且无法以此方式登录到节点。

相反,您应该使用自己的节点的RPC客户端来检索交易对手的身份:

val otherParty = services.partyFromX500Name("CN=Other,O=Other,L=NY,C=US")!!

在这里看到一个M14的例子: https : //github.com/corda/cordapp-example/blob/release-M14/kotlin-source/src/main/kotlin/com/example/api/ExampleApi.kt 。