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