-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIP-1056 Topic block item to record item transformer (#10318)
Add block item to record item transformers for ConsensusCreateTopic and ConsensusSubmitMessage --------- Signed-off-by: filev94 <[email protected]>
- Loading branch information
Showing
6 changed files
with
404 additions
and
11 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
.../hedera/mirror/importer/downloader/block/transformer/ConsensusCreateTopicTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2025 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.mirror.importer.downloader.block.transformer; | ||
|
||
import com.hedera.hapi.block.stream.output.protoc.StateIdentifier; | ||
import com.hedera.mirror.common.domain.transaction.BlockItem; | ||
import com.hedera.mirror.common.domain.transaction.TransactionType; | ||
import com.hederahashgraph.api.proto.java.TransactionRecord; | ||
import jakarta.inject.Named; | ||
|
||
@Named | ||
final class ConsensusCreateTopicTransformer extends AbstractBlockItemTransformer { | ||
@Override | ||
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) { | ||
|
||
if (!blockItem.successful()) { | ||
return; | ||
} | ||
|
||
for (var stateChange : blockItem.stateChanges()) { | ||
for (var change : stateChange.getStateChangesList()) { | ||
if (change.getStateId() == StateIdentifier.STATE_ID_TOPICS.getNumber() && change.hasMapUpdate()) { | ||
var key = change.getMapUpdate().getKey(); | ||
if (key.hasTopicIdKey()) { | ||
transactionRecordBuilder.getReceiptBuilder().setTopicID(key.getTopicIdKey()); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public TransactionType getType() { | ||
return TransactionType.CONSENSUSCREATETOPIC; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...edera/mirror/importer/downloader/block/transformer/ConsensusSubmitMessageTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2025 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.mirror.importer.downloader.block.transformer; | ||
|
||
import static com.hedera.mirror.importer.util.Utility.DEFAULT_RUNNING_HASH_VERSION; | ||
|
||
import com.hedera.hapi.block.stream.output.protoc.StateIdentifier; | ||
import com.hedera.mirror.common.domain.transaction.BlockItem; | ||
import com.hedera.mirror.common.domain.transaction.TransactionType; | ||
import com.hederahashgraph.api.proto.java.TransactionRecord; | ||
import jakarta.inject.Named; | ||
|
||
@Named | ||
final class ConsensusSubmitMessageTransformer extends AbstractBlockItemTransformer { | ||
|
||
@Override | ||
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) { | ||
|
||
if (!blockItem.successful()) { | ||
return; | ||
} | ||
|
||
for (var transactionOutput : blockItem.transactionOutput()) { | ||
if (transactionOutput.hasSubmitMessage()) { | ||
var submitMessageOutput = transactionOutput.getSubmitMessage(); | ||
var assessedCustomFees = submitMessageOutput.getAssessedCustomFeesList(); | ||
transactionRecordBuilder.addAllAssessedCustomFees(assessedCustomFees); | ||
break; | ||
} | ||
} | ||
|
||
for (var stateChange : blockItem.stateChanges()) { | ||
for (var change : stateChange.getStateChangesList()) { | ||
if (change.getStateId() == StateIdentifier.STATE_ID_TOPICS.getNumber() && change.hasMapUpdate()) { | ||
var value = change.getMapUpdate().getValue(); | ||
if (value.hasTopicValue()) { | ||
var topicValue = value.getTopicValue(); | ||
transactionRecordBuilder | ||
.getReceiptBuilder() | ||
.setTopicRunningHash(topicValue.getRunningHash()) | ||
.setTopicSequenceNumber(topicValue.getSequenceNumber()) | ||
.setTopicRunningHashVersion(DEFAULT_RUNNING_HASH_VERSION); | ||
|
||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public TransactionType getType() { | ||
return TransactionType.CONSENSUSSUBMITMESSAGE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.