'States Matching Logic Corda

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?



Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joel