use of com.hedera.mirror.common.domain.entity.EntityType in project hedera-mirror-node by hashgraph.
the class EntityIdServiceImpl method notify.
@Override
public void notify(Aliasable aliasable) {
if (aliasable == null || (aliasable.getDeleted() != null && aliasable.getDeleted())) {
return;
}
ByteString alias = DomainUtils.fromBytes(aliasable.getAlias());
if (alias == null) {
return;
}
EntityId entityId = aliasable.toEntityId();
EntityType type = aliasable.getType();
GeneratedMessageV3.Builder<?> builder;
switch(type) {
case ACCOUNT:
builder = AccountID.newBuilder().setShardNum(entityId.getShardNum()).setRealmNum(entityId.getRealmNum()).setAlias(alias);
break;
case CONTRACT:
builder = ContractID.newBuilder().setShardNum(entityId.getShardNum()).setRealmNum(entityId.getRealmNum()).setEvmAddress(alias);
break;
default:
throw new InvalidEntityException(String.format("%s entity can't have alias", type));
}
cache.put(builder.build().hashCode(), entityId);
}
use of com.hedera.mirror.common.domain.entity.EntityType 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;
}
Aggregations