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