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