Search in sources :

Example 11 with Timestamp

use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.

the class ConsensusController method toFilter.

private TopicMessageFilter toFilter(ConsensusTopicQuery query) {
    var filter = TopicMessageFilter.builder().limit(query.getLimit());
    if (query.hasTopicID()) {
        filter.topicId(EntityId.of(query.getTopicID()));
    }
    if (query.hasConsensusStartTime()) {
        Timestamp startTimeStamp = query.getConsensusStartTime();
        Instant startInstant = ProtoUtil.fromTimestamp(startTimeStamp);
        filter.startTime(startInstant.isBefore(Instant.EPOCH) ? Instant.EPOCH : startInstant);
    }
    if (query.hasConsensusEndTime()) {
        Timestamp endTimeStamp = query.getConsensusEndTime();
        Instant endInstant = ProtoUtil.fromTimestamp(endTimeStamp);
        filter.endTime(endInstant.isAfter(InstantToLongConverter.LONG_MAX_INSTANT) ? InstantToLongConverter.LONG_MAX_INSTANT : endInstant);
    }
    return filter.build();
}
Also used : Instant(java.time.Instant) Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Example 12 with Timestamp

use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.

the class DomainBuilder method addressBookEntry.

public DomainWrapper<AddressBookEntry, AddressBookEntry.AddressBookEntryBuilder> addressBookEntry(int endpoints) {
    long consensusTimestamp = timestamp();
    long nodeId = id();
    var builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).description(text(10)).memo(text(10)).nodeId(nodeId).nodeAccountId(EntityId.of(0L, 0L, nodeId + 3, ACCOUNT)).nodeCertHash(bytes(96)).publicKey(text(64)).stake(0L);
    var serviceEndpoints = new HashSet<AddressBookServiceEndpoint>();
    builder.serviceEndpoints(serviceEndpoints);
    for (int i = 0; i < endpoints; ++i) {
        var endpoint = addressBookServiceEndpoint().customize(a -> a.consensusTimestamp(consensusTimestamp).nodeId(nodeId)).get();
        serviceEndpoints.add(endpoint);
    }
    return new DomainWrapperImpl<>(builder, builder::build);
}
Also used : SCHEDULE(com.hedera.mirror.common.domain.entity.EntityType.SCHEDULE) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) EntityType(com.hedera.mirror.common.domain.entity.EntityType) NodeStake(com.hedera.mirror.common.domain.addressbook.NodeStake) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) InetAddress(java.net.InetAddress) SecureRandom(java.security.SecureRandom) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) Range(com.google.common.collect.Range) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) Instant(java.time.Instant) TINYBARS_IN_ONE_HBAR(com.hedera.mirror.common.util.DomainUtils.TINYBARS_IN_ONE_HBAR) SignaturePair(com.hederahashgraph.api.proto.java.SignaturePair) ZoneId(java.time.ZoneId) FileData(com.hedera.mirror.common.domain.file.FileData) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) ByteString(com.google.protobuf.ByteString) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) TransactionOperations(org.springframework.transaction.support.TransactionOperations) StakingRewardTransfer(com.hedera.mirror.common.domain.transaction.StakingRewardTransfer) LocalDate(java.time.LocalDate) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) Schedule(com.hedera.mirror.common.domain.schedule.Schedule) TOPIC(com.hedera.mirror.common.domain.entity.EntityType.TOPIC) NftId(com.hedera.mirror.common.domain.token.NftId) Contract(com.hedera.mirror.common.domain.contract.Contract) Supplier(java.util.function.Supplier) Scope(org.springframework.context.annotation.Scope) Value(lombok.Value) HashSet(java.util.HashSet) FILE(com.hedera.mirror.common.domain.entity.EntityType.FILE) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) EntityManager(javax.persistence.EntityManager) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) UnknownHostException(java.net.UnknownHostException) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Key(com.hederahashgraph.api.proto.java.Key) Component(org.springframework.stereotype.Component) Log4j2(lombok.extern.log4j.Log4j2) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) EthereumTransaction(com.hedera.mirror.common.domain.transaction.EthereumTransaction) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) HashSet(java.util.HashSet)

Example 13 with Timestamp

use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.

the class ProtoUtilTest method toTimestamp.

@DisplayName("Convert Instant to Timestamp")
@ParameterizedTest(name = "with {0}s and {1}ns")
@CsvSource({ "0, 0", "0, 999999999", "10, 0", "31556889864403199, 999999999", "-31557014167219200, 0" })
void toTimestamp(long seconds, int nanos) {
    Instant instant = Instant.ofEpochSecond(seconds, nanos);
    Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
    assertThat(ProtoUtil.toTimestamp(instant)).isEqualTo(timestamp);
}
Also used : Instant(java.time.Instant) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) CsvSource(org.junit.jupiter.params.provider.CsvSource) DisplayName(org.junit.jupiter.api.DisplayName) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Timestamp

use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.

the class ProtoUtilTest method fromTimestamp.

@DisplayName("Convert Timestamp to Instant")
@ParameterizedTest(name = "with {0}s and {1}ns")
@CsvSource({ "0, 0", "0, 999999999", "10, 0", "31556889864403199, 999999999", "-31557014167219200, 0" })
void fromTimestamp(long seconds, int nanos) {
    Instant instant = Instant.ofEpochSecond(seconds, nanos);
    Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
    assertThat(ProtoUtil.fromTimestamp(timestamp)).isEqualTo(instant);
}
Also used : Instant(java.time.Instant) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) CsvSource(org.junit.jupiter.params.provider.CsvSource) DisplayName(org.junit.jupiter.api.DisplayName) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with Timestamp

use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionHandlerTest method updateTransactionSuccessful.

@Test
void updateTransactionSuccessful() {
    RecordItem recordItem = recordItemBuilder.tokenUpdate().build();
    var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
    when(entityIdService.lookup(any(AccountID.class))).thenReturn(EntityIdEndec.decode(10, EntityType.ACCOUNT));
    transactionHandler.updateTransaction(transaction, recordItem);
    assertTokenUpdate(timestamp, tokenId, id -> assertEquals(10L, id));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) DomainUtils(com.hedera.mirror.common.util.DomainUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.when(org.mockito.Mockito.when) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Timestamp (com.hederahashgraph.api.proto.java.Timestamp)26 Test (org.junit.jupiter.api.Test)12 Instant (java.time.Instant)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EntityId (com.hedera.mirror.common.domain.entity.EntityId)5 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Consumer (java.util.function.Consumer)5 Range (com.google.common.collect.Range)4 Entity (com.hedera.mirror.common.domain.entity.Entity)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)4 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 AccountID (com.hederahashgraph.api.proto.java.AccountID)4 Duration (com.hederahashgraph.api.proto.java.Duration)4 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3