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);
}
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));
}
Aggregations