Search in sources :

Example 11 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-services by hashgraph.

the class HapiMessageSubmit method resolveTopicId.

private TopicID resolveTopicId(HapiApiSpec spec) {
    if (topicFn.isPresent()) {
        TopicID topicID = topicFn.get().apply(spec);
        topic = Optional.of(HapiPropertySource.asTopicString(topicID));
        return topicID;
    }
    if (topic.isPresent()) {
        return asTopicId(topic.get(), spec);
    }
    return TopicID.getDefaultInstance();
}
Also used : TopicID(com.hederahashgraph.api.proto.java.TopicID)

Example 12 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID 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 13 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-services by hashgraph.

the class HapiTopicDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    TopicID id = resolveTopicId(spec);
    ConsensusDeleteTopicTransactionBody opBody = spec.txns().<ConsensusDeleteTopicTransactionBody, ConsensusDeleteTopicTransactionBody.Builder>body(ConsensusDeleteTopicTransactionBody.class, b -> {
        b.setTopicID(id);
    });
    return b -> b.setConsensusDeleteTopic(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder) TopicID(com.hederahashgraph.api.proto.java.TopicID) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) ConsensusDeleteTopic(com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusDeleteTopic) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TxnUtils.asTopicId(com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) ConsensusDeleteTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusDeleteTopicTransactionBody) Optional(java.util.Optional) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ConsensusDeleteTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusDeleteTopicTransactionBody) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder) TopicID(com.hederahashgraph.api.proto.java.TopicID)

Example 14 with TopicID

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

the class EntityRecordItemListenerTopicTest method submitMessageTestFiltered.

@Test
void submitMessageTestFiltered() {
    // given
    var responseCode = SUCCESS;
    var topicId = (TopicID) new TopicIdArgumentConverter().convert("0.0.999", // excluded in application-default.yml
    null);
    var consensusTimestamp = 10_000_000L;
    var message = "message";
    var sequenceNumber = 10_000L;
    var runningHash = "running-hash";
    var runningHashVersion = 1;
    var chunkNum = 3;
    var chunkTotal = 5;
    var validStartNs = 7L;
    var scheduled = false;
    var nonce = 0;
    TransactionID initialTransactionId = createTransactionID(PAYER_ACCOUNT_ID.getEntityNum(), TestUtils.toTimestamp(validStartNs), scheduled, nonce);
    var transaction = createSubmitMessageTransaction(topicId, message, chunkNum, chunkTotal, initialTransactionId);
    var transactionRecord = createTransactionRecord(topicId, sequenceNumber, runningHash.getBytes(), runningHashVersion, consensusTimestamp, responseCode);
    // when
    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
    // then
    // if the transaction is filtered out, nothing in it should affect the state
    assertEquals(0L, entityRepository.count());
    assertEquals(0L, topicMessageRepository.count());
}
Also used : TopicIdArgumentConverter(com.hedera.mirror.importer.converter.TopicIdArgumentConverter) TopicID(com.hederahashgraph.api.proto.java.TopicID) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID 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

TopicID (com.hederahashgraph.api.proto.java.TopicID)16 Test (org.junit.jupiter.api.Test)9 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)5 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 Transaction (com.hederahashgraph.api.proto.java.Transaction)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 Consumer (java.util.function.Consumer)4 MoreObjects (com.google.common.base.MoreObjects)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 ConsensusSubmitMessageTransactionBody (com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Range (com.google.common.collect.Range)2 ByteString (com.google.protobuf.ByteString)2 Entity (com.hedera.mirror.common.domain.entity.Entity)2 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)2 EntityType (com.hedera.mirror.common.domain.entity.EntityType)2 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)2 TOPIC (com.hedera.mirror.common.domain.entity.EntityType.TOPIC)2