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

com.hedera.hapi.node.file.schema.FileCreateTransactionBodySchema Maven / Gradle / Ivy

package com.hedera.hapi.node.file.schema;

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


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

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

    /**
     * (2) The time at which this file should expire (unless FileUpdateTransaction is used before then
     * to extend its life)
     */
    public static final FieldDefinition EXPIRATION_TIME = new FieldDefinition("expirationTime", FieldType.MESSAGE, false, false, false, 2);


    /**
     * (3) All keys at the top level of a key list must sign to create or modify the file. Any one of
     * the keys at the top level key list can sign to delete the file.
     */
    public static final FieldDefinition KEYS = new FieldDefinition("keys", FieldType.MESSAGE, false, false, false, 3);


    /**
     * (4) The bytes that are the contents of the file
     */
    public static final FieldDefinition CONTENTS = new FieldDefinition("contents", FieldType.BYTES, false, false, false, 4);


    /**
     * (5) Shard in which this file is created
     */
    public static final FieldDefinition SHARD_ID = new FieldDefinition("shardID", FieldType.MESSAGE, false, false, false, 5);


    /**
     * (6) The Realm in which to the file is created (leave this null to create a new realm)
     */
    public static final FieldDefinition REALM_ID = new FieldDefinition("realmID", FieldType.MESSAGE, false, false, false, 6);


    /**
     * (7) If realmID is null, then this the admin key for the new realm that will be created
     */
    public static final FieldDefinition NEW_REALM_ADMIN_KEY = new FieldDefinition("newRealmAdminKey", FieldType.MESSAGE, false, false, false, 7);


    /**
     * (8) The memo associated with the file (UTF-8 encoding max 100 bytes)
     */
    public static final FieldDefinition MEMO = new FieldDefinition("memo", FieldType.STRING, false, false, false, 8);


    // -- 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 2 -> EXPIRATION_TIME;
            case 3 -> KEYS;
            case 4 -> CONTENTS;
            case 5 -> SHARD_ID;
            case 6 -> REALM_ID;
            case 7 -> NEW_REALM_ADMIN_KEY;
            case 8 -> MEMO;
	        default -> null;
	    };
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy