use of com.hedera.mirror.common.domain.entity.EntityId 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.EntityId in project hedera-mirror-node by hashgraph.
the class TestRecordFiles method getV2V5Files.
public List<RecordFile> getV2V5Files() {
EntityId nodeAccountId = EntityId.of(0, 0, 3, EntityType.ACCOUNT);
RecordFile recordFileV2 = RecordFile.builder().consensusStart(1611188151568507001L).consensusEnd(1611188151568507001L).count(1L).digestAlgorithm(DigestAlgorithm.SHA384).fileHash("e7d9e71efd239bde3adcad8eb0571c38f91f77ae76a4af69bb44f19b2785ad3594ac1d265351a592ab14301da9bb1950").hash("e7d9e71efd239bde3adcad8eb0571c38f91f77ae76a4af69bb44f19b2785ad3594ac1d265351a592ab14301da9bb1950").name("2021-01-21T00_15_51.568507001Z.rcd").nodeAccountId(nodeAccountId).previousHash("d27ba83c736bfa2ffc9a6f062b27ea4856800bbbe820b77b32e08faf3d7475d81ef5a16f90ce065d35eefa999677edaa").version(2).build();
RecordFile recordFileV5 = RecordFile.builder().consensusStart(1611188383558496000L).consensusEnd(1611188383558496000L).count(1L).digestAlgorithm(DigestAlgorithm.SHA384).fileHash("42717bae0e538bac34563784b08b5a5b50a9964c9435452c93134bf13355c9778a1c64cfdc30f33fe52dd7f76dbdda70").hapiVersionMajor(0).hapiVersionMinor(11).hapiVersionPatch(0).hash("e6c1d7bfe956b6b2c8061bee5c43e512111cbccb21099bb0c49e2a7c74cf617cf5b6bf65070f29eb43a80d9cef2d8242").metadataHash("1d83206a166a06c8579f9de637cf50a565341928b55bfbdc774ce85ac2169b46c23db42729723e7c39e5a042bd9e3b98").name("2021-01-21T00_19_43.558496000Z.rcd").nodeAccountId(nodeAccountId).previousHash(recordFileV2.getHash()).version(5).build();
return List.of(recordFileV2, recordFileV5);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityIdServiceImplTest method lookupContractsReturnsFirst.
@Test
void lookupContractsReturnsFirst() {
ContractID contractId1 = ContractID.newBuilder().setContractNum(100).build();
ContractID contractId2 = ContractID.newBuilder().setContractNum(101).build();
EntityId entityId = entityIdService.lookup(contractId1, contractId2);
assertThat(entityId).isEqualTo(EntityId.of(contractId1));
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityIdServiceImplTest method lookupContracts.
@Test
void lookupContracts() {
ContractID nullContractId = null;
ContractID contractId = ContractID.newBuilder().setContractNum(100).build();
ContractID contractIdInvalid = ContractID.newBuilder().setRealmNum(1).build();
Contract contractDeleted = domainBuilder.contract().customize(e -> e.deleted(true)).persist();
EntityId entityId = entityIdService.lookup(nullContractId, ContractID.getDefaultInstance(), getProtoContractId(contractDeleted), contractIdInvalid, contractId);
assertThat(entityId).isEqualTo(EntityId.of(contractId));
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityIdServiceImplTest method cache.
@Test
void cache() {
Contract contract = domainBuilder.contract().persist();
ContractID contractId = getProtoContractId(contract);
EntityId expected = contract.toEntityId();
// db query and cache put
assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
// mark it as deleted
contract.setDeleted(true);
contractRepository.save(contract);
// cache hit
assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
contractRepository.deleteById(contract.getId());
assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
// cache miss
reset();
assertThrows(AliasNotFoundException.class, () -> entityIdService.lookup(getProtoContractId(contract)));
}
Aggregations