【发布时间】:2020-05-04 13:45:16
【问题描述】:
所以我想在 Corda 中查询 3 个状态,但我只会从用户那里得到一个查询条件。所以我将从查询条件中查询第一个状态,现在我将从第一个状态结果中查询具有特定值的第二个状态,最后我将从第二个状态的特定结果中查询第三个状态。 最后,我将获得第三个状态的特定值
所以任何人都可以解释我如何做到这一点。我已经尝试过了,但它返回空值 这是我的代码
@GetMapping("PledgeData")
public APIResponse<List<String>> getPledgeData(@RequestParam("pledgeIdFromUser") String pledgeIdFromUser){
//from the user i have taken the PledgeId and using it as a query criteria
try {
FieldInfo pledgeId1 = null;
try {
pledgeId1 = getField("pledgeId", PledgeSchema.PersistentPledge.class);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
QueryCriteria allDataRelatedToPledgeIdInPledgeState = new QueryCriteria.VaultCustomQueryCriteria
(Builder.equal(pledgeId1, pledgeIdFromUser));
List<StateAndRef<PledgeState>> results1 = activeParty.vaultQueryByCriteria
( allDataRelatedToPledgeIdInPledgeState, PledgeState.class).getStates();
// so i have retrieved all the branchId from PledgeState using pledge id
List<String> allBranchIds =results1.stream().map(stateStateAndRef -> stateStateAndRef.getState().getData().getBranchId()).collect(Collectors.toList());
// now i want to iterate all the branchID to find the winner in PledgeUpdateState
//so here my input will be branchID
List<String> allWinner = null;
for(String allBranchId:allBranchIds ){
FieldInfo branchId = null;
try {
branchId = getField("branchId", PledgeResultSchema.PersistentPledge1.class);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
QueryCriteria allDataRelatedToPledgeIdInPledgeUpdateState = new
QueryCriteria.VaultCustomQueryCriteria(Builder.equal(branchId, allBranchId));
List<StateAndRef<PledgeUpdateState>> results2 = activeParty.vaultQueryByCriteria
( allDataRelatedToPledgeIdInPledgeUpdateState, PledgeUpdateState.class).getStates();
allWinner = results2.stream().map(stateStateAndRef -> stateStateAndRef.getState().getData()
.getWinner()).collect(Collectors.toList());
}
// now here i want to return all the winner in the PledgeUpdateState
return APIResponse.success(allWinner);
}catch (Exception e){
return APIResponse.error(e.getMessage());
}
}```
【问题讨论】:
标签: blockchain corda