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