Search in sources :

Example 31 with Entity

use of com.hedera.mirror.common.domain.entity.Entity 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)

Example 32 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class SqlEntityListener method onEntity.

@Override
public void onEntity(Entity entity) throws ImporterException {
    long id = entity.getId();
    if (id == EntityId.EMPTY.getId()) {
        return;
    }
    Entity merged = entityState.merge(entity.getId(), entity, this::mergeEntity);
    if (merged == entity) {
        // only add the merged object to the collection if the state is replaced with the new entity object, i.e.,
        // attributes only in the previous state are merged into the new entity object
        entities.add(entity);
    }
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 33 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImplTest method storeAccountDeleted.

@Test
void storeAccountDeleted() {
    Entity account = domainBuilder.entity().customize(e -> e.deleted(true)).get();
    entityIdService.notify(account);
    assertThrows(AliasNotFoundException.class, () -> entityIdService.lookup(getProtoAccountId(account)));
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Entity(com.hedera.mirror.common.domain.entity.Entity) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ContractID(com.hederahashgraph.api.proto.java.ContractID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Assertions(org.junit.jupiter.api.Assertions) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) AccountID(com.hederahashgraph.api.proto.java.AccountID) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImplTest method lookupAccountAlias.

@Test
void lookupAccountAlias() {
    Entity account = domainBuilder.entity().persist();
    assertThat(entityIdService.lookup(getProtoAccountId(account))).isEqualTo(account.toEntityId());
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImplTest method storeAccount.

@ParameterizedTest
@CsvSource(value = { "false", "," })
void storeAccount(Boolean deleted) {
    Entity account = domainBuilder.entity().customize(e -> e.deleted(deleted)).get();
    entityIdService.notify(account);
    assertThat(entityIdService.lookup(getProtoAccountId(account))).isEqualTo(account.toEntityId());
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Entity(com.hedera.mirror.common.domain.entity.Entity) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ContractID(com.hederahashgraph.api.proto.java.ContractID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Assertions(org.junit.jupiter.api.Assertions) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) AccountID(com.hederahashgraph.api.proto.java.AccountID) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) Entity(com.hedera.mirror.common.domain.entity.Entity) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Entity (com.hedera.mirror.common.domain.entity.Entity)78 Test (org.junit.jupiter.api.Test)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)40 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)23 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)22 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)21 Transaction (com.hederahashgraph.api.proto.java.Transaction)19 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)16 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)15 EntityId (com.hedera.mirror.common.domain.entity.EntityId)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)10 ByteString (com.google.protobuf.ByteString)9 Contract (com.hedera.mirror.common.domain.contract.Contract)9 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)9 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)9 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)9 Resource (javax.annotation.Resource)9 Assertions (org.junit.jupiter.api.Assertions)9