Skip to content

Instantly share code, notes, and snippets.

@lankydan lankydan/Messages.kt
Created Aug 12, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.