Search in sources :

Example 46 with EntityId

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

the class DomainUtilsTest method toEvmAddressEntityId.

@Test
void toEvmAddressEntityId() {
    EntityId contractId = EntityId.of(1, 2, 255, EntityType.CONTRACT);
    String expected = "00000001000000000000000200000000000000FF";
    assertThat(DomainUtils.toEvmAddress(contractId)).asHexString().isEqualTo(expected);
    assertThrows(InvalidEntityException.class, () -> DomainUtils.toEvmAddress((EntityId) null));
    assertThrows(InvalidEntityException.class, () -> DomainUtils.toEvmAddress(EntityId.EMPTY));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with EntityId

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

the class DomainUtilsTest method fromEvmAddress.

@Test
void fromEvmAddress() {
    long shard = 1;
    long realm = 2;
    long num = 255;
    byte[] evmAddress = new byte[20];
    evmAddress[3] = (byte) shard;
    evmAddress[11] = (byte) realm;
    evmAddress[19] = (byte) num;
    EntityId expected = EntityId.of(shard, realm, num, EntityType.CONTRACT);
    assertThat(DomainUtils.fromEvmAddress(evmAddress)).isEqualTo(expected);
    evmAddress[0] = (byte) 255;
    evmAddress[4] = (byte) 255;
    evmAddress[12] = (byte) 255;
    // can't be encoded to long
    assertThat(DomainUtils.fromEvmAddress(evmAddress)).isNull();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with EntityId

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

the class CryptoTransfer method getId.

@JsonIgnore
@Override
public Id getId() {
    Id id = new Id();
    id.setConsensusTimestamp(consensusTimestamp);
    id.setAmount(amount);
    id.setEntityId(entityId);
    return id;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 49 with EntityId

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

the class AddressBookServiceImpl method getNodeIds.

/**
 * Get Node id and account id
 *
 * @param nodeAddressProto
 * @return Pair of nodeId and nodeAccountId
 */
private static Pair<Long, EntityId> getNodeIds(NodeAddress nodeAddressProto) {
    var memo = nodeAddressProto.getMemo().toStringUtf8();
    EntityId memoNodeAccountId = StringUtils.isEmpty(memo) ? EntityId.EMPTY : EntityId.of(memo, EntityType.ACCOUNT);
    var nodeAccountId = nodeAddressProto.hasNodeAccountId() ? EntityId.of(nodeAddressProto.getNodeAccountId()) : memoNodeAccountId;
    var nodeId = nodeAddressProto.getNodeId();
    // ensure valid nodeId. In early versions of initial addressBook (entityNum < 20) all nodeIds are set to 0
    if (nodeId == 0 && nodeAccountId.getEntityNum() < 20 && nodeAccountId.getEntityNum() != INITIAL_NODE_ID_ACCOUNT_ID_OFFSET) {
        nodeId = nodeAccountId.getEntityNum() - INITIAL_NODE_ID_ACCOUNT_ID_OFFSET;
    }
    return Pair.of(nodeId, nodeAccountId);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 50 with EntityId

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

the class MetricsExecutionInterceptor method afterExecution.

@Override
public void afterExecution(Context.AfterExecution context, ExecutionAttributes executionAttributes) {
    try {
        String uri = context.httpRequest().getUri().toString();
        EntityId nodeAccountId = getNodeAccountId(uri);
        Instant startTime = executionAttributes.getAttribute(START_TIME);
        ResponseSizeSubscriber responseSizeSubscriber = executionAttributes.getAttribute(SIZE);
        String[] tags = { "action", getAction(uri), "method", context.httpRequest().method().name(), "nodeAccount", nodeAccountId.getEntityNum().toString(), "realm", nodeAccountId.getRealmNum().toString(), "shard", nodeAccountId.getShardNum().toString(), "status", String.valueOf(context.httpResponse().statusCode()), "type", getType(uri) };
        if (startTime != null) {
            requestMetric.tags(tags).register(meterRegistry).record(Duration.between(startTime, Instant.now()));
        }
        if (responseSizeSubscriber != null) {
            responseSizeMetric.tags(tags).register(meterRegistry).record(Double.valueOf(responseSizeSubscriber.getSize()));
        }
    } catch (Exception e) {
        log.warn("Unable to collect S3 metrics", e);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Instant(java.time.Instant)

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