use of com.hedera.hashgraph.sdk.AccountId in project hedera-mirror-node by hashgraph.
the class TransactionPublisher method getClients.
private synchronized Flux<Client> getClients() {
NodeValidationProperties validationProperties = monitorProperties.getNodeValidation();
var configuredNodes = monitorProperties.getNodes();
Map<String, AccountId> nodeMap = configuredNodes.stream().collect(Collectors.toMap(NodeProperties::getEndpoint, p -> AccountId.fromString(p.getAccountId())));
this.nodes.addAll(configuredNodes);
Client client = toClient(nodeMap);
client.setMaxAttempts(validationProperties.getMaxAttempts());
client.setMaxBackoff(validationProperties.getMaxBackoff());
client.setMinBackoff(validationProperties.getMinBackoff());
client.setRequestTimeout(validationProperties.getRequestTimeout());
this.validationClient.set(client);
if (validationProperties.isEnabled() && nodeValidator.get() == null) {
int nodeCount = configuredNodes.size();
int parallelism = Math.min(nodeCount, validationProperties.getMaxThreads());
var scheduler = Schedulers.newParallel("validator", parallelism + 1);
var disposable = Flux.interval(Duration.ZERO, validationProperties.getFrequency(), scheduler).filter(// In case it's later disabled
i -> validationProperties.isEnabled()).flatMap(i -> Flux.fromIterable(configuredNodes)).parallel(parallelism).runOn(scheduler).map(this::validateNode).sequential().buffer(nodeCount).doOnNext(i -> log.info("{} of {} nodes are functional", nodes.size(), nodeCount)).doOnSubscribe(s -> log.info("Starting node validation")).onErrorContinue((e, i) -> log.error("Exception validating nodes: ", e)).subscribe();
nodeValidator.set(disposable);
}
return Flux.range(0, publishProperties.getClients()).flatMap(i -> Mono.defer(() -> Mono.just(toClient(nodeMap))));
}
use of com.hedera.hashgraph.sdk.AccountId in project hedera-mirror-node by hashgraph.
the class PublishMetrics method recordMetric.
private void recordMetric(PublishRequest request, PublishResponse response, String status) {
try {
String node = Optional.ofNullable(request.getTransaction().getNodeAccountIds()).filter(l -> !l.isEmpty()).map(l -> l.get(0)).map(AccountId::toString).orElse(UNKNOWN);
long startTime = request.getTimestamp().toEpochMilli();
long endTime = response != null ? response.getTimestamp().toEpochMilli() : System.currentTimeMillis();
Tags tags = new Tags(node, request.getScenario(), status);
Timer submitTimer = submitTimers.computeIfAbsent(tags, this::newSubmitMetric);
submitTimer.record(endTime - startTime, TimeUnit.MILLISECONDS);
durationGauges.computeIfAbsent(tags, this::newDurationMetric);
if (response != null && response.getReceipt() != null) {
long elapsed = System.currentTimeMillis() - startTime;
Timer handleTimer = handleTimers.computeIfAbsent(tags, this::newHandleMetric);
handleTimer.record(elapsed, TimeUnit.MILLISECONDS);
}
} catch (Exception ex) {
log.error("Unexpected error when recording metric", ex);
}
}
use of com.hedera.hashgraph.sdk.AccountId in project hedera-mirror-node by hashgraph.
the class TokenClient method updateTokenTreasury.
public NetworkTransactionResponse updateTokenTreasury(TokenId tokenId, ExpandedAccountId newTreasuryId) {
AccountId treasuryAccountId = newTreasuryId.getAccountId();
String memo = getMemo("Update token");
TokenUpdateTransaction tokenUpdateTransaction = new TokenUpdateTransaction().setTokenId(tokenId).setTokenMemo(memo).setTreasuryAccountId(treasuryAccountId).setTransactionMemo(memo);
KeyList keyList = KeyList.of(newTreasuryId.getPrivateKey());
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(tokenUpdateTransaction, keyList);
log.debug("Updated token {} treasury account {}.", tokenId, treasuryAccountId);
return networkTransactionResponse;
}
use of com.hedera.hashgraph.sdk.AccountId in project hedera-mirror-node by hashgraph.
the class AccountFeature method sendTinyHbars.
@When("I send {long} tℏ to account {int}")
public void sendTinyHbars(long amount, int accountNum) {
senderAccountId = new ExpandedAccountId(new AccountId(accountNum));
startingBalance = accountClient.getBalance(senderAccountId);
networkTransactionResponse = accountClient.sendCryptoTransfer(senderAccountId.getAccountId(), Hbar.fromTinybars(amount));
assertNotNull(networkTransactionResponse.getTransactionId());
assertNotNull(networkTransactionResponse.getReceipt());
}
use of com.hedera.hashgraph.sdk.AccountId in project hedera-mirror-node by hashgraph.
the class CustomFeesConverter method customFee.
@DataTableType
public CustomFee customFee(Map<String, String> entry) {
String amount = entry.get("amount");
AccountId collector = tokenFeature.getRecipientAccountId(Integer.parseInt(entry.get("collector")));
if (Strings.isNotEmpty(amount)) {
// fixed fee
CustomFixedFee fixedFee = new CustomFixedFee();
fixedFee.setAmount(Long.parseLong(amount));
fixedFee.setFeeCollectorAccountId(collector);
fixedFee.setDenominatingTokenId(getTokenId(entry.get("token")));
return fixedFee;
} else {
CustomFractionalFee fractionalFee = new CustomFractionalFee();
fractionalFee.setNumerator(Long.parseLong(entry.get("numerator")));
fractionalFee.setDenominator(Long.parseLong(entry.get("denominator")));
fractionalFee.setFeeCollectorAccountId(collector);
fractionalFee.setMax(getValueOrDefault(entry.get("maximum")));
fractionalFee.setMin(getValueOrDefault(entry.get("minimum")));
return fractionalFee;
}
}
Aggregations