Hari Prasath
Hari Prasath

Reputation: 31

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?

Upvotes: 0

Views: 47

Answers (1)

Joel
Joel

Reputation: 23210

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)

Upvotes: 0

Related Questions