Search in sources :

Example 1 with Status

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

the class TransactionPublisher method validateNode.

boolean validateNode(NodeProperties node) {
    try {
        log.info("Validating node {}", node);
        Hbar hbar = Hbar.fromTinybars(1L);
        AccountId nodeAccountId = AccountId.fromString(node.getAccountId());
        Client client = validationClient.get();
        Status receiptStatus = new TransferTransaction().addHbarTransfer(nodeAccountId, hbar).addHbarTransfer(client.getOperatorAccountId(), hbar.negated()).setNodeAccountIds(node.getAccountIds()).execute(client).getReceipt(client).status;
        if (receiptStatus == SUCCESS) {
            log.info("Validated node {} successfully", nodeAccountId);
            nodes.addIfAbsent(node);
            return true;
        }
        log.warn("Unable to validate node {}: invalid status code {}", node, receiptStatus);
    } catch (TimeoutException e) {
        log.warn("Unable to validate node {}: Timed out", node);
    } catch (Exception e) {
        log.warn("Unable to validate node {}: ", node, e);
    }
    nodes.remove(node);
    return false;
}
Also used : Status(com.hedera.hashgraph.sdk.Status) AccountId(com.hedera.hashgraph.sdk.AccountId) Hbar(com.hedera.hashgraph.sdk.Hbar) Client(com.hedera.hashgraph.sdk.Client) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

AccountId (com.hedera.hashgraph.sdk.AccountId)1 Client (com.hedera.hashgraph.sdk.Client)1 Hbar (com.hedera.hashgraph.sdk.Hbar)1 Status (com.hedera.hashgraph.sdk.Status)1 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)1 TimeoutException (java.util.concurrent.TimeoutException)1