corda实现通用金库查询

问题描述 投票:0回答:1

试图创建这个通用的金库查询方法。

        <T extends ContractState> List<StateAndRef<T>> getStatesByLinearId(T stateType, Class<T> cl, String linearId) {
        List<UniqueIdentifier> linearIds = singletonList(UniqueIdentifier.Companion.fromString(linearId));
        QueryCriteria linearCriteriaAll = new QueryCriteria.LinearStateQueryCriteria(null, linearIds, Vault.StateStatus.UNCONSUMED, null);

        return getServiceHub().getVaultService().queryBy(cl, linearCriteriaAll).getStates();
    }

我不知道如何获取Class的值。例如,我不知道如何调用这个方法:getStatesByLinearId(IouState.class,?,linearId)

java generics corda
1个回答
0
投票

这有帮助吗?

IouState state; // Assuming IouState extends or implements ContractState

getStatesByLinearId(state, state.getClass(), linearId);
// or, if you know the class beforehand
getStatesByLinearId(state, IouState.class, linearId);
© www.soinside.com 2019 - 2024. All rights reserved.