serviceHub.vaultQueryService.queryBy returns all related states by default?

时光怂恿深爱的人放手 提交于 2021-01-28 02:27:51

问题


When I tried to use below codes to retrieve the state by linearId, I got 2 records returned, one is the consumed one, the other is the unconsumed one. The initial linearId was passed in from web api.

val linearId: UniqueIdentifier = UniqueIdentifier(null, UUID.fromString(legalContractState.legalContract.linearId))
val linearIds = listOf(linearId)
val linearStateCriteria = QueryCriteria.LinearStateQueryCriteria(linearId = listOf(linearIds.first(), linearIds.last()))
val states = serviceHub.vaultQueryService.queryBy(LegalContractState::class.java, linearStateCriteria).states
val inputState: StateAndRef<LegalContractState> = serviceHub.vaultQueryService.queryBy(LegalContractState::class.java, linearStateCriteria).states.single()

But from a sample code on the vault api page, it says this will return an unconsumed state based on a linearId, I also checked the data in H2 database VAULT_STATES table, there are 2 records, one has a CONSUMED_TIMESTAMP and its STATE_STATUS is 1, but the other one CONSUMED_TIMESTAMP IS null and STATE_STATUS is 0. This is one unshared state which means only stored in my database, and I executed one update for it, so ideally have one consumed state and one new output state in db. So now I am not sure what's wrong here.

Query for unconsumed linear states for given linear ids:

val linearIds = issuedStates.states.map { it.state.data.linearId }.toList()
val criteria = LinearStateQueryCriteria(linearId = listOf(linearIds.first(), linearIds.last()))
val results = vaultQuerySvc.queryBy<LinearState>(criteria)

回答1:


This is a bug that will be fixed in release M14. See https://github.com/corda/corda/issues/949.



来源:https://stackoverflow.com/questions/45144809/servicehub-vaultqueryservice-queryby-returns-all-related-states-by-default

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!