Vaultaire: Corda Vault Queries Made Simple

Upgrade to a clean and easy to use query DSL generated just for you.

Manos Batsis
2 min readOct 21, 2019
Sample Vaultaire DSL Query

Feeling Lucky

If you are in a hurry and want to quickly try Vaultaire with your project skip ahead to “Testing the Solution”, otherwise read on.

Admitting the Problem

A few months ago, I was looking for a bug in a Corda vault query. The code had grown over time to support more criteria and was increasingly difficult to maintain.
The same problem was spreading throughout the code-base for some time and no easy solution was readily available. I was wasting too much time trying to read my own code instead of dealing with the issue.
If you don’t know what I’m talking about, Corda ’s Query DSL is rather easy to use but a bit verbose:

Simple but verbose query using Corda’s Query DSL

Setting the Objectives

In short, Vaultaire’s DSL APIs were designed with the following requirements:

  • Utilize the standard Corda APIs for interoperability
  • Provide a compact syntax for readability
  • Maintain type safety and require minimal configuration for ease of use

Testing the Solution

Here’s how to quickly setup your project build to automatically generate and maintain a query DSL specific to your Corda States.

Adding Dependencies

Update your Cordapp’s Gradle dependencies:

Vaultaire dependencies for your Cordapp

Optional: The core module can also be useful outside a cordapp, e.g. in a Spring app querying a Corda node vault via RPC:

Vaultaire dependencies for non-Cordapps

Creating a DSL

To create a query DSL for your state, simply annotate the corresponding schema’s PersistentState subclass with @VaultaireGenerate:

Annotating persistent states

Vaultaire’s annotation processor will pick that up and automatically generate and maintain a DSL for you at e.g. projectname/build/generated/source/kaptKotlin/main/example/BookStateVaultaireGenerated.kt

Querying the Vault

Start with converting a simple query like the example at the top of this post:

Simple query using Vaultaire-generated Query DSL

Getting Back to Work

Well, that’s it. There’s more to Vaultaire’s features, including aggregate queries with the DSL and generation of DAO-style state services that are not covered in this article, see the github project for details and support.

--

--