Skip to content

Instantly share code, notes, and snippets.

@lankydan
Created August 12, 2019 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lankydan/bb5fff5e4119164a8f84b41901b4a65c to your computer and use it in GitHub Desktop.
Save lankydan/bb5fff5e4119164a8f84b41901b4a65c to your computer and use it in GitHub Desktop.
Corda + Ktor - endpoints
fun Routing.messages(proxy: CordaRPCOps) {
route("/messages") {
get("/") {
call.respond(
HttpStatusCode.OK,
proxy.vaultQueryBy<MessageState>().states.map { it.state.data })
}
post("/") {
val received = call.receive<Message>()
try {
val message = proxy.startFlow(
::SendMessageFlow,
state(proxy, received, UUID.randomUUID())
).returnValue.getOrThrow().coreTransaction.outputStates.first() as MessageState
call.respond(HttpStatusCode.Created, message)
} catch (e: Exception) {
call.respond(HttpStatusCode.InternalServerError, e.message ?: "Something went wrong")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment