Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIP-1056 Add token blockitem to recorditem transformers #10354

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/design/block-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,7 @@ Beginning from an `EventTransaction` block item, a record item is composed of on
| token_airdrop.token_id (fungible) | state_changes[i].state_change.map_update.key.tokenReference.fungible_token_type |
| token_airdrop.token_id (nft) | state_changes[i].state_change.map_update.key.tokenReference.non_fungible_token.nftId.tokenId |
| assessed_custom_fee | Similar to crypto_transfer, retrieved from transaction_output.token_airdrop |
| token_account.account_id | transaction_output.token_airdrop.automatic_token_associations[i].accountId |
| token_account.token_id | transaction_output.token_airdrop.automatic_token_associations[i].tokenId |
| token_transfer.account_id | transaction_output.token_airdrop.token_transfer_lists[i].transfers[j].accountAmount.accountID |
| token_transfer.amount | transaction_output.token_airdrop.token_transfer_lists[i].transfers[j].accountAmount.amount |
| token_transfer.consensus_timestamp | transaction_result.consensus_timestamp |
| token_transfer.is_approval | transaction_output.token_airdrop.token_transfer_lists[i].transfers[j].accountAmount.isApproval |
| token_transfer.token_id | transaction_output.token_airdrop.token_transfer_lists[i].token.tokenID |

### Token Create Transaction

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_PENDING_AIRDROPS;

import com.hedera.mirror.common.domain.transaction.BlockItem;
import com.hedera.mirror.common.domain.transaction.TransactionType;
import com.hederahashgraph.api.proto.java.PendingAirdropId.TokenReferenceCase;
import com.hederahashgraph.api.proto.java.PendingAirdropRecord;
import com.hederahashgraph.api.proto.java.TransactionRecord;
import jakarta.inject.Named;

@Named
final class TokenAirdropTransformer extends AbstractBlockItemTransformer {

@SuppressWarnings("java:S3776")
@Override
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) {
if (!blockItem.successful()) {
return;
}

for (var stateChanges : blockItem.stateChanges()) {
for (var stateChange : stateChanges.getStateChangesList()) {
if (stateChange.getStateId() == STATE_ID_PENDING_AIRDROPS.getNumber() && stateChange.hasMapUpdate()) {
var mapUpdate = stateChange.getMapUpdate();
var key = mapUpdate.getKey();
if (key.hasPendingAirdropIdKey()) {
var pendingId = key.getPendingAirdropIdKey();
var pendingAirdrop = PendingAirdropRecord.newBuilder().setPendingAirdropId(pendingId);
if (pendingId.getTokenReferenceCase() == TokenReferenceCase.FUNGIBLE_TOKEN_TYPE) {
var value = mapUpdate.getValue();
if (value.hasAccountPendingAirdropValue()) {
var accountValue = value.getAccountPendingAirdropValue();
if (accountValue.hasPendingAirdropValue()) {
pendingAirdrop.setPendingAirdropValue(accountValue.getPendingAirdropValue());
}
}
}

transactionRecordBuilder.addNewPendingAirdrops(pendingAirdrop);
}
}
}
}

for (var transactionOutput : blockItem.transactionOutput()) {
if (transactionOutput.hasTokenAirdrop()) {
var output = transactionOutput.getTokenAirdrop();
var assessedCustomFees = output.getAssessedCustomFeesList();
transactionRecordBuilder.addAllAssessedCustomFees(assessedCustomFees);
}
}
}

@Override
public TransactionType getType() {
return TransactionType.TOKENAIRDROP;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_TOKENS;

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 TokenBurnTransformer extends AbstractBlockItemTransformer {

@SuppressWarnings("java:S3776")
@Override
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) {
if (!blockItem.successful()) {
return;
}

for (var stateChanges : blockItem.stateChanges()) {
for (var stateChange : stateChanges.getStateChangesList()) {
if (stateChange.getStateId() == STATE_ID_TOKENS.getNumber() && stateChange.hasMapUpdate()) {
var mapUpdate = stateChange.getMapUpdate();
if (mapUpdate.getKey().hasTokenIdKey()) {
var value = mapUpdate.getValue();
if (value.hasTokenValue()) {
var totalSupply = value.getTokenValue().getTotalSupply();
transactionRecordBuilder.getReceiptBuilder().setNewTotalSupply(totalSupply);
return;
}
}
}
}
}
}

Check warning on line 51 in hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/downloader/block/transformer/TokenBurnTransformer.java

View check run for this annotation

Codecov / codecov/patch

hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/downloader/block/transformer/TokenBurnTransformer.java#L49-L51

Added lines #L49 - L51 were not covered by tests

@Override
public TransactionType getType() {
return TransactionType.TOKENBURN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_TOKENS;

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 TokenCreateTransformer extends AbstractBlockItemTransformer {

@Override
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) {
if (!blockItem.successful()) {
return;
}

for (var stateChanges : blockItem.stateChanges()) {
for (var stateChange : stateChanges.getStateChangesList()) {
if (stateChange.getStateId() == STATE_ID_TOKENS.getNumber() && stateChange.hasMapUpdate()) {
var key = stateChange.getMapUpdate().getKey();
if (key.hasTokenIdKey()) {
transactionRecordBuilder.getReceiptBuilder().setTokenID(key.getTokenIdKey());
return;
}
}
}
}
}

Check warning on line 46 in hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/downloader/block/transformer/TokenCreateTransformer.java

View check run for this annotation

Codecov / codecov/patch

hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/downloader/block/transformer/TokenCreateTransformer.java#L44-L46

Added lines #L44 - L46 were not covered by tests

@Override
public TransactionType getType() {
return TransactionType.TOKENCREATION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_NFTS;
import static com.hedera.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_TOKENS;

import com.hedera.hapi.block.stream.output.protoc.MapUpdateChange;
import com.hedera.mirror.common.domain.transaction.BlockItem;
import com.hedera.mirror.common.domain.transaction.TransactionType;
import com.hederahashgraph.api.proto.java.TransactionReceipt;
import com.hederahashgraph.api.proto.java.TransactionRecord;
import jakarta.inject.Named;

@Named
final class TokenMintTransformer extends AbstractBlockItemTransformer {

@SuppressWarnings("java:S3776")
@Override
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) {
if (!blockItem.successful()) {
return;
}

var receiptBuilder = transactionRecordBuilder.getReceiptBuilder();
for (var stateChanges : blockItem.stateChanges()) {
for (var stateChange : stateChanges.getStateChangesList()) {
if (stateChange.hasMapUpdate()) {
var mapUpdate = stateChange.getMapUpdate();
if (stateChange.getStateId() == STATE_ID_TOKENS.getNumber()) {
if (setSupply(mapUpdate, receiptBuilder)) {
return;
}
} else if (stateChange.getStateId() == STATE_ID_NFTS.getNumber()) {
var key = mapUpdate.getKey();
if (key.hasNftIdKey()) {
receiptBuilder.addSerialNumbers(key.getNftIdKey().getSerialNumber());
setSupply(mapUpdate, receiptBuilder);
}
}
}
}
}
}

private boolean setSupply(MapUpdateChange mapUpdate, TransactionReceipt.Builder receiptBuilder) {
if (mapUpdate.hasValue()) {
var value = mapUpdate.getValue();
if (value.hasTokenValue()) {
receiptBuilder.setNewTotalSupply(value.getTokenValue().getTotalSupply());
return true;
}
}

return false;
}

@Override
public TransactionType getType() {
return TransactionType.TOKENMINT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_NFTS;
import static com.hedera.hapi.block.stream.output.protoc.StateIdentifier.STATE_ID_TOKENS;

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 TokenWipeTransformer extends AbstractBlockItemTransformer {

@SuppressWarnings("java:S3776")
@Override
protected void updateTransactionRecord(BlockItem blockItem, TransactionRecord.Builder transactionRecordBuilder) {
if (!blockItem.successful()) {
return;
}

var receiptBuilder = transactionRecordBuilder.getReceiptBuilder();
for (var stateChanges : blockItem.stateChanges()) {
for (var stateChange : stateChanges.getStateChangesList()) {
if (stateChange.hasMapUpdate()
&& (stateChange.getStateId() == STATE_ID_TOKENS.getNumber()
|| stateChange.getStateId() == STATE_ID_NFTS.getNumber())) {
var mapUpdate = stateChange.getMapUpdate();
if (mapUpdate.hasValue()) {
var value = mapUpdate.getValue();
if (value.hasTokenValue()) {
receiptBuilder.setNewTotalSupply(
value.getTokenValue().getTotalSupply());
return;
}
}
}
}
}
}

Check warning on line 55 in hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/downloader/block/transformer/TokenWipeTransformer.java

View check run for this annotation

Codecov / codecov/patch

hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/downloader/block/transformer/TokenWipeTransformer.java#L53-L55

Added lines #L53 - L55 were not covered by tests

@Override
public TransactionType getType() {
return TransactionType.TOKENWIPE;
}
}
Loading
Loading