Search in sources :

Example 1 with SingleAccountBalances

use of com.hedera.services.stream.proto.SingleAccountBalances in project hedera-services by hashgraph.

the class SignedStateBalancesExporter method summarized.

BalancesSummary summarized(ServicesState signedState) {
    long nodeBalanceWarnThreshold = dynamicProperties.nodeBalanceWarningThreshold();
    BigInteger totalFloat = BigInteger.valueOf(0L);
    List<SingleAccountBalances> accountBalances = new ArrayList<>();
    var nodeIds = MiscUtils.getNodeAccounts(signedState.addressBook());
    var tokens = signedState.tokens();
    var accounts = signedState.accounts();
    var tokenAssociations = signedState.tokenAssociations();
    for (var entry : accounts.entrySet()) {
        var id = entry.getKey();
        var account = entry.getValue();
        if (!account.isDeleted()) {
            var accountId = id.toGrpcAccountId();
            var balance = account.getBalance();
            if (nodeIds.contains(accountId) && balance < nodeBalanceWarnThreshold) {
                log.warn(LOW_NODE_BALANCE_WARN_MSG_TPL, readableId(accountId), balance);
            }
            totalFloat = totalFloat.add(BigInteger.valueOf(account.getBalance()));
            SingleAccountBalances.Builder sabBuilder = SingleAccountBalances.newBuilder();
            sabBuilder.setHbarBalance(balance).setAccountID(accountId);
            if (dynamicProperties.shouldExportTokenBalances()) {
                addTokenBalances(accountId, account, sabBuilder, tokens, tokenAssociations);
            }
            accountBalances.add(sabBuilder.build());
        }
    }
    accountBalances.sort(SINGLE_ACCOUNT_BALANCES_COMPARATOR);
    return new BalancesSummary(totalFloat, accountBalances);
}
Also used : SingleAccountBalances(com.hedera.services.stream.proto.SingleAccountBalances) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger)

Example 2 with SingleAccountBalances

use of com.hedera.services.stream.proto.SingleAccountBalances in project hedera-mirror-node by hashgraph.

the class ProtoBalanceFileReader method toAccountBalance.

private AccountBalance toAccountBalance(long consensusTimestamp, SingleAccountBalances balances) {
    EntityId accountId = EntityId.of(balances.getAccountID());
    List<TokenBalance> tokenBalances = balances.getTokenUnitBalancesList().stream().map(tokenBalance -> {
        EntityId tokenId = EntityId.of(tokenBalance.getTokenId());
        TokenBalance.Id id = new TokenBalance.Id(consensusTimestamp, accountId, tokenId);
        return new TokenBalance(tokenBalance.getBalance(), id);
    }).collect(Collectors.toList());
    return new AccountBalance(balances.getHbarBalance(), tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) ExtensionRegistryLite(com.google.protobuf.ExtensionRegistryLite) Named(javax.inject.Named) SingleAccountBalances(com.hedera.services.stream.proto.SingleAccountBalances) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) DomainUtils(com.hedera.mirror.common.util.DomainUtils) IOException(java.io.IOException) Instant(java.time.Instant) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) Collectors(java.util.stream.Collectors) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOUtils(org.apache.commons.io.IOUtils) Flux(reactor.core.publisher.Flux) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) List(java.util.List) CodedInputStream(com.google.protobuf.CodedInputStream) Log4j2(lombok.extern.log4j.Log4j2) DigestUtils(org.apache.commons.codec.digest.DigestUtils) InputStream(java.io.InputStream) Assert(org.springframework.util.Assert) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Aggregations

SingleAccountBalances (com.hedera.services.stream.proto.SingleAccountBalances)2 CodedInputStream (com.google.protobuf.CodedInputStream)1 ExtensionRegistryLite (com.google.protobuf.ExtensionRegistryLite)1 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)1 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)1 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)1 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 DomainUtils (com.hedera.mirror.common.util.DomainUtils)1 StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)1 InvalidStreamFileException (com.hedera.mirror.importer.exception.InvalidStreamFileException)1 StreamFileReaderException (com.hedera.mirror.importer.exception.StreamFileReaderException)1 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1