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

com.hedera.hapi.node.contract.ContractDeleteTransactionBody Maven / Gradle / Ivy

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

import com.hedera.hapi.node.base.*;
import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import com.hedera.pbj.runtime.io.stream.*;
import edu.umd.cs.findbugs.annotations.*;

import com.hedera.pbj.runtime.Codec;
import java.util.function.Consumer;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.NonNull;
import static java.util.Objects.requireNonNull;

/**
 * At consensus, marks a contract as deleted and transfers its remaining hBars, if any, to a
 * designated receiver. After a contract is deleted, it can no longer be called.
 * 

* If the target contract is immutable (that is, was created without an admin key), then this * transaction resolves to MODIFYING_IMMUTABLE_CONTRACT. *

* --- Signing Requirements --- * 1. The admin key of the target contract must sign. * 2. If the transfer account or contract has receiverSigRequired, its associated key must also sign * * @param contractID (1) The id of the contract to be deleted * @param obtainers (2, 3) * @param permanentRemoval (4) If set to true, means this is a "synthetic" system transaction being used to * alert mirror nodes that the contract is being permanently removed from the ledger. * IMPORTANT: User transactions cannot set this field to true, as permanent * removal is always managed by the ledger itself. Any ContractDeleteTransactionBody * submitted to HAPI with permanent_removal=true will be rejected with precheck status * PERMANENT_REMOVAL_REQUIRES_SYSTEM_INITIATION. */ public record ContractDeleteTransactionBody( @Nullable ContractID contractID, OneOf obtainers, boolean permanentRemoval ) { /** Protobuf codec for reading and writing in protobuf format */ public static final Codec PROTOBUF = new com.hedera.hapi.node.contract.codec.ContractDeleteTransactionBodyProtoCodec(); /** JSON codec for reading and writing in JSON format */ public static final JsonCodec JSON = new com.hedera.hapi.node.contract.codec.ContractDeleteTransactionBodyJsonCodec(); /** Default instance with all fields set to default values */ public static final ContractDeleteTransactionBody DEFAULT = newBuilder().build(); /** * Create a pre-populated ContractDeleteTransactionBody. * * @param contractID (1) The id of the contract to be deleted, * @param obtainers (2, 3) , * @param permanentRemoval (4) If set to true, means this is a "synthetic" system transaction being used to * alert mirror nodes that the contract is being permanently removed from the ledger. * IMPORTANT: User transactions cannot set this field to true, as permanent * removal is always managed by the ledger itself. Any ContractDeleteTransactionBody * submitted to HAPI with permanent_removal=true will be rejected with precheck status * PERMANENT_REMOVAL_REQUIRES_SYSTEM_INITIATION. */ public ContractDeleteTransactionBody(ContractID contractID, OneOf obtainers, boolean permanentRemoval) { this.contractID = contractID; if (obtainers == null) { throw new NullPointerException("Parameter 'obtainers' must be supplied and can not be null"); } this.obtainers = obtainers; this.permanentRemoval = permanentRemoval; } /** * Override the default hashCode method for * all other objects to make hashCode */ @Override public int hashCode() { int result = 1; if (contractID != null && !contractID.equals(DEFAULT.contractID)) { result = 31 * result + contractID.hashCode(); } if (obtainers != null && !obtainers.equals(DEFAULT.obtainers)) { result = 31 * result + obtainers.hashCode(); } if (permanentRemoval != DEFAULT.permanentRemoval) { result = 31 * result + Boolean.hashCode(permanentRemoval); } long hashCode = result; // Shifts: 30, 27, 16, 20, 5, 18, 10, 24, 30 hashCode += hashCode << 30; hashCode ^= hashCode >>> 27; hashCode += hashCode << 16; hashCode ^= hashCode >>> 20; hashCode += hashCode << 5; hashCode ^= hashCode >>> 18; hashCode += hashCode << 10; hashCode ^= hashCode >>> 24; hashCode += hashCode << 30; return (int)hashCode; } /** * Override the default equals method for */ @Override public boolean equals(Object that) { if (that == null || this.getClass() != that.getClass()) { return false; } ContractDeleteTransactionBody thatObj = (ContractDeleteTransactionBody)that; if (contractID == null && thatObj.contractID != null) { return false; } if (contractID != null && !contractID.equals(thatObj.contractID)) { return false; } if (obtainers == null && thatObj.obtainers != null) { return false; } if (obtainers != null && !obtainers.equals(thatObj.obtainers)) { return false; } if (permanentRemoval != thatObj.permanentRemoval) { return false; } return true; } /** * Convenience method to check if the contractID has a value * * @return true of the contractID has a value */ public boolean hasContractID() { return contractID != null; } /** * Gets the value for contractID if it has a value, or else returns the default * value for the type. * * @param defaultValue the default value to return if contractID is null * @return the value for contractID if it has a value, or else returns the default value */ public ContractID contractIDOrElse(@NonNull final ContractID defaultValue) { return hasContractID() ? contractID : defaultValue; } /** * Gets the value for contractID if it has a value, or else throws an NPE. * value for the type. * * @return the value for contractID if it has a value * @throws NullPointerException if contractID is null */ public @NonNull ContractID contractIDOrThrow() { return requireNonNull(contractID, "Field contractID is null"); } /** * Executes the supplied {@link Consumer} if, and only if, the contractID has a value * * @param ifPresent the {@link Consumer} to execute */ public void ifContractID(@NonNull final Consumer ifPresent) { if (hasContractID()) { ifPresent.accept(contractID); } } /** * Direct typed getter for one of field transferAccountID. * * @return one of value or null if one of is not set or a different one of value */ public @Nullable AccountID transferAccountID() { return obtainers.kind() == ObtainersOneOfType.TRANSFER_ACCOUNT_ID ? (AccountID)obtainers.value() : null; } /** * Convenience method to check if the obtainers has a one-of with type TRANSFER_ACCOUNT_ID * * @return true of the one of kind is TRANSFER_ACCOUNT_ID */ public boolean hasTransferAccountID() { return obtainers.kind() == ObtainersOneOfType.TRANSFER_ACCOUNT_ID; } /** * Gets the value for transferAccountID if it has a value, or else returns the default * value for the type. * * @param defaultValue the default value to return if transferAccountID is null * @return the value for transferAccountID if it has a value, or else returns the default value */ public AccountID transferAccountIDOrElse(@NonNull final AccountID defaultValue) { return hasTransferAccountID() ? transferAccountID() : defaultValue; } /** * Gets the value for transferAccountID if it was set, or throws a NullPointerException if it was not set. * * @return the value for transferAccountID if it has a value * @throws NullPointerException if transferAccountID is null */ public @NonNull AccountID transferAccountIDOrThrow() { return requireNonNull(transferAccountID(), "Field transferAccountID is null"); } /** * Direct typed getter for one of field transferContractID. * * @return one of value or null if one of is not set or a different one of value */ public @Nullable ContractID transferContractID() { return obtainers.kind() == ObtainersOneOfType.TRANSFER_CONTRACT_ID ? (ContractID)obtainers.value() : null; } /** * Convenience method to check if the obtainers has a one-of with type TRANSFER_CONTRACT_ID * * @return true of the one of kind is TRANSFER_CONTRACT_ID */ public boolean hasTransferContractID() { return obtainers.kind() == ObtainersOneOfType.TRANSFER_CONTRACT_ID; } /** * Gets the value for transferContractID if it has a value, or else returns the default * value for the type. * * @param defaultValue the default value to return if transferContractID is null * @return the value for transferContractID if it has a value, or else returns the default value */ public ContractID transferContractIDOrElse(@NonNull final ContractID defaultValue) { return hasTransferContractID() ? transferContractID() : defaultValue; } /** * Gets the value for transferContractID if it was set, or throws a NullPointerException if it was not set. * * @return the value for transferContractID if it has a value * @throws NullPointerException if transferContractID is null */ public @NonNull ContractID transferContractIDOrThrow() { return requireNonNull(transferContractID(), "Field transferContractID is null"); } /** * Return a builder for building a copy of this model object. It will be pre-populated with all the data from this * model object. * * @return a pre-populated builder */ public Builder copyBuilder() { return new Builder(contractID, obtainers, permanentRemoval); } /** * Return a new builder for building a model object. This is just a shortcut for new Model.Builder(). * * @return a new builder */ public static Builder newBuilder() { return new Builder(); } /** * Builder class for easy creation, ideal for clean code where performance is not critical. In critical performance * paths use the constructor directly. */ public static final class Builder { @Nullable private ContractID contractID = null; private OneOf obtainers = com.hedera.hapi.node.contract.codec.ContractDeleteTransactionBodyProtoCodec.OBTAINERS_UNSET; private boolean permanentRemoval = false; /** * Create an empty builder */ public Builder() {} /** * Create a pre-populated Builder. * * @param contractID (1) The id of the contract to be deleted, * @param obtainers (2, 3) , * @param permanentRemoval (4) If set to true, means this is a "synthetic" system transaction being used to * alert mirror nodes that the contract is being permanently removed from the ledger. * IMPORTANT: User transactions cannot set this field to true, as permanent * removal is always managed by the ledger itself. Any ContractDeleteTransactionBody * submitted to HAPI with permanent_removal=true will be rejected with precheck status * PERMANENT_REMOVAL_REQUIRES_SYSTEM_INITIATION. */ public Builder(ContractID contractID, OneOf obtainers, boolean permanentRemoval) { this.contractID = contractID; this.obtainers = obtainers; this.permanentRemoval = permanentRemoval; } /** * Build a new model record with data set on builder * * @return new model record with data set */ public ContractDeleteTransactionBody build() { return new ContractDeleteTransactionBody(contractID, obtainers, permanentRemoval); } /** * (1) The id of the contract to be deleted * * @param contractID value to set * @return builder to continue building with */ public Builder contractID(@Nullable ContractID contractID) { this.contractID = contractID; return this; } /** * (1) The id of the contract to be deleted * * @param builder A pre-populated builder * @return builder to continue building with */ public Builder contractID(ContractID.Builder builder) { this.contractID = builder.build() ; return this; } /** * (2) The id of an account to receive any remaining hBars from the deleted contract * * @param transferAccountID value to set * @return builder to continue building with */ public Builder transferAccountID(@Nullable AccountID transferAccountID) { this.obtainers = new OneOf<>(ContractDeleteTransactionBody.ObtainersOneOfType.TRANSFER_ACCOUNT_ID,transferAccountID); return this; } /** * (2) The id of an account to receive any remaining hBars from the deleted contract * * @param builder A pre-populated builder * @return builder to continue building with */ public Builder transferAccountID(AccountID.Builder builder) { this.obtainers = new OneOf<>(ContractDeleteTransactionBody.ObtainersOneOfType.TRANSFER_ACCOUNT_ID, builder.build() ); return this; } /** * (3) The id of a contract to receive any remaining hBars from the deleted contract * * @param transferContractID value to set * @return builder to continue building with */ public Builder transferContractID(@Nullable ContractID transferContractID) { this.obtainers = new OneOf<>(ContractDeleteTransactionBody.ObtainersOneOfType.TRANSFER_CONTRACT_ID,transferContractID); return this; } /** * (3) The id of a contract to receive any remaining hBars from the deleted contract * * @param builder A pre-populated builder * @return builder to continue building with */ public Builder transferContractID(ContractID.Builder builder) { this.obtainers = new OneOf<>(ContractDeleteTransactionBody.ObtainersOneOfType.TRANSFER_CONTRACT_ID, builder.build() ); return this; } /** * (4) If set to true, means this is a "synthetic" system transaction being used to * alert mirror nodes that the contract is being permanently removed from the ledger. * IMPORTANT: User transactions cannot set this field to true, as permanent * removal is always managed by the ledger itself. Any ContractDeleteTransactionBody * submitted to HAPI with permanent_removal=true will be rejected with precheck status * PERMANENT_REMOVAL_REQUIRES_SYSTEM_INITIATION. * * @param permanentRemoval value to set * @return builder to continue building with */ public Builder permanentRemoval(boolean permanentRemoval) { this.permanentRemoval = permanentRemoval; return this; } } /** * Enum for the type of "obtainers" oneof value */ public enum ObtainersOneOfType implements com.hedera.pbj.runtime.EnumWithProtoMetadata { /** * Enum value for a unset OneOf, to avoid null OneOfs */ UNSET(-1, "UNSET"), /**(2) The id of an account to receive any remaining hBars from the deleted contract */ TRANSFER_ACCOUNT_ID(2, "transferAccountID"), /**(3) The id of a contract to receive any remaining hBars from the deleted contract */ TRANSFER_CONTRACT_ID(3, "transferContractID") ; /** The field ordinal in protobuf for this type */ private final int protoOrdinal; /** The original field name in protobuf for this type */ private final String protoName; /** * OneOf Type Enum Constructor * * @param protoOrdinal The oneof field ordinal in protobuf for this type * @param protoName The original field name in protobuf for this type */ ObtainersOneOfType(final int protoOrdinal, String protoName) { this.protoOrdinal = protoOrdinal; this.protoName = protoName; } /** * Get the oneof field ordinal in protobuf for this type * * @return The oneof field ordinal in protobuf for this type */ public int protoOrdinal() { return protoOrdinal; } /** * Get the original field name in protobuf for this type * * @return The original field name in protobuf for this type */ public String protoName() { return protoName; } /** * Get enum from protobuf ordinal * * @param ordinal the protobuf ordinal number * @return enum for matching ordinal * @throws IllegalArgumentException if ordinal doesn't exist */ public static ObtainersOneOfType fromProtobufOrdinal(int ordinal) { return switch(ordinal) { case 2 -> TRANSFER_ACCOUNT_ID; case 3 -> TRANSFER_CONTRACT_ID; default -> throw new IllegalArgumentException("Unknown protobuf ordinal "+ordinal); }; } /** * Get enum from string name, supports the enum or protobuf format name * * @param name the enum or protobuf format name * @return enum for matching name */ public static ObtainersOneOfType fromString(String name) { return switch(name) { case "transferAccountID", "TRANSFER_ACCOUNT_ID" -> TRANSFER_ACCOUNT_ID; case "transferContractID", "TRANSFER_CONTRACT_ID" -> TRANSFER_CONTRACT_ID; default -> throw new IllegalArgumentException("Unknown token kyc status "+name); }; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy