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

com.hedera.hashgraph.sdk.SystemDeleteTransaction Maven / Gradle / Ivy

The newest version!
/*-
 *
 * Hedera Java SDK
 *
 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.hedera.hashgraph.sdk;

import com.google.protobuf.InvalidProtocolBufferException;
import com.hedera.hashgraph.sdk.proto.FileServiceGrpc;
import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody;
import com.hedera.hashgraph.sdk.proto.SmartContractServiceGrpc;
import com.hedera.hashgraph.sdk.proto.SystemDeleteTransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionResponse;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.grpc.MethodDescriptor;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nullable;

/**
 * Delete a file or smart contract - can only be done with a Hedera admin.
 * 

* When it is deleted, it immediately disappears from the system as seen by the user, * but is still stored internally until the expiration time, at which time it * is truly and permanently deleted. *

* Until that time, it can be undeleted by the Hedera admin. * When a smart contract is deleted, the cryptocurrency account within it continues * to exist, and is not affected by the expiration time here. */ public final class SystemDeleteTransaction extends Transaction { @Nullable private FileId fileId = null; @Nullable private ContractId contractId = null; @Nullable private Instant expirationTime = null; /** * Constructor. */ public SystemDeleteTransaction() { } /** * Constructor. * * @param txs Compound list of transaction id's list of (AccountId, Transaction) * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ SystemDeleteTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } /** * Constructor. * * @param txBody protobuf TransactionBody */ SystemDeleteTransaction(com.hedera.hashgraph.sdk.proto.TransactionBody txBody) { super(txBody); initFromTransactionBody(); } /** * Extract the file id. * * @return the file id */ @Nullable public final FileId getFileId() { return fileId; } /** * Sets the file ID to delete. *

* Mutually exclusive with {@link #setContractId(ContractId)}. * * @param fileId The FileId to be set * @return {@code this} */ public SystemDeleteTransaction setFileId(FileId fileId) { Objects.requireNonNull(fileId); requireNotFrozen(); this.fileId = fileId; return this; } /** * Extract the contract id. * * @return the contract id */ @Nullable public final ContractId getContractId() { return contractId; } /** * Sets the contract ID to delete. *

* Mutually exclusive with {@link #setFileId(FileId)}. * * @param contractId The ContractId to be set * @return {@code this} */ public SystemDeleteTransaction setContractId(ContractId contractId) { Objects.requireNonNull(contractId); requireNotFrozen(); this.contractId = contractId; return this; } /** * Extract the expiration time. * * @return the expiration time */ @Nullable @SuppressFBWarnings( value = "EI_EXPOSE_REP", justification = "An Instant can't actually be mutated" ) public Instant getExpirationTime() { return expirationTime; } /** * Sets the timestamp at which the "deleted" file should * truly be permanently deleted. * * @param expirationTime The Instant to be set as expiration time * @return {@code this} */ @SuppressFBWarnings( value = "EI_EXPOSE_REP2", justification = "An Instant can't actually be mutated" ) public SystemDeleteTransaction setExpirationTime(Instant expirationTime) { Objects.requireNonNull(expirationTime); requireNotFrozen(); this.expirationTime = expirationTime; return this; } /** * Build the transaction body. * * @return {@link com.hedera.hashgraph.sdk.proto.SystemDeleteTransactionBody} */ SystemDeleteTransactionBody.Builder build() { var builder = SystemDeleteTransactionBody.newBuilder(); if (fileId != null) { builder.setFileID(fileId.toProtobuf()); } if (contractId != null) { builder.setContractID(contractId.toProtobuf()); } if (expirationTime != null) { builder.setExpirationTime(InstantConverter.toSecondsProtobuf(expirationTime)); } return builder; } /** * Initialize from the transaction body. */ void initFromTransactionBody() { var body = sourceTransactionBody.getSystemDelete(); if (body.hasFileID()) { fileId = FileId.fromProtobuf(body.getFileID()); } if (body.hasContractID()) { contractId = ContractId.fromProtobuf(body.getContractID()); } if (body.hasExpirationTime()) { expirationTime = InstantConverter.fromProtobuf(body.getExpirationTime()); } } @Override void validateChecksums(Client client) throws BadEntityIdException { if (fileId != null) { fileId.validateChecksum(client); } if (contractId != null) { contractId.validateChecksum(client); } } @Override CompletableFuture onExecuteAsync(Client client) { int modesEnabled = (fileId != null ? 1 : 0) + (contractId != null ? 1 : 0); if (modesEnabled != 1) { throw new IllegalStateException("SystemDeleteTransaction must have exactly 1 of the following fields set: contractId, fileId"); } return super.onExecuteAsync(client); } @Override MethodDescriptor getMethodDescriptor() { if (fileId != null) { return FileServiceGrpc.getSystemDeleteMethod(); } else { return SmartContractServiceGrpc.getSystemDeleteMethod(); } } @Override void onFreeze(TransactionBody.Builder bodyBuilder) { bodyBuilder.setSystemDelete(build()); } @Override void onScheduled(SchedulableTransactionBody.Builder scheduled) { scheduled.setSystemDelete(build()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy