Search in sources :

Example 1 with ConsensusSubmitMessageTransactionBody

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();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) TopicID(com.hederahashgraph.api.proto.java.TopicID) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

Example 2 with ConsensusSubmitMessageTransactionBody

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);
}
Also used : ConsensusMessageChunkInfo(com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 3 with ConsensusSubmitMessageTransactionBody

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);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TopicID(com.hederahashgraph.api.proto.java.TopicID) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) TxnUtils.asTransactionID(com.hedera.services.bdd.spec.transactions.TxnUtils.asTransactionID) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) TxnUtils.asTopicId(com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusSubmitMessage(com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusSubmitMessage) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) SubmitMessageMeta(com.hedera.services.usage.consensus.SubmitMessageMeta) ConsensusMessageChunkInfo(com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) ConsensusMessageChunkInfo(com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo) TopicID(com.hederahashgraph.api.proto.java.TopicID) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)

Example 4 with ConsensusSubmitMessageTransactionBody

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();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) TopicID(com.hederahashgraph.api.proto.java.TopicID) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

Aggregations

ConsensusSubmitMessageTransactionBody (com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)4 TopicID (com.hederahashgraph.api.proto.java.TopicID)3 Transaction (com.hederahashgraph.api.proto.java.Transaction)3 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)2 ConsensusMessageChunkInfo (com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo)2 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)2 Test (org.junit.jupiter.api.Test)2 MoreObjects (com.google.common.base.MoreObjects)1 ByteString (com.google.protobuf.ByteString)1 TopicMessage (com.hedera.mirror.common.domain.topic.TopicMessage)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 AdapterUtils (com.hedera.services.bdd.spec.fees.AdapterUtils)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils.asTopicId (com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId)1 TxnUtils.asTransactionID (com.hedera.services.bdd.spec.transactions.TxnUtils.asTransactionID)1 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)1 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)1 SubmitMessageMeta (com.hedera.services.usage.consensus.SubmitMessageMeta)1