Search in sources :

Example 11 with AccountId

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))));
}
Also used : NodeProperties(com.hedera.mirror.monitor.NodeProperties) Disposable(reactor.core.Disposable) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TimeoutException(java.util.concurrent.TimeoutException) Status(com.hedera.hashgraph.sdk.Status) AtomicReference(java.util.concurrent.atomic.AtomicReference) SecureRandom(java.security.SecureRandom) HbarUnit(com.hedera.hashgraph.sdk.HbarUnit) WithExecute(com.hedera.hashgraph.sdk.WithExecute) Duration(java.time.Duration) Map(java.util.Map) Transaction(com.hedera.hashgraph.sdk.Transaction) Schedulers(reactor.core.scheduler.Schedulers) AccountId(com.hedera.hashgraph.sdk.AccountId) Hbar(com.hedera.hashgraph.sdk.Hbar) Named(javax.inject.Named) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransactionId(com.hedera.hashgraph.sdk.TransactionId) TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) NodeValidationProperties(com.hedera.mirror.monitor.NodeValidationProperties) Client(com.hedera.hashgraph.sdk.Client) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) Flux(reactor.core.publisher.Flux) SUCCESS(com.hedera.hashgraph.sdk.Status.SUCCESS) Log4j2(lombok.extern.log4j.Log4j2) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) MonitorProperties(com.hedera.mirror.monitor.MonitorProperties) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AccountId(com.hedera.hashgraph.sdk.AccountId) NodeValidationProperties(com.hedera.mirror.monitor.NodeValidationProperties) Client(com.hedera.hashgraph.sdk.Client)

Example 12 with AccountId

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);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TimeGauge(io.micrometer.core.instrument.TimeGauge) Scheduled(org.springframework.scheduling.annotation.Scheduled) Value(lombok.Value) DurationToStringSerializer(com.hedera.mirror.monitor.converter.DurationToStringSerializer) TimeUnit(java.util.concurrent.TimeUnit) Timer(io.micrometer.core.instrument.Timer) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Map(java.util.Map) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) AccountId(com.hedera.hashgraph.sdk.AccountId) Named(javax.inject.Named) Timer(io.micrometer.core.instrument.Timer)

Example 13 with AccountId

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;
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) KeyList(com.hedera.hashgraph.sdk.KeyList) TokenUpdateTransaction(com.hedera.hashgraph.sdk.TokenUpdateTransaction)

Example 14 with AccountId

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());
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) When(io.cucumber.java.en.When)

Example 15 with AccountId

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;
    }
}
Also used : CustomFractionalFee(com.hedera.hashgraph.sdk.CustomFractionalFee) AccountId(com.hedera.hashgraph.sdk.AccountId) CustomFixedFee(com.hedera.hashgraph.sdk.CustomFixedFee) DataTableType(io.cucumber.java.DataTableType)

Aggregations

AccountId (com.hedera.hashgraph.sdk.AccountId)35 Client (com.hedera.hashgraph.sdk.Client)20 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)17 Hbar (com.hedera.hashgraph.sdk.Hbar)16 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)16 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)15 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)14 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)11 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)10 KeyList (com.hedera.hashgraph.sdk.KeyList)9 PublicKey (com.hedera.hashgraph.sdk.PublicKey)9 Var (com.google.errorprone.annotations.Var)8 ExpandedAccountId (com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId)7 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)6 ScheduleId (com.hedera.hashgraph.sdk.ScheduleId)5 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)5 ScheduleSignTransaction (com.hedera.hashgraph.sdk.ScheduleSignTransaction)5 TimeoutException (java.util.concurrent.TimeoutException)5 AccountBalance (com.hedera.hashgraph.sdk.AccountBalance)4 ScheduleCreateTransaction (com.hedera.hashgraph.sdk.ScheduleCreateTransaction)4