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