Search in sources :

Example 41 with Query

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

the class HapiGetAccountBalance method submitWith.

@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getAccountBalanceQuery(spec, payment, false);
    response = spec.clients().getCryptoSvcStub(targetNodeFor(spec), useTls).cryptoGetBalance(query);
    ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
    if (status == ResponseCodeEnum.ACCOUNT_DELETED) {
        log.info(spec.logPrefix() + repr + " was actually deleted!");
    } else {
        long balance = response.getCryptogetAccountBalance().getBalance();
        long TINYBARS_PER_HBAR = 100_000_000L;
        long hBars = balance / TINYBARS_PER_HBAR;
        if (!loggingOff) {
            log.info(spec.logPrefix() + "balance for '" + repr + "': " + balance + " tinyBars (" + hBars + "ħ)");
        }
        if (yahcliLogger) {
            COMMON_MESSAGES.info(String.format("%20s | %20d |", repr, balance));
        }
    }
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query)

Example 42 with Query

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

the class HapiGetExecTime method lookupCostWith.

@Override
protected long lookupCostWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getExecTimesQuery(spec, payment, true);
    Response response = spec.clients().getNetworkSvcStub(targetNodeFor(spec), useTls).getExecutionTime(query);
    return costFrom(response);
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) NetworkGetExecutionTimeResponse(com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeResponse) Query(com.hederahashgraph.api.proto.java.Query) NetworkGetExecutionTimeQuery(com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeQuery)

Example 43 with Query

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

the class HapiGetFileContents method submitWith.

@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getFileContentQuery(spec, payment, false);
    preQueryCb.ifPresent(cb -> cb.accept(fileId));
    response = spec.clients().getFileSvcStub(targetNodeFor(spec), useTls).getFileContent(query);
    postQueryCb.ifPresent(cb -> cb.accept(response));
    byte[] bytes = response.getFileGetContents().getFileContents().getContents().toByteArray();
    if (verboseLoggingOn) {
        var len = response.getFileGetContents().getFileContents().getContents().size();
        log.info(String.format("%s contained %s bytes", fileName, len));
        if (isConfigListFile(spec)) {
            var configList = ServicesConfigurationList.parseFrom(bytes);
            var msg = new StringBuilder("As a config list, contents are:");
            List<String> entries = new ArrayList<>();
            configList.getNameValueList().forEach(setting -> entries.add(String.format("\n  %s=%s", setting.getName(), setting.getValue())));
            Collections.sort(entries);
            entries.forEach(msg::append);
            log.info(msg.toString());
        }
    }
    if (fileName.equals(spec.setup().appPropertiesFile()) && (props != IMMUTABLE_MAP)) {
        try {
            var configList = ServicesConfigurationList.parseFrom(bytes);
            configList.getNameValueList().forEach(setting -> props.put(setting.getName(), setting.getValue()));
        } catch (Exception impossible) {
            throw new IllegalStateException(impossible);
        }
    }
    if (snapshotPath.isPresent() || readablePath.isPresent()) {
        try {
            if (snapshotPath.isPresent()) {
                if (saveIn4kChunks) {
                    int i = 0;
                    int MAX_LEN = 4 * 1024;
                    int suffix = 0;
                    while (i < bytes.length) {
                        File snapshotFile = new File(String.format("part%d-%s", suffix++, snapshotPath.get()));
                        ByteSink byteSink = Files.asByteSink(snapshotFile);
                        int numToWrite = Math.min(bytes.length - i, MAX_LEN);
                        byteSink.write(Arrays.copyOfRange(bytes, i, i + numToWrite));
                        i += numToWrite;
                        log.info("Saved next " + numToWrite + " bytes of '" + fileName + "' to " + snapshotFile.getAbsolutePath());
                    }
                } else {
                    File snapshotFile = new File(snapshotPath.get());
                    ByteSink byteSink = Files.asByteSink(snapshotFile);
                    byteSink.write(bytes);
                    log.info("Saved " + bytes.length + " bytes of '" + fileName + "' to " + snapshotFile.getAbsolutePath());
                }
            }
            if (readablePath.isPresent()) {
                String contents = parser.apply(bytes);
                File readableFile = new File(readablePath.get());
                CharSink charSink = Files.asCharSink(readableFile, Charset.forName("UTF-8"));
                charSink.write(contents);
                log.info("Saved parsed contents of '" + fileName + "' to " + readableFile.getAbsolutePath());
            }
        } catch (Exception e) {
            log.error("Couldn't save '" + fileName + "' snapshot!", e);
        }
    }
    if (registryEntry.isPresent()) {
        spec.registry().saveBytes(registryEntry.get(), response.getFileGetContents().getFileContents().getContents());
    }
    contentsCb.ifPresent(cb -> cb.accept(response.getFileGetContents().getFileContents().getContents().toByteArray()));
}
Also used : CharSink(com.google.common.io.CharSink) Query(com.hederahashgraph.api.proto.java.Query) FileGetContentsQuery(com.hederahashgraph.api.proto.java.FileGetContentsQuery) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ByteSink(com.google.common.io.ByteSink) File(java.io.File)

Example 44 with Query

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

the class HapiGetFileInfo method lookupCostWith.

@Override
protected long lookupCostWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getFileInfoQuery(spec, payment, true);
    Response response = spec.clients().getFileSvcStub(targetNodeFor(spec), useTls).getFileInfo(query);
    return costFrom(response);
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) Query(com.hederahashgraph.api.proto.java.Query) FileGetInfoQuery(com.hederahashgraph.api.proto.java.FileGetInfoQuery)

Example 45 with Query

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

the class HapiGetAccountInfo method submitWith.

@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getAccountInfoQuery(spec, payment, false);
    response = spec.clients().getCryptoSvcStub(targetNodeFor(spec), useTls).getAccountInfo(query);
    final var infoResponse = response.getCryptoGetInfo();
    if (infoResponse.getHeader().getNodeTransactionPrecheckCode() == OK) {
        exposingExpiryTo.ifPresent(cb -> cb.accept(infoResponse.getAccountInfo().getExpirationTime().getSeconds()));
        exposingBalanceTo.ifPresent(cb -> cb.accept(infoResponse.getAccountInfo().getBalance()));
        idObserver.ifPresent(cb -> cb.accept(infoResponse.getAccountInfo().getAccountID()));
    }
    if (verboseLoggingOn) {
        log.info("Info for '" + repr() + "': " + response.getCryptoGetInfo().getAccountInfo());
    }
    if (customLog.isPresent()) {
        customLog.get().accept(response.getCryptoGetInfo().getAccountInfo(), log);
    }
    if (registryEntry.isPresent()) {
        spec.registry().saveAccountInfo(registryEntry.get(), response.getCryptoGetInfo().getAccountInfo());
    }
}
Also used : CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query)

Aggregations

Query (com.hederahashgraph.api.proto.java.Query)152 Test (org.junit.jupiter.api.Test)108 Response (com.hederahashgraph.api.proto.java.Response)95 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)24 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)13 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)13 ContractGetInfoQuery (com.hederahashgraph.api.proto.java.ContractGetInfoQuery)11 ByteString (com.google.protobuf.ByteString)10 ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)10 ScheduleGetInfoQuery (com.hederahashgraph.api.proto.java.ScheduleGetInfoQuery)10 TokenGetInfoQuery (com.hederahashgraph.api.proto.java.TokenGetInfoQuery)10 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)9 CryptoGetInfoQuery (com.hederahashgraph.api.proto.java.CryptoGetInfoQuery)9 FileGetInfoQuery (com.hederahashgraph.api.proto.java.FileGetInfoQuery)8 NetworkGetExecutionTimeQuery (com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeQuery)8 HashMap (java.util.HashMap)8 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)7 ContractGetBytecodeQuery (com.hederahashgraph.api.proto.java.ContractGetBytecodeQuery)7 FileGetContentsQuery (com.hederahashgraph.api.proto.java.FileGetContentsQuery)7 FileGetInfoResponse (com.hederahashgraph.api.proto.java.FileGetInfoResponse)7