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

com.hedera.hapi.node.token.schema.LiveHashSchema Maven / Gradle / Ivy

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

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


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

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

    /**
     * (1) The account to which the livehash is attached
     */
    public static final FieldDefinition ACCOUNT_ID = new FieldDefinition("accountId", FieldType.MESSAGE, false, false, false, 1);


    /**
     * (2) The SHA-384 hash of a credential or certificate
     */
    public static final FieldDefinition HASH = new FieldDefinition("hash", FieldType.BYTES, false, false, false, 2);


    /**
     * (3) A list of keys (primitive or threshold), all of which must sign to attach the livehash to an account, and any one of which can later delete it.
     */
    public static final FieldDefinition KEYS = new FieldDefinition("keys", FieldType.MESSAGE, false, false, false, 3);


    /**
     * (5) The duration for which the livehash will remain valid
     */
    public static final FieldDefinition DURATION = new FieldDefinition("duration", FieldType.MESSAGE, false, false, false, 5);


    // -- 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 -> ACCOUNT_ID;
            case 2 -> HASH;
            case 3 -> KEYS;
            case 5 -> DURATION;
	        default -> null;
	    };
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy