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);
}
Aggregations