use of com.hederahashgraph.api.proto.java.ResponseType in project hedera-services by hashgraph.
the class GetAccountInfoAnswer method responseGiven.
@Override
public Response responseGiven(final Query query, final StateView view, final ResponseCodeEnum validity, final long cost) {
final CryptoGetInfoQuery op = query.getCryptoGetInfo();
CryptoGetInfoResponse.Builder response = CryptoGetInfoResponse.newBuilder();
final ResponseType type = op.getHeader().getResponseType();
if (validity != OK) {
response.setHeader(header(validity, type, cost));
} else {
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(OK, cost));
} else {
AccountID id = op.getAccountID();
var optionalInfo = view.infoForAccount(id, aliasManager);
if (optionalInfo.isPresent()) {
response.setHeader(answerOnlyHeader(OK));
response.setAccountInfo(optionalInfo.get());
} else {
response.setHeader(answerOnlyHeader(FAIL_INVALID));
}
}
}
return Response.newBuilder().setCryptoGetInfo(response).build();
}
use of com.hederahashgraph.api.proto.java.ResponseType in project hedera-services by hashgraph.
the class GetFileContentsAnswer method responseGiven.
@Override
public Response responseGiven(Query query, StateView view, ResponseCodeEnum validity, long cost) {
var op = query.getFileGetContents();
var target = op.getFileID();
FileGetContentsResponse.Builder response = FileGetContentsResponse.newBuilder();
ResponseType type = op.getHeader().getResponseType();
if (validity != OK) {
response.setHeader(header(validity, type, cost));
response.setFileContents(from(target, Optional.empty()));
} else {
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(OK, cost));
response.setFileContents(from(target, Optional.empty()));
} else {
/* Include cost here to satisfy legacy regression tests. */
response.setHeader(answerOnlyHeader(OK, cost));
response.setFileContents(from(target, view.contentsOf(target)));
}
}
return Response.newBuilder().setFileGetContents(response).build();
}
use of com.hederahashgraph.api.proto.java.ResponseType in project hedera-services by hashgraph.
the class GetTopicInfoAnswer method responseGiven.
@Override
public Response responseGiven(Query query, StateView view, ResponseCodeEnum validity, long cost) {
ConsensusGetTopicInfoQuery op = query.getConsensusGetTopicInfo();
ConsensusGetTopicInfoResponse.Builder response = ConsensusGetTopicInfoResponse.newBuilder();
response.setTopicID(op.getTopicID());
ResponseType type = op.getHeader().getResponseType();
if (validity != OK) {
response.setHeader(header(validity, type, cost));
} else {
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(OK, cost));
} else {
var optionalInfo = view.infoForTopic(op.getTopicID());
if (optionalInfo.isPresent()) {
response.setHeader(answerOnlyHeader(OK));
response.setTopicInfo(optionalInfo.get());
} else {
response.setHeader(answerOnlyHeader(INVALID_TOPIC_ID));
}
}
}
return Response.newBuilder().setConsensusGetTopicInfo(response).build();
}
use of com.hederahashgraph.api.proto.java.ResponseType in project hedera-services by hashgraph.
the class GetFileInfoAnswer method responseGiven.
@Override
public Response responseGiven(Query query, StateView view, ResponseCodeEnum validity, long cost) {
var op = query.getFileGetInfo();
FileGetInfoResponse.Builder response = FileGetInfoResponse.newBuilder();
ResponseType type = op.getHeader().getResponseType();
if (validity != OK) {
log.debug("FileGetInfo not successful for: validity {}, query {} ", validity, query.getFileGetInfo());
response.setHeader(header(validity, type, cost));
} else {
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(OK, cost));
} else {
var info = view.infoForFile(op.getFileID());
/* Include cost here to satisfy legacy regression tests. */
if (info.isPresent()) {
response.setHeader(answerOnlyHeader(OK, cost));
response.setFileInfo(info.get());
} else {
response.setHeader(answerOnlyHeader(FAIL_INVALID));
}
}
}
return Response.newBuilder().setFileGetInfo(response).build();
}
use of com.hederahashgraph.api.proto.java.ResponseType in project hedera-services by hashgraph.
the class GetFastTxnRecordAnswer method responseGiven.
@Override
public Response responseGiven(Query query, StateView view, ResponseCodeEnum validity, long cost) {
TransactionGetFastRecordQuery op = query.getTransactionGetFastRecord();
ResponseType type = op.getHeader().getResponseType();
TransactionGetFastRecordResponse.Builder response = TransactionGetFastRecordResponse.newBuilder();
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(NOT_SUPPORTED, 0L));
} else {
response.setHeader(answerOnlyHeader(NOT_SUPPORTED));
}
return Response.newBuilder().setTransactionGetFastRecord(response).build();
}
Aggregations