use of com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody in project hedera-mirror-node by hashgraph.
the class PubSubRecordItemListenerTest method testPubSubMessageNullEntityId.
@Test
void testPubSubMessageNullEntityId() throws Exception {
// given
byte[] message = new byte[] { 'a', 'b', 'c' };
TopicID topicID = TopicID.newBuilder().setTopicNum(10L).build();
EntityId topicIdEntity = EntityId.of(topicID);
ConsensusSubmitMessageTransactionBody submitMessage = ConsensusSubmitMessageTransactionBody.newBuilder().setMessage(ByteString.copyFrom(message)).setTopicID(topicID).build();
Transaction transaction = buildTransaction(builder -> builder.setConsensusSubmitMessage(submitMessage));
// when
doReturn(null).when(transactionHandler).getEntity(any());
pubSubRecordItemListener.onItem(new RecordItem(transaction, DEFAULT_RECORD));
// then
var pubSubMessage = assertPubSubMessage(buildPubSubTransaction(transaction), 1);
assertThat(pubSubMessage.getEntity()).isEqualTo(null);
assertThat(pubSubMessage.getNonFeeTransfers()).isNull();
}
use of com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertConsensusTopicMessage.
private void insertConsensusTopicMessage(RecordItem recordItem) {
if (!entityProperties.getPersist().isTopics()) {
return;
}
ConsensusSubmitMessageTransactionBody transactionBody = recordItem.getTransactionBody().getConsensusSubmitMessage();
TransactionRecord transactionRecord = recordItem.getRecord();
var receipt = transactionRecord.getReceipt();
var topicId = transactionBody.getTopicID();
int runningHashVersion = receipt.getTopicRunningHashVersion() == 0 ? 1 : (int) receipt.getTopicRunningHashVersion();
TopicMessage topicMessage = new TopicMessage();
// Handle optional fragmented topic message
if (transactionBody.hasChunkInfo()) {
ConsensusMessageChunkInfo chunkInfo = transactionBody.getChunkInfo();
topicMessage.setChunkNum(chunkInfo.getNumber());
topicMessage.setChunkTotal(chunkInfo.getTotal());
if (chunkInfo.hasInitialTransactionID()) {
topicMessage.setInitialTransactionId(chunkInfo.getInitialTransactionID().toByteArray());
}
}
topicMessage.setConsensusTimestamp(DomainUtils.timeStampInNanos(transactionRecord.getConsensusTimestamp()));
topicMessage.setMessage(DomainUtils.toBytes(transactionBody.getMessage()));
topicMessage.setPayerAccountId(recordItem.getPayerAccountId());
topicMessage.setRunningHash(DomainUtils.toBytes(receipt.getTopicRunningHash()));
topicMessage.setRunningHashVersion(runningHashVersion);
topicMessage.setSequenceNumber(receipt.getTopicSequenceNumber());
topicMessage.setTopicId(EntityId.of(topicId));
entityListener.onTopicMessage(topicMessage);
}
use of com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody in project hedera-services by hashgraph.
the class HapiMessageSubmit method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
TopicID id = resolveTopicId(spec);
ConsensusSubmitMessageTransactionBody opBody = spec.txns().<ConsensusSubmitMessageTransactionBody, ConsensusSubmitMessageTransactionBody.Builder>body(ConsensusSubmitMessageTransactionBody.class, b -> {
b.setTopicID(id);
message.ifPresent(m -> b.setMessage(m));
if (clearMessage) {
b.clearMessage();
}
if (totalChunks.isPresent() && chunkNumber.isPresent()) {
ConsensusMessageChunkInfo chunkInfo = ConsensusMessageChunkInfo.newBuilder().setInitialTransactionID(initialTransactionID.orElse(asTransactionID(spec, initialTransactionPayer.isPresent() ? initialTransactionPayer : payer))).setTotal(totalChunks.getAsInt()).setNumber(chunkNumber.getAsInt()).build();
b.setChunkInfo(chunkInfo);
spec.registry().saveTimestamp(txnName, chunkInfo.getInitialTransactionID().getTransactionValidStart());
}
});
return b -> b.setConsensusSubmitMessage(opBody);
}
use of com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody in project hedera-mirror-node by hashgraph.
the class PubSubRecordItemListenerTest method testPubSubMessage.
@Test
void testPubSubMessage() throws Exception {
// given
byte[] message = new byte[] { 'a', 'b', 'c' };
TopicID topicID = TopicID.newBuilder().setTopicNum(10L).build();
EntityId topicIdEntity = EntityId.of(topicID);
ConsensusSubmitMessageTransactionBody submitMessage = ConsensusSubmitMessageTransactionBody.newBuilder().setMessage(ByteString.copyFrom(message)).setTopicID(topicID).build();
Transaction transaction = buildTransaction(builder -> builder.setConsensusSubmitMessage(submitMessage));
// when
doReturn(topicIdEntity).when(transactionHandler).getEntity(any());
pubSubRecordItemListener.onItem(new RecordItem(transaction, DEFAULT_RECORD));
// then
var pubSubMessage = assertPubSubMessage(buildPubSubTransaction(transaction), 1);
assertThat(pubSubMessage.getEntity()).isEqualTo(topicIdEntity);
assertThat(pubSubMessage.getNonFeeTransfers()).isNull();
}
Aggregations