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

com.hedera.hapi.node.base.schema.TokenTransferListSchema Maven / Gradle / Ivy

There is a newer version: 0.54.0
Show newest version
package com.hedera.hapi.node.base.schema;

import com.hedera.pbj.runtime.FieldDefinition;
import com.hedera.pbj.runtime.FieldType;
import com.hedera.pbj.runtime.Schema;


/**
 * Schema for TokenTransferList model object. Generate based on protobuf schema.
 */
public final class TokenTransferListSchema implements Schema {

    // -- FIELD DEFINITIONS ---------------------------------------------

    /**
     * (1) The ID of the token
     */
    public static final FieldDefinition TOKEN = new FieldDefinition("token", FieldType.MESSAGE, false, false, false, 1);


    /**
     * (2) Applicable to tokens of type FUNGIBLE_COMMON. Multiple list of AccountAmounts, each of which
     * has an account and amount
     */
    public static final FieldDefinition TRANSFERS = new FieldDefinition("transfers", FieldType.MESSAGE, true, false, false, 2);


    /**
     * (3) Applicable to tokens of type NON_FUNGIBLE_UNIQUE. Multiple list of NftTransfers, each of
     * which has a sender and receiver account, including the serial number of the NFT
     */
    public static final FieldDefinition NFT_TRANSFERS = new FieldDefinition("nftTransfers", FieldType.MESSAGE, true, false, false, 3);


    /**
     * (4) If present, the number of decimals this fungible token type is expected to have. The transfer
     * will fail with UNEXPECTED_TOKEN_DECIMALS if the actual decimals differ.
     */
    public static final FieldDefinition EXPECTED_DECIMALS = new FieldDefinition("expected_decimals", FieldType.UINT32, false, true, false, 4);


    // -- OTHER METHODS -------------------------------------------------

    /**
     * Check if a field definition belongs to this schema.
     *
     * @param f field def to check
     * @return true if it belongs to this schema
     */
    public static boolean valid(FieldDefinition f) {
    	return f != null && getField(f.number()) == f;
    }

	/**
	 * Get a field definition given a field number
	 *
	 * @param fieldNumber the fields number to get def for
	 * @return field def or null if field number does not exist
	 */
	public static FieldDefinition getField(final int fieldNumber) {
	    return switch(fieldNumber) {
	        case 1 -> TOKEN;
            case 2 -> TRANSFERS;
            case 3 -> NFT_TRANSFERS;
            case 4 -> EXPECTED_DECIMALS;
	        default -> null;
	    };
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy