Search in sources :

Example 1 with NodeStake

use of com.hedera.mirror.common.domain.addressbook.NodeStake in project hedera-mirror-node by hashgraph.

the class NodeStakeUpdateTransactionHandler method updateTransaction.

@Override
public void updateTransaction(Transaction transaction, RecordItem recordItem) {
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    if (!recordItem.isSuccessful()) {
        var record = recordItem.getRecord();
        log.warn("NodeStakeUpdateTransaction at consensus timestamp {} failed with status {}", consensusTimestamp, record.getReceipt().getStatus());
        return;
    }
    // We subtract one since we get stake update in current day, but it applies to previous day
    long epochDay = Utility.getEpochDay(consensusTimestamp) - 1L;
    var transactionBody = recordItem.getTransactionBody().getNodeStakeUpdate();
    long stakingPeriod = DomainUtils.timestampInNanosMax(transactionBody.getEndOfStakingPeriod());
    long stakeTotal = transactionBody.getNodeStakeList().stream().map(n -> n.getStake()).reduce(0L, Long::sum);
    for (var nodeStakeProto : transactionBody.getNodeStakeList()) {
        NodeStake nodeStake = new NodeStake();
        nodeStake.setConsensusTimestamp(consensusTimestamp);
        nodeStake.setEpochDay(epochDay);
        nodeStake.setNodeId(nodeStakeProto.getNodeId());
        nodeStake.setRewardRate(nodeStakeProto.getRewardRate());
        nodeStake.setStake(nodeStakeProto.getStake());
        nodeStake.setStakeRewarded(nodeStakeProto.getStakeRewarded());
        nodeStake.setStakeTotal(stakeTotal);
        nodeStake.setStakingPeriod(stakingPeriod);
        entityListener.onNodeStake(nodeStake);
    }
}
Also used : DomainUtils(com.hedera.mirror.common.util.DomainUtils) EntityId(com.hedera.mirror.common.domain.entity.EntityId) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Log4j2(lombok.extern.log4j.Log4j2) Named(javax.inject.Named) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) NodeStake(com.hedera.mirror.common.domain.addressbook.NodeStake) EntityListener(com.hedera.mirror.importer.parser.record.entity.EntityListener) Utility(com.hedera.mirror.importer.util.Utility) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) NodeStake(com.hedera.mirror.common.domain.addressbook.NodeStake)

Aggregations

NodeStake (com.hedera.mirror.common.domain.addressbook.NodeStake)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)1 TransactionType (com.hedera.mirror.common.domain.transaction.TransactionType)1 DomainUtils (com.hedera.mirror.common.util.DomainUtils)1 EntityListener (com.hedera.mirror.importer.parser.record.entity.EntityListener)1 Utility (com.hedera.mirror.importer.util.Utility)1 Named (javax.inject.Named)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Log4j2 (lombok.extern.log4j.Log4j2)1