Search in sources :

Example 16 with Client

use of com.hedera.hashgraph.sdk.Client in project hedera-mirror-node by hashgraph.

the class SDKClient method toClient.

private Client toClient(Map<String, AccountId> network) throws InterruptedException {
    Client client = Client.forNetwork(network);
    client.setOperator(expandedOperatorAccountId.getAccountId(), expandedOperatorAccountId.getPrivateKey());
    client.setMirrorNetwork(List.of(acceptanceTestProperties.getMirrorNodeAddress()));
    return client;
}
Also used : Client(com.hedera.hashgraph.sdk.Client)

Example 17 with Client

use of com.hedera.hashgraph.sdk.Client in project hedera-mirror-node by hashgraph.

the class SDKClient method validateNode.

private boolean validateNode(String endpoint, AccountId nodeAccountId) {
    boolean valid = false;
    try (Client client = toClient(Map.of(endpoint, nodeAccountId))) {
        new AccountBalanceQuery().setAccountId(nodeAccountId).setNodeAccountIds(List.of(nodeAccountId)).execute(client, Duration.ofSeconds(10L));
        log.debug("Validated node: {}", nodeAccountId);
        valid = true;
    } catch (Exception e) {
        log.warn("Unable to validate node {}: ", nodeAccountId, e.getMessage());
    }
    return valid;
}
Also used : AccountBalanceQuery(com.hedera.hashgraph.sdk.AccountBalanceQuery) Client(com.hedera.hashgraph.sdk.Client) TimeoutException(java.util.concurrent.TimeoutException)

Example 18 with Client

use of com.hedera.hashgraph.sdk.Client in project hedera-mirror-node by hashgraph.

the class SDKClient method getNetworkMap.

private Map<String, AccountId> getNetworkMap() {
    var customNodes = acceptanceTestProperties.getNodes();
    var network = acceptanceTestProperties.getNetwork();
    if (!CollectionUtils.isEmpty(customNodes)) {
        log.debug("Creating SDK client for {} network with nodes: {}", network, customNodes);
        return getNetworkMap(customNodes);
    }
    if (acceptanceTestProperties.isRetrieveAddressBook()) {
        try {
            return getAddressBook();
        } catch (Exception e) {
            log.warn("Error retrieving address book", e);
        }
    }
    Client client = Client.forName(network.toString().toLowerCase());
    return client.getNetwork();
}
Also used : Client(com.hedera.hashgraph.sdk.Client) TimeoutException(java.util.concurrent.TimeoutException)

Example 19 with Client

use of com.hedera.hashgraph.sdk.Client in project hedera-mirror-node by hashgraph.

the class TransactionPublisher method toClient.

private Client toClient(Map<String, AccountId> nodes) {
    AccountId operatorId = AccountId.fromString(monitorProperties.getOperator().getAccountId());
    PrivateKey operatorPrivateKey = PrivateKey.fromString(monitorProperties.getOperator().getPrivateKey());
    Client client = Client.forNetwork(nodes);
    client.setNodeMaxBackoff(publishProperties.getNodeMaxBackoff());
    client.setOperator(operatorId, operatorPrivateKey);
    return client;
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) Client(com.hedera.hashgraph.sdk.Client)

Example 20 with Client

use of com.hedera.hashgraph.sdk.Client in project hedera-mirror-node by hashgraph.

the class TransactionPublisher method close.

@Override
public void close() {
    if (nodeValidator.get() != null) {
        nodeValidator.get().dispose();
    }
    if (publishProperties.isEnabled()) {
        log.warn("Closing {} clients", publishProperties.getClients());
        clients.subscribe(client -> {
            try {
                client.close();
            } catch (Exception e) {
            // Ignore
            }
        });
        Client client = validationClient.get();
        if (client != null) {
            try {
                client.close();
            } catch (Exception e) {
            // Ignore
            }
        }
    }
}
Also used : Client(com.hedera.hashgraph.sdk.Client) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Client (com.hedera.hashgraph.sdk.Client)41 Hbar (com.hedera.hashgraph.sdk.Hbar)23 AccountId (com.hedera.hashgraph.sdk.AccountId)20 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)20 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)16 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)16 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)13 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)12 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)9 Var (com.google.errorprone.annotations.Var)6 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)6 FileId (com.hedera.hashgraph.sdk.FileId)6 KeyList (com.hedera.hashgraph.sdk.KeyList)6 PublicKey (com.hedera.hashgraph.sdk.PublicKey)6 TimeoutException (java.util.concurrent.TimeoutException)6 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)5 ByteString (com.google.protobuf.ByteString)4 AccountBalance (com.hedera.hashgraph.sdk.AccountBalance)4 ScheduleId (com.hedera.hashgraph.sdk.ScheduleId)4 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)4