Search in sources :

Example 96 with EntityId

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

the class CryptoCreateTransactionHandler method updateStakingInfo.

private void updateStakingInfo(RecordItem recordItem, Entity entity) {
    var transactionBody = recordItem.getTransactionBody().getCryptoCreateAccount();
    entity.setDeclineReward(transactionBody.getDeclineReward());
    switch(transactionBody.getStakedIdCase()) {
        case STAKEDID_NOT_SET:
            return;
        case STAKED_NODE_ID:
            entity.setStakedNodeId(transactionBody.getStakedNodeId());
            entity.setStakedAccountId(-1L);
            break;
        case STAKED_ACCOUNT_ID:
            EntityId accountId = EntityId.of(transactionBody.getStakedAccountId());
            entity.setStakedAccountId(AccountIdConverter.INSTANCE.convertToDatabaseColumn(accountId));
            entity.setStakedNodeId(-1L);
            break;
    }
    entity.setStakePeriodStart(Utility.getEpochDay(recordItem.getConsensusTimestamp()));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 97 with EntityId

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

the class HistoricalAccountInfoMigration method process.

boolean process(AccountInfo accountInfo) {
    EntityType entityType = EntityType.ACCOUNT;
    long id = EntityId.of(accountInfo.getAccountID()).getId();
    if (contractIds.contains(id)) {
        entityType = EntityType.CONTRACT;
    }
    EntityId entityId = EntityIdEndec.decode(id, entityType);
    CrudRepository<AbstractEntity, Long> repository = getRepository(entityType);
    Optional<AbstractEntity> currentEntity = repository.findById(entityId.getId());
    boolean exists = currentEntity.isPresent();
    AbstractEntity entity = currentEntity.orElseGet(entityId::toEntity);
    boolean updated = !exists;
    // All contract accounts don't have to have a key, but luckily in our file they do.
    if (exists && ArrayUtils.isNotEmpty(entity.getKey())) {
        log.trace("Skipping entity {} that was created after the reset", entityId::entityIdToString);
        return false;
    }
    if (entity.getAutoRenewPeriod() == null && accountInfo.hasAutoRenewPeriod()) {
        entity.setAutoRenewPeriod(accountInfo.getAutoRenewPeriod().getSeconds());
        updated = true;
    }
    // Accounts can't be undeleted
    if (entity.getDeleted() == null || (entity.getDeleted() != accountInfo.getDeleted() && accountInfo.getDeleted())) {
        entity.setDeleted(accountInfo.getDeleted());
        updated = true;
    }
    if (entity.getExpirationTimestamp() == null && accountInfo.hasExpirationTime()) {
        entity.setExpirationTimestamp(DomainUtils.timestampInNanosMax(accountInfo.getExpirationTime()));
        updated = true;
    }
    if (entity.getKey() == null && accountInfo.hasKey()) {
        entity.setKey(accountInfo.getKey().toByteArray());
        updated = true;
    }
    if (StringUtils.isEmpty(entity.getMemo())) {
        entity.setMemo(accountInfo.getMemo());
        updated = true;
    }
    if (entity.getProxyAccountId() == null && accountInfo.hasProxyAccountID()) {
        EntityId proxyAccountEntityId = EntityId.of(accountInfo.getProxyAccountID());
        // Proxy account should get created separately
        entity.setProxyAccountId(proxyAccountEntityId);
        updated |= proxyAccountEntityId != null;
    }
    if (updated) {
        log.info("Saving {} entity: {}", exists ? "existing" : "new", entity);
        repository.save(entity);
    }
    return updated;
}
Also used : EntityType(com.hedera.mirror.common.domain.entity.EntityType) EntityId(com.hedera.mirror.common.domain.entity.EntityId) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity)

Example 98 with EntityId

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

the class AbstractEntityCrudTransactionHandler method updateTransaction.

@Override
public final void updateTransaction(Transaction transaction, RecordItem recordItem) {
    doUpdateTransaction(transaction, recordItem);
    EntityId entityId = transaction.getEntityId();
    EntityOperation entityOperation = type.getEntityOperation();
    if (entityOperation != EntityOperation.NONE && !EntityId.isEmpty(entityId) && recordItem.isSuccessful()) {
        updateEntity(entityId, recordItem);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) EntityOperation(com.hedera.mirror.common.domain.entity.EntityOperation)

Example 99 with EntityId

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

the class ContractResultServiceImpl method getCreatedContractIds.

@SuppressWarnings("deprecation")
private List<Long> getCreatedContractIds(ContractFunctionResult functionResult, RecordItem recordItem, ContractResult contractResult) {
    List<Long> createdContractIds = new ArrayList<>();
    boolean persist = shouldPersistCreatedContractIDs(recordItem);
    for (ContractID createdContractId : functionResult.getCreatedContractIDsList()) {
        EntityId contractId = entityIdService.lookup(createdContractId);
        if (!EntityId.isEmpty(contractId)) {
            createdContractIds.add(contractId.getId());
            // The parent contract ID can also sometimes appear in the created contract IDs list, so exclude it
            if (persist && !contractId.equals(contractResult.getContractId())) {
                processCreatedContractEntity(recordItem, contractId);
            }
        }
    }
    return createdContractIds;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 100 with EntityId

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

the class EntityRecordItemListenerTokenTest method tokenCreateWithNfts.

@ParameterizedTest(name = "{0}")
@MethodSource("provideTokenCreateNftArguments")
void tokenCreateWithNfts(String name, List<CustomFee> customFees, boolean freezeDefault, boolean freezeKey, boolean kycKey, boolean pauseKey, List<TokenAccount> expectedTokenAccounts) {
    // given
    Entity expected = createEntity(DOMAIN_TOKEN_ID, TOKEN_REF_KEY, PAYER.getAccountNum(), AUTO_RENEW_PERIOD, false, EXPIRY_NS, TOKEN_CREATE_MEMO, null, CREATE_TIMESTAMP, CREATE_TIMESTAMP);
    List<EntityId> autoAssociatedAccounts = expectedTokenAccounts.stream().map(TokenAccount::getId).map(TokenAccountId::getAccountId).collect(Collectors.toList());
    // when
    createTokenEntity(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, freezeDefault, freezeKey, kycKey, pauseKey, customFees, autoAssociatedAccounts);
    // then
    assertEquals(1L, entityRepository.count());
    assertEntity(expected);
    // verify token
    TokenPauseStatusEnum pauseStatus = pauseKey ? TokenPauseStatusEnum.UNPAUSED : TokenPauseStatusEnum.NOT_APPLICABLE;
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, CREATE_TIMESTAMP, SYMBOL, 0, pauseStatus);
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expectedTokenAccounts);
    assertCustomFeesInDb(customFees);
    assertThat(tokenTransferRepository.count()).isZero();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13