All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hedera.hapi.node.token.codec.TokenCreateTransactionBodyJsonCodec Maven / Gradle / Ivy

package com.hedera.hapi.node.token.codec;

import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import java.io.IOException;
import java.nio.*;
import java.nio.charset.*;
import java.util.*;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import com.hedera.hapi.node.token.TokenCreateTransactionBody;

import com.hedera.hapi.node.base.*;
import com.hedera.hapi.node.base.codec.*;
import com.hedera.hapi.node.token.*;
import com.hedera.hapi.node.token.schema.*;
import com.hedera.hapi.node.transaction.*;
import com.hedera.hapi.node.transaction.codec.*;
import com.hedera.pbj.runtime.io.buffer.*;
import java.util.*;

import com.hedera.pbj.runtime.jsonparser.*;
import static com.hedera.hapi.node.token.schema.TokenCreateTransactionBodySchema.*;
import static com.hedera.pbj.runtime.JsonTools.*;

/**
 * JSON Codec for TokenCreateTransactionBody model object. Generated based on protobuf schema.
 */
public final class TokenCreateTransactionBodyJsonCodec implements JsonCodec {
    

        /**
     * Parses a HashObject object from JSON parse tree for object JSONParser.ObjContext.
     * Throws an UnknownFieldException wrapped in a ParseException if in strict mode ONLY.
     *
     * @param root The JSON parsed object tree to parse data from
     * @return Parsed HashObject model object or null if data input was null or empty
     * @throws ParseException If parsing fails
     */
    public @NonNull TokenCreateTransactionBody parse(
            @Nullable final JSONParser.ObjContext root,
            final boolean strictMode,
            final int maxDepth) throws ParseException {
        if (maxDepth < 0) {
            throw new ParseException("Reached maximum allowed depth of nested messages");
        }
        try {
            // -- TEMP STATE FIELDS --------------------------------------
                String temp_name = "";
        String temp_symbol = "";
        int temp_decimals = 0;
        long temp_initialSupply = 0;
        AccountID temp_treasury = null;
        Key temp_adminKey = null;
        Key temp_kycKey = null;
        Key temp_freezeKey = null;
        Key temp_wipeKey = null;
        Key temp_supplyKey = null;
        boolean temp_freezeDefault = false;
        Timestamp temp_expiry = null;
        AccountID temp_autoRenewAccount = null;
        Duration temp_autoRenewPeriod = null;
        String temp_memo = "";
        TokenType temp_tokenType = TokenType.fromProtobufOrdinal(0);
        TokenSupplyType temp_supplyType = TokenSupplyType.fromProtobufOrdinal(0);
        long temp_maxSupply = 0;
        Key temp_fee_schedule_key = null;
        List temp_custom_fees = Collections.emptyList();
        Key temp_pause_key = null;
        Bytes temp_metadata = Bytes.EMPTY;
        Key temp_metadata_key = null;
    
            // -- EXTRACT VALUES FROM PARSE TREE ---------------------------------------------
    
            for (JSONParser.PairContext kvPair : root.pair()) {
                switch (kvPair.STRING().getText()) {
                    case "name" /* [1] */ : temp_name = unescape(kvPair.value().STRING().getText()); break;
    case "symbol" /* [2] */ : temp_symbol = unescape(kvPair.value().STRING().getText()); break;
    case "decimals" /* [3] */ : temp_decimals = parseInteger(kvPair.value()); break;
    case "initialSupply" /* [4] */ : temp_initialSupply = parseLong(kvPair.value()); break;
    case "treasury" /* [5] */ : temp_treasury = AccountID.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "adminKey" /* [6] */ : temp_adminKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "kycKey" /* [7] */ : temp_kycKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "freezeKey" /* [8] */ : temp_freezeKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "wipeKey" /* [9] */ : temp_wipeKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "supplyKey" /* [10] */ : temp_supplyKey = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "freezeDefault" /* [11] */ : temp_freezeDefault = parseBoolean(kvPair.value()); break;
    case "expiry" /* [13] */ : temp_expiry = Timestamp.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "autoRenewAccount" /* [14] */ : temp_autoRenewAccount = AccountID.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "autoRenewPeriod" /* [15] */ : temp_autoRenewPeriod = Duration.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "memo" /* [16] */ : temp_memo = unescape(kvPair.value().STRING().getText()); break;
    case "tokenType" /* [17] */ : temp_tokenType = TokenType.fromString(kvPair.value().STRING().getText()); break;
    case "supplyType" /* [18] */ : temp_supplyType = TokenSupplyType.fromString(kvPair.value().STRING().getText()); break;
    case "maxSupply" /* [19] */ : temp_maxSupply = parseLong(kvPair.value()); break;
    case "feeScheduleKey" /* [20] */ : temp_fee_schedule_key = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "customFees" /* [21] */ : temp_custom_fees = parseObjArray(kvPair.value().arr(), CustomFee.JSON, maxDepth - 1); break;
    case "pauseKey" /* [22] */ : temp_pause_key = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "metadata" /* [23] */ : temp_metadata = Bytes.fromBase64(kvPair.value().STRING().getText()); break;
    case "metadataKey" /* [24] */ : temp_metadata_key = Key.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    
                    default: {
                        if (strictMode) {
                            // Since we are parsing is strict mode, this is an exceptional condition.
                            throw new UnknownFieldException(kvPair.STRING().getText());
                        }
                    }
                }
            }
    
            return new TokenCreateTransactionBody(temp_name, temp_symbol, temp_decimals, temp_initialSupply, temp_treasury, temp_adminKey, temp_kycKey, temp_freezeKey, temp_wipeKey, temp_supplyKey, temp_freezeDefault, temp_expiry, temp_autoRenewAccount, temp_autoRenewPeriod, temp_memo, temp_tokenType, temp_supplyType, temp_maxSupply, temp_fee_schedule_key, temp_custom_fees, temp_pause_key, temp_metadata, temp_metadata_key);
        } catch (Exception ex) {
            throw new ParseException(ex);
        }
    }

        /**
     * Returns JSON string representing an item.
     *
     * @param data      The item to convert. Must not be null.
     * @param indent    The indent to use for pretty printing
     * @param inline    When true the output will start with indent end with a new line otherwise
     *                        it will just be the object "{...}"
     */
    @Override
    public String toJSON(@NonNull TokenCreateTransactionBody data, String indent, boolean inline) {
        StringBuilder sb = new StringBuilder();
        // start
        sb.append(inline ? "{\n" : indent + "{\n");
        final String childIndent = indent + INDENT;
        // collect field lines
        final List fieldLines = new ArrayList<>();
            // [1] - name
        if (data.name() != "") fieldLines.add(field("name", data.name()));
        // [2] - symbol
        if (data.symbol() != "") fieldLines.add(field("symbol", data.symbol()));
        // [3] - decimals
        if (data.decimals() != 0) fieldLines.add(field("decimals", data.decimals()));
        // [4] - initialSupply
        if (data.initialSupply() != 0) fieldLines.add(field("initialSupply", data.initialSupply()));
        // [5] - treasury
        if (data.treasury() != null) fieldLines.add(field(childIndent, "treasury", com.hedera.hapi.node.base.AccountID.JSON, data.treasury()));
        // [6] - adminKey
        if (data.adminKey() != null) fieldLines.add(field(childIndent, "adminKey", com.hedera.hapi.node.base.Key.JSON, data.adminKey()));
        // [7] - kycKey
        if (data.kycKey() != null) fieldLines.add(field(childIndent, "kycKey", com.hedera.hapi.node.base.Key.JSON, data.kycKey()));
        // [8] - freezeKey
        if (data.freezeKey() != null) fieldLines.add(field(childIndent, "freezeKey", com.hedera.hapi.node.base.Key.JSON, data.freezeKey()));
        // [9] - wipeKey
        if (data.wipeKey() != null) fieldLines.add(field(childIndent, "wipeKey", com.hedera.hapi.node.base.Key.JSON, data.wipeKey()));
        // [10] - supplyKey
        if (data.supplyKey() != null) fieldLines.add(field(childIndent, "supplyKey", com.hedera.hapi.node.base.Key.JSON, data.supplyKey()));
        // [11] - freezeDefault
        if (data.freezeDefault() != false) fieldLines.add(field("freezeDefault", data.freezeDefault()));
        // [13] - expiry
        if (data.expiry() != null) fieldLines.add(field(childIndent, "expiry", com.hedera.hapi.node.base.Timestamp.JSON, data.expiry()));
        // [14] - autoRenewAccount
        if (data.autoRenewAccount() != null) fieldLines.add(field(childIndent, "autoRenewAccount", com.hedera.hapi.node.base.AccountID.JSON, data.autoRenewAccount()));
        // [15] - autoRenewPeriod
        if (data.autoRenewPeriod() != null) fieldLines.add(field(childIndent, "autoRenewPeriod", com.hedera.hapi.node.base.Duration.JSON, data.autoRenewPeriod()));
        // [16] - memo
        if (data.memo() != "") fieldLines.add(field("memo", data.memo()));
        // [17] - tokenType
        if (data.tokenType() != TokenType.fromProtobufOrdinal(0)) fieldLines.add(field("tokenType", data.tokenType().protoName()));
        // [18] - supplyType
        if (data.supplyType() != TokenSupplyType.fromProtobufOrdinal(0)) fieldLines.add(field("supplyType", data.supplyType().protoName()));
        // [19] - maxSupply
        if (data.maxSupply() != 0) fieldLines.add(field("maxSupply", data.maxSupply()));
        // [20] - fee_schedule_key
        if (data.feeScheduleKey() != null) fieldLines.add(field(childIndent, "feeScheduleKey", com.hedera.hapi.node.base.Key.JSON, data.feeScheduleKey()));
        // [21] - custom_fees
        if (!data.customFees().isEmpty()) fieldLines.add(arrayField(childIndent, "customFees", com.hedera.hapi.node.transaction.CustomFee.JSON, data.customFees()));
        // [22] - pause_key
        if (data.pauseKey() != null) fieldLines.add(field(childIndent, "pauseKey", com.hedera.hapi.node.base.Key.JSON, data.pauseKey()));
        // [23] - metadata
        if (data.metadata() != Bytes.EMPTY && data.metadata() != null && data.metadata().length() > 0) fieldLines.add(field("metadata", data.metadata()));
        // [24] - metadata_key
        if (data.metadataKey() != null) fieldLines.add(field(childIndent, "metadataKey", com.hedera.hapi.node.base.Key.JSON, data.metadataKey()));
    
        // write field lines
        if (!fieldLines.isEmpty()){
            sb.append(childIndent);
            sb.append(String.join(",\n"+childIndent, fieldLines));
            sb.append("\n");
        }
        // end
        sb.append(indent + "}");
        return sb.toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy