Search in sources :

Example 1 with ResponseHeader

use of com.hederahashgraph.api.proto.java.ResponseHeader in project hedera-services by hashgraph.

the class QueryUtils method reflectForHeaderField.

private static Object reflectForHeaderField(Response response, String field) throws Throwable {
    String getterName = Arrays.stream(Response.class.getDeclaredMethods()).map(Method::getName).filter(name -> !"hashCode".equals(name) && name.startsWith("has")).filter(name -> {
        try {
            return (Boolean) Response.class.getMethod(name).invoke(response);
        } catch (Exception ignore) {
        }
        return false;
    }).map(name -> name.replace("has", "get")).findAny().get();
    Method getter = Response.class.getMethod(getterName);
    Class<?> getterClass = getter.getReturnType();
    Method headerMethod = getterClass.getMethod("getHeader");
    ResponseHeader header = (ResponseHeader) headerMethod.invoke(getter.invoke(response));
    Method fieldGetter = ResponseHeader.class.getMethod(asGetter(field));
    return fieldGetter.invoke(header);
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) ResponseHeader(com.hederahashgraph.api.proto.java.ResponseHeader) Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) QueryHeader(com.hederahashgraph.api.proto.java.QueryHeader) ANSWER_ONLY(com.hederahashgraph.api.proto.java.ResponseType.ANSWER_ONLY) Query(com.hederahashgraph.api.proto.java.Query) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Response(com.hederahashgraph.api.proto.java.Response) COST_ANSWER(com.hederahashgraph.api.proto.java.ResponseType.COST_ANSWER) PropertySource.asAccountString(com.hedera.services.bdd.spec.PropertySource.asAccountString) TransactionGetReceiptQuery(com.hederahashgraph.api.proto.java.TransactionGetReceiptQuery) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Method(java.lang.reflect.Method) ResponseHeader(com.hederahashgraph.api.proto.java.ResponseHeader) PropertySource.asAccountString(com.hedera.services.bdd.spec.PropertySource.asAccountString) Method(java.lang.reflect.Method)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 PropertySource.asAccountString (com.hedera.services.bdd.spec.PropertySource.asAccountString)1 Query (com.hederahashgraph.api.proto.java.Query)1 QueryHeader (com.hederahashgraph.api.proto.java.QueryHeader)1 Response (com.hederahashgraph.api.proto.java.Response)1 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)1 ResponseHeader (com.hederahashgraph.api.proto.java.ResponseHeader)1 ANSWER_ONLY (com.hederahashgraph.api.proto.java.ResponseType.ANSWER_ONLY)1 COST_ANSWER (com.hederahashgraph.api.proto.java.ResponseType.COST_ANSWER)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1 TransactionGetReceiptQuery (com.hederahashgraph.api.proto.java.TransactionGetReceiptQuery)1 TransactionID (com.hederahashgraph.api.proto.java.TransactionID)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1