States Matching Logic Corda

56 views Asked by At

We need a logic for the following scenario:

Say for example, we have three parties, Party A, B and C. We have two states, state X and state Y. Party A, and Party B creates multiple X states, Party C can view all these states. At least two of these X states will have similar data. Party C should create state Y by finding and matching two similar X states.

Where should we apply this matching logic(API or Flow)? How to implement this scenario?

1

There are 1 answers

0
Joel On

It would be best to perform the matching in a flow, where you have access to the full VaultQuery API documented here: https://docs.corda.net/api-vault-query.html.

How you perform the match depends on what fields you're matching on, and how similar these fields are. Suppose, based on the CorDapp Example (https://github.com/corda/cordapp-example), that we wanted to match IOUStates whose value was 3. Then we could write:

val queryCriteria = QueryCriteria.VaultCustomQueryCriteria(
    IOUSchemaV1.PersistentIOU::value.equal(3)
)

serviceHub.vaultService.queryBy<IOUState>(queryCriteria)