Search code examples
rpccorda

Do we really need to import Corda's code for RPC ? How in the future?


I know that Corda is in the process of removing its web server module and in the documentation they suggest the use of other frameworks.

In one example ("spring-observable-stream") they use Spring Boot for the server-side APIs and use an RPC call to the actual running Corda node. That's fine and comparable with what I have to do.

In that example, the author import the specific Corda's RPC code, along with the code of the actual flow (and states) needed.

What I want to ask here is if it's possible to avoid that tangle and keep the web server APIs independent from the actual Corda/CordApp's code by using a general RPC library (any advice ?).

If, instead, I must import the Corda-specific code (there is a reason ?), I'd like to ask you:

  1. What is the minimum necessary to do so from a Gradle perspective ?
  2. Is it possible to implement some sort of plugin on the CordApp to reduce that tangle ?

To be honest, I'm interested in a more general way for interacting with the CordApp (e.g. from Python), but I know that due to the AMQP integration not yet ready, we have to stay on the JVM for now. So, feel free to answer just about what we need to do as of today from Kotlin (which I have to use for a short-term PoC)…

Thank you in advance!


Solution

  • Currently, your server has to depend on the Corda RPC library to interact with nodes via RPC. Corda doesn't yet expose an independent format for sending and receiving messages via RPC.

    Your server also needs to depend on any CorDapps that contain flows that the server will start via RPC, or that contain types that will be returned via RPC. Otherwise, your server will not be able to start the flows or deserialise the returned types.

    If you're using Gradle, here's what a minimal dependencies block might look like:

    dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    
        cordaCompile "net.corda:corda-rpc:$corda_release_version"
    
        compile "com.github.corda:cordapp-example:release-V1-SNAPSHOT"
    }
    

    Here, we're depending on the corda-rpc library, and also using JitPack to depend on the CorDapp where we define the flows and states that we want to start/return via RPC.

    If you want, you can modularise the CorDapp so that all the classes you need to depend on for RPC are included in a separate module, and only depend on that module.