use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionThrowsWithAliasNotFound.
@ParameterizedTest(name = "{0}")
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "ERROR" })
void updateTransactionThrowsWithAliasNotFound(PartialDataAction partialDataAction) {
// given
recordParserProperties.setPartialDataAction(partialDataAction);
var alias = DomainUtils.fromBytes(domainBuilder.key());
var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).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(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
// when, then
assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.
the class ProtoBalanceFileReader method toFlux.
private Flux<AccountBalance> toFlux(StreamFileData streamFileData) {
return Flux.defer(() -> {
InputStream inputStream = streamFileData.getInputStream();
ExtensionRegistryLite extensionRegistry = ExtensionRegistryLite.getEmptyRegistry();
CodedInputStream input = CodedInputStream.newInstance(inputStream);
AtomicLong consensusTimestamp = new AtomicLong(0L);
UnknownFieldSet.Builder unknownFieldSet = UnknownFieldSet.newBuilder();
return Flux.<AccountBalance>generate(sink -> {
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch(tag) {
case TAG_EOF:
done = true;
break;
case TAG_TIMESTAMP:
Timestamp timestamp = input.readMessage(Timestamp.parser(), extensionRegistry);
consensusTimestamp.set(DomainUtils.timestampInNanosMax(timestamp));
break;
case TAG_BALANCE:
Assert.state(consensusTimestamp.get() > 0, "Missing consensus timestamp)");
var ab = input.readMessage(SingleAccountBalances.parser(), extensionRegistry);
sink.next(toAccountBalance(consensusTimestamp.get(), ab));
return;
default:
log.warn("Unsupported tag: {}", tag);
done = !unknownFieldSet.mergeFieldFrom(tag, input);
}
}
Assert.state(consensusTimestamp.get() > 0, "Missing consensus timestamp)");
sink.complete();
} catch (IOException e) {
sink.error(new StreamFileReaderException(e));
} catch (IllegalStateException e) {
sink.error(new InvalidStreamFileException(e));
}
}).doFinally(s -> IOUtils.closeQuietly(inputStream));
});
}
use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.
the class ConsensusUpdateTopicTransactionHandler method doUpdateEntity.
@Override
protected void doUpdateEntity(Entity entity, RecordItem recordItem) {
var transactionBody = recordItem.getTransactionBody().getConsensusUpdateTopic();
if (transactionBody.hasAutoRenewAccount()) {
getAccountId(transactionBody.getAutoRenewAccount()).map(EntityId::getId).ifPresent(entity::setAutoRenewAccountId);
}
if (transactionBody.hasAutoRenewPeriod()) {
entity.setAutoRenewPeriod(transactionBody.getAutoRenewPeriod().getSeconds());
}
if (transactionBody.hasExpirationTime()) {
Timestamp expirationTime = transactionBody.getExpirationTime();
entity.setExpirationTimestamp(DomainUtils.timestampInNanosMax(expirationTime));
}
if (transactionBody.hasAdminKey()) {
entity.setKey(transactionBody.getAdminKey().toByteArray());
}
if (transactionBody.hasMemo()) {
entity.setMemo(transactionBody.getMemo().getValue());
}
if (transactionBody.hasSubmitKey()) {
entity.setSubmitKey(transactionBody.getSubmitKey().toByteArray());
}
entityListener.onEntity(entity);
}
use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.
the class DomainUtilsTest method timeStampInNanosInvalid.
@Test
@DisplayName("converting illegal timestamp to nanos")
void timeStampInNanosInvalid() {
Timestamp timestamp = Timestamp.newBuilder().setSeconds(1568376750538L).setNanos(0).build();
assertThrows(ArithmeticException.class, () -> {
DomainUtils.timeStampInNanos(timestamp);
});
}
use of com.hederahashgraph.api.proto.java.Timestamp in project hedera-mirror-node by hashgraph.
the class DomainUtilsTest method timeStampInNanosTimeStamp.
@ParameterizedTest(name = "with seconds {0} and nanos {1}")
@CsvSource({ "1569936354, 901", "0, 901", "1569936354, 0", "0,0" })
void timeStampInNanosTimeStamp(long seconds, int nanos) {
Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
Long timeStampInNanos = DomainUtils.timeStampInNanos(timestamp);
assertThat(timeStampInNanos).isNotNull();
Instant fromTimeStamp = Instant.ofEpochSecond(0, timeStampInNanos);
assertAll(() -> assertEquals(timestamp.getSeconds(), fromTimeStamp.getEpochSecond()), () -> assertEquals(timestamp.getNanos(), fromTimeStamp.getNano()));
}
Aggregations