Search in sources :

Example 1 with StakingRewardTransfer

use of com.hedera.mirror.common.domain.transaction.StakingRewardTransfer in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method insertStakingRewardTransfers.

private void insertStakingRewardTransfers(RecordItem recordItem) {
    var consensusTimestamp = recordItem.getConsensusTimestamp();
    var payerAccountId = recordItem.getPayerAccountId();
    for (var aa : recordItem.getRecord().getPaidStakingRewardsList()) {
        var accountId = EntityId.of(aa.getAccountID());
        var stakingRewardTransfer = new StakingRewardTransfer();
        stakingRewardTransfer.setAccountId(accountId.getId());
        stakingRewardTransfer.setAmount(aa.getAmount());
        stakingRewardTransfer.setConsensusTimestamp(consensusTimestamp);
        stakingRewardTransfer.setPayerAccountId(payerAccountId);
        entityListener.onStakingRewardTransfer(stakingRewardTransfer);
        // The staking reward may be paid to either an account or a contract. Create non-history updates
        // with the new stake reward start for both an account entity and a contract, the upsert sql
        // will only update one depending on the actual type of the entity.
        Entity account = accountId.toEntity();
        var stakePeriodStart = Utility.getEpochDay(consensusTimestamp);
        account.setStakePeriodStart(stakePeriodStart);
        // Don't trigger a history row
        account.setTimestampRange(null);
        entityListener.onEntity(account);
        Contract contract = EntityId.of(account.getShard(), account.getRealm(), account.getNum(), EntityType.CONTRACT).toEntity();
        contract.setStakePeriodStart(stakePeriodStart);
        // Don't trigger a history row
        contract.setTimestampRange(null);
        entityListener.onContract(contract);
    }
}
Also used : StakingRewardTransfer(com.hedera.mirror.common.domain.transaction.StakingRewardTransfer) Entity(com.hedera.mirror.common.domain.entity.Entity) Contract(com.hedera.mirror.common.domain.contract.Contract)

Aggregations

Contract (com.hedera.mirror.common.domain.contract.Contract)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 StakingRewardTransfer (com.hedera.mirror.common.domain.transaction.StakingRewardTransfer)1