Corda:Party拒绝了会话请求,因为请求者尚未注册

时间:2017-10-18 21:35:02

标签: kotlin corda

我有一个Corda应用程序,使用M14构建和运行corda来运行TwoPartyProtocol,其中任何一方可以交换数据以达成数据有效性共识。我跟着Corda flow cookbook建立了一个流程。

此外,在阅读了几个不同的corda里程碑的文档后,我已经明白M14不再需要release notes中提到的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()
}

My 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": []]]
}

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

您不应该通过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