github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/live_hash_delete_transaction.go (about)

     1  package hedera
     2  
     3  /*-
     4   *
     5   * Hedera Go SDK
     6   *
     7   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
     8   *
     9   * Licensed under the Apache License, Version 2.0 (the "License");
    10   * you may not use this file except in compliance with the License.
    11   * You may obtain a copy of the License at
    12   *
    13   *      http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing, software
    16   * distributed under the License is distributed on an "AS IS" BASIS,
    17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18   * See the License for the specific language governing permissions and
    19   * limitations under the License.
    20   *
    21   */
    22  
    23  import (
    24  	"errors"
    25  
    26  	"github.com/hashgraph/hedera-protobufs-go/services"
    27  
    28  	"time"
    29  )
    30  
    31  // LiveHashDeleteTransaction At consensus, deletes a livehash associated to the given account. The transaction must be signed
    32  // by either the key of the owning account, or at least one of the keys associated to the livehash.
    33  type LiveHashDeleteTransaction struct {
    34  	Transaction
    35  	accountID *AccountID
    36  	hash      []byte
    37  }
    38  
    39  // NewLiveHashDeleteTransaction creates LiveHashDeleteTransaction which at consensus, deletes a livehash associated to the given account.
    40  // The transaction must be signed by either the key of the owning account, or at least one of the keys associated to the livehash.
    41  func NewLiveHashDeleteTransaction() *LiveHashDeleteTransaction {
    42  	tx := LiveHashDeleteTransaction{
    43  		Transaction: _NewTransaction(),
    44  	}
    45  	tx._SetDefaultMaxTransactionFee(NewHbar(2))
    46  
    47  	return &tx
    48  }
    49  
    50  func _LiveHashDeleteTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *LiveHashDeleteTransaction {
    51  	return &LiveHashDeleteTransaction{
    52  		Transaction: tx,
    53  		accountID:   _AccountIDFromProtobuf(pb.GetCryptoDeleteLiveHash().GetAccountOfLiveHash()),
    54  		hash:        pb.GetCryptoDeleteLiveHash().LiveHashToDelete,
    55  	}
    56  }
    57  
    58  // SetHash Set the SHA-384 livehash to delete from the account
    59  func (tx *LiveHashDeleteTransaction) SetHash(hash []byte) *LiveHashDeleteTransaction {
    60  	tx._RequireNotFrozen()
    61  	tx.hash = hash
    62  	return tx
    63  }
    64  
    65  // GetHash returns the SHA-384 livehash to delete from the account
    66  func (tx *LiveHashDeleteTransaction) GetHash() []byte {
    67  	return tx.hash
    68  }
    69  
    70  // SetAccountID Sets the account owning the livehash
    71  func (tx *LiveHashDeleteTransaction) SetAccountID(accountID AccountID) *LiveHashDeleteTransaction {
    72  	tx._RequireNotFrozen()
    73  	tx.accountID = &accountID
    74  	return tx
    75  }
    76  
    77  // GetAccountID returns the account owning the livehash
    78  func (tx *LiveHashDeleteTransaction) GetAccountID() AccountID {
    79  	if tx.accountID == nil {
    80  		return AccountID{}
    81  	}
    82  
    83  	return *tx.accountID
    84  }
    85  
    86  // ---- Required Interfaces ---- //
    87  
    88  // Sign uses the provided privateKey to sign the transaction.
    89  func (tx *LiveHashDeleteTransaction) Sign(privateKey PrivateKey) *LiveHashDeleteTransaction {
    90  	tx.Transaction.Sign(privateKey)
    91  	return tx
    92  }
    93  
    94  // SignWithOperator signs the transaction with client's operator privateKey.
    95  func (tx *LiveHashDeleteTransaction) SignWithOperator(client *Client) (*LiveHashDeleteTransaction, error) {
    96  	_, err := tx.Transaction.signWithOperator(client, tx)
    97  	if err != nil {
    98  		return nil, err
    99  	}
   100  	return tx, nil
   101  }
   102  
   103  // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map
   104  // with the publicKey as the map key.
   105  func (tx *LiveHashDeleteTransaction) SignWith(
   106  	publicKey PublicKey,
   107  	signer TransactionSigner,
   108  ) *LiveHashDeleteTransaction {
   109  	tx.Transaction.SignWith(publicKey, signer)
   110  	return tx
   111  }
   112  
   113  // AddSignature adds a signature to the transaction.
   114  func (tx *LiveHashDeleteTransaction) AddSignature(publicKey PublicKey, signature []byte) *LiveHashDeleteTransaction {
   115  	tx.Transaction.AddSignature(publicKey, signature)
   116  	return tx
   117  }
   118  
   119  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
   120  func (tx *LiveHashDeleteTransaction) SetGrpcDeadline(deadline *time.Duration) *LiveHashDeleteTransaction {
   121  	tx.Transaction.SetGrpcDeadline(deadline)
   122  	return tx
   123  }
   124  
   125  func (tx *LiveHashDeleteTransaction) Freeze() (*LiveHashDeleteTransaction, error) {
   126  	return tx.FreezeWith(nil)
   127  }
   128  
   129  func (tx *LiveHashDeleteTransaction) FreezeWith(client *Client) (*LiveHashDeleteTransaction, error) {
   130  	_, err := tx.Transaction.freezeWith(client, tx)
   131  	return tx, err
   132  }
   133  
   134  // SetMaxTransactionFee sets the maximum transaction fee for this LiveHashDeleteTransaction.
   135  func (tx *LiveHashDeleteTransaction) SetMaxTransactionFee(fee Hbar) *LiveHashDeleteTransaction {
   136  	tx.Transaction.SetMaxTransactionFee(fee)
   137  	return tx
   138  }
   139  
   140  // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received
   141  func (tx *LiveHashDeleteTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *LiveHashDeleteTransaction {
   142  	tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID)
   143  	return tx
   144  }
   145  
   146  // SetTransactionMemo sets the memo for this LiveHashDeleteTransaction.
   147  func (tx *LiveHashDeleteTransaction) SetTransactionMemo(memo string) *LiveHashDeleteTransaction {
   148  	tx.Transaction.SetTransactionMemo(memo)
   149  	return tx
   150  }
   151  
   152  // SetTransactionValidDuration sets the valid duration for this LiveHashDeleteTransaction.
   153  func (tx *LiveHashDeleteTransaction) SetTransactionValidDuration(duration time.Duration) *LiveHashDeleteTransaction {
   154  	tx.Transaction.SetTransactionValidDuration(duration)
   155  	return tx
   156  }
   157  
   158  // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not
   159  func (tx *LiveHashDeleteTransaction) ToBytes() ([]byte, error) {
   160  	bytes, err := tx.Transaction.toBytes(tx)
   161  	if err != nil {
   162  		return nil, err
   163  	}
   164  	return bytes, nil
   165  }
   166  
   167  // SetTransactionID sets the TransactionID for this LiveHashDeleteTransaction.
   168  func (tx *LiveHashDeleteTransaction) SetTransactionID(transactionID TransactionID) *LiveHashDeleteTransaction {
   169  	tx.Transaction.SetTransactionID(transactionID)
   170  	return tx
   171  }
   172  
   173  // SetNodeAccountIDs sets the _Node AccountID for this LiveHashDeleteTransaction.
   174  func (tx *LiveHashDeleteTransaction) SetNodeAccountIDs(nodeID []AccountID) *LiveHashDeleteTransaction {
   175  	tx.Transaction.SetNodeAccountIDs(nodeID)
   176  	return tx
   177  }
   178  
   179  // SetMaxRetry sets the max number of errors before execution will fail.
   180  func (tx *LiveHashDeleteTransaction) SetMaxRetry(count int) *LiveHashDeleteTransaction {
   181  	tx.Transaction.SetMaxRetry(count)
   182  	return tx
   183  }
   184  
   185  // SetMaxBackoff The maximum amount of time to wait between retries.
   186  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   187  func (tx *LiveHashDeleteTransaction) SetMaxBackoff(max time.Duration) *LiveHashDeleteTransaction {
   188  	tx.Transaction.SetMaxBackoff(max)
   189  	return tx
   190  }
   191  
   192  // SetMinBackoff sets the minimum amount of time to wait between retries.
   193  func (tx *LiveHashDeleteTransaction) SetMinBackoff(min time.Duration) *LiveHashDeleteTransaction {
   194  	tx.Transaction.SetMinBackoff(min)
   195  	return tx
   196  }
   197  
   198  func (tx *LiveHashDeleteTransaction) SetLogLevel(level LogLevel) *LiveHashDeleteTransaction {
   199  	tx.Transaction.SetLogLevel(level)
   200  	return tx
   201  }
   202  
   203  func (tx *LiveHashDeleteTransaction) Execute(client *Client) (TransactionResponse, error) {
   204  	return tx.Transaction.execute(client, tx)
   205  }
   206  
   207  func (tx *LiveHashDeleteTransaction) Schedule() (*ScheduleCreateTransaction, error) {
   208  	return tx.Transaction.schedule(tx)
   209  }
   210  
   211  // ----------- Overridden functions ----------------
   212  
   213  func (tx *LiveHashDeleteTransaction) getName() string {
   214  	return "LiveHashDeleteTransaction"
   215  }
   216  
   217  func (tx *LiveHashDeleteTransaction) validateNetworkOnIDs(client *Client) error {
   218  	if client == nil || !client.autoValidateChecksums {
   219  		return nil
   220  	}
   221  
   222  	if tx.accountID != nil {
   223  		if err := tx.accountID.ValidateChecksum(client); err != nil {
   224  			return err
   225  		}
   226  	}
   227  
   228  	return nil
   229  }
   230  
   231  func (tx *LiveHashDeleteTransaction) build() *services.TransactionBody {
   232  	return &services.TransactionBody{
   233  		TransactionFee:           tx.transactionFee,
   234  		Memo:                     tx.Transaction.memo,
   235  		TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()),
   236  		TransactionID:            tx.transactionID._ToProtobuf(),
   237  		Data: &services.TransactionBody_CryptoDeleteLiveHash{
   238  			CryptoDeleteLiveHash: tx.buildProtoBody(),
   239  		},
   240  	}
   241  }
   242  
   243  func (tx *LiveHashDeleteTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) {
   244  	return nil, errors.New("cannot schedule `LiveHashDeleteTransaction`")
   245  }
   246  
   247  func (tx *LiveHashDeleteTransaction) buildProtoBody() *services.CryptoDeleteLiveHashTransactionBody {
   248  	body := &services.CryptoDeleteLiveHashTransactionBody{}
   249  
   250  	if tx.accountID != nil {
   251  		body.AccountOfLiveHash = tx.accountID._ToProtobuf()
   252  	}
   253  
   254  	if tx.hash != nil {
   255  		body.LiveHashToDelete = tx.hash
   256  	}
   257  
   258  	return body
   259  }
   260  
   261  func (tx *LiveHashDeleteTransaction) getMethod(channel *_Channel) _Method {
   262  	return _Method{
   263  		transaction: channel._GetCrypto().DeleteLiveHash,
   264  	}
   265  }
   266  func (tx *LiveHashDeleteTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
   267  	return tx.buildScheduled()
   268  }