Web3j client wrappers for Corda
Introduction
Client code generated by the web3j-corda command can be divided into the following blocks:
- CorDapps
- Flows
CorDapps block
A CorDapp client file is generated for each CorDapp in the path specified to the generate command. This block encapsulates the all information related to the particular CorDapp in an interface.
Example code is as follows:
/**
* CorDapp wrapper.
*/
@Path("/api/rest/cordapps/<name-of-cordapp-or-jar>/")
interface <name-of-cordapp> : CorDapp {
@get:Path("flows")
override val flows: FlowResource // Lists all the flows in a CorDapp
// Contains flow definition
/**
* <name-of-cordapp> CorDapp lifecycle methods.
*/
companion object : LifeCycle<name-of-cordapp> {
/**
* Loads an existing <name-of-cordapp> CorDapp instance.
*/
override fun load(service: CordaService) = ClientBuilder.build(<name-of-cordapp>::class.java, service, CordaException.Companion::of)
}
}
Flows blocks
Each individual CorDapp can have multiple flows which are listed in the CorDapp block. Each instance of flow can be used to start the flow, using underlying RPC calls.
A flow can be defined as mentioned below:
/**
* Get the <flow-name> flow.
*/
@get:Path("<flow-complete-path>")
val <flow-instance> : <flow-name>
/**
* <corDapp-name> <flow-name> flow.
*/
interface <flow-name> : Flow {
/**
* Start the <flow-name> flow.
*/
@POST
@Produces("application/json")
@Consumes("application/json")
fun start(payload: <flow-input-parameters>): <flow-output-parameters>
}