I want to create State with unique id in database. There is my State code
data class SampleState(
val partyA: Party,
val partyB: Party,
val value: Int,
val id: String,
override val linearId: UniqueIdentifier = UniqueIdentifier(id),
val properties: LCProperties = LCProperties("ABC")) : LinearState {...}
When I commit two similar SampleState, there are two different State in database with two different linearId. So, There are anyone can talk me that how to ensure that the "id" of a object of SampleState in database is unique? I used same code for catch this case in Flows and Contracts like
val results = builder {
val quantityIndex = SampleSchemaV1.PersistentSample::id.equal(id);
val customCriteria1 = QueryCriteria.VaultCustomQueryCriteria(quantityIndex)
val criteria = generalCriteria.and(customCriteria1);
serviceHub.vaultService.queryBy<SampleState>(criteria)
}
if(results.states.count() > 0)
throw IllegalArgumentException("id $id is exist")
However, it do not work with two commit Sample State Transaction in a near similar time even that in 1s (commit Transaction 1, and after 1 second, commit Transaction 2)