Search in sources :

Example 1 with ResponseType

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();
}
Also used : CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Example 2 with ResponseType

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();
}
Also used : FileGetContentsResponse(com.hederahashgraph.api.proto.java.FileGetContentsResponse) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Example 3 with ResponseType

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();
}
Also used : ConsensusGetTopicInfoQuery(com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery) ConsensusGetTopicInfoResponse(com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoResponse) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Example 4 with ResponseType

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();
}
Also used : FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Example 5 with ResponseType

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();
}
Also used : TransactionGetFastRecordQuery(com.hederahashgraph.api.proto.java.TransactionGetFastRecordQuery) TransactionGetFastRecordResponse(com.hederahashgraph.api.proto.java.TransactionGetFastRecordResponse) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Aggregations

ResponseType (com.hederahashgraph.api.proto.java.ResponseType)12 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)1 ConsensusGetTopicInfoResponse (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoResponse)1 ContractGetRecordsQuery (com.hederahashgraph.api.proto.java.ContractGetRecordsQuery)1 ContractGetRecordsResponse (com.hederahashgraph.api.proto.java.ContractGetRecordsResponse)1 CryptoGetInfoQuery (com.hederahashgraph.api.proto.java.CryptoGetInfoQuery)1 CryptoGetInfoResponse (com.hederahashgraph.api.proto.java.CryptoGetInfoResponse)1 CryptoGetLiveHashQuery (com.hederahashgraph.api.proto.java.CryptoGetLiveHashQuery)1 CryptoGetLiveHashResponse (com.hederahashgraph.api.proto.java.CryptoGetLiveHashResponse)1 CryptoGetStakersQuery (com.hederahashgraph.api.proto.java.CryptoGetStakersQuery)1 CryptoGetStakersResponse (com.hederahashgraph.api.proto.java.CryptoGetStakersResponse)1 FileGetContentsResponse (com.hederahashgraph.api.proto.java.FileGetContentsResponse)1 FileGetInfoResponse (com.hederahashgraph.api.proto.java.FileGetInfoResponse)1 GetBySolidityIDQuery (com.hederahashgraph.api.proto.java.GetBySolidityIDQuery)1 GetBySolidityIDResponse (com.hederahashgraph.api.proto.java.GetBySolidityIDResponse)1 TokenGetAccountNftInfosQuery (com.hederahashgraph.api.proto.java.TokenGetAccountNftInfosQuery)1 TokenGetAccountNftInfosResponse (com.hederahashgraph.api.proto.java.TokenGetAccountNftInfosResponse)1 TokenGetNftInfosQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfosQuery)1 TokenGetNftInfosResponse (com.hederahashgraph.api.proto.java.TokenGetNftInfosResponse)1