Reputation: 99
I have a corda state say Employee and I need to generate the Employee Id. Anyone please let me know how to generate this through corda oracle services?
Upvotes: 1
Views: 119
Reputation: 23140
The Oracle could have an atomic counter that is incremented each time an employee ID is allocated.
Where should you put this counter?
You could define the service as follows:
@CordaService
class Oracle(val services: ServiceHub) : SingletonSerializeAsToken() {
private val counter = AtomicInteger(0)
val employeeId
get() = counter.getAndIncrement()
}
And you would retrieve the employee ID in a flow using:
serviceHub.cordaService(Oracle::class.java).employeeId
Upvotes: 1