github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_unpause_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  	"time"
    25  
    26  	"github.com/hashgraph/hedera-protobufs-go/services"
    27  )
    28  
    29  // TokenUnpauseTransaction
    30  // Unpauses the Token. Must be signed with the Token's pause key.
    31  // If the provided token is not found, the transaction will resolve to INVALID_TOKEN_ID.
    32  // If the provided token has been deleted, the transaction will resolve to TOKEN_WAS_DELETED.
    33  // If no Pause Key is defined, the transaction will resolve to TOKEN_HAS_NO_PAUSE_KEY.
    34  // Once executed the Token is marked as Unpaused and can be used in Transactions.
    35  // The operation is idempotent - becomes a no-op if the Token is already unpaused.
    36  type TokenUnpauseTransaction struct {
    37  	Transaction
    38  	tokenID *TokenID
    39  }
    40  
    41  // NewTokenUnpauseTransaction creates TokenUnpauseTransaction which unpauses the Token.
    42  // Must be signed with the Token's pause key.
    43  // If the provided token is not found, the transaction will resolve to INVALID_TOKEN_ID.
    44  // If the provided token has been deleted, the transaction will resolve to TOKEN_WAS_DELETED.
    45  // If no Pause Key is defined, the transaction will resolve to TOKEN_HAS_NO_PAUSE_KEY.
    46  // Once executed the Token is marked as Unpaused and can be used in Transactions.
    47  // The operation is idempotent - becomes a no-op if the Token is already unpaused.
    48  func NewTokenUnpauseTransaction() *TokenUnpauseTransaction {
    49  	tx := TokenUnpauseTransaction{
    50  		Transaction: _NewTransaction(),
    51  	}
    52  
    53  	tx._SetDefaultMaxTransactionFee(NewHbar(30))
    54  
    55  	return &tx
    56  }
    57  
    58  func _TokenUnpauseTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *TokenUnpauseTransaction {
    59  	return &TokenUnpauseTransaction{
    60  		Transaction: tx,
    61  		tokenID:     _TokenIDFromProtobuf(pb.GetTokenDeletion().GetToken()),
    62  	}
    63  }
    64  
    65  // SetTokenID Sets the token to be unpaused.
    66  func (tx *TokenUnpauseTransaction) SetTokenID(tokenID TokenID) *TokenUnpauseTransaction {
    67  	tx._RequireNotFrozen()
    68  	tx.tokenID = &tokenID
    69  	return tx
    70  }
    71  
    72  // GetTokenID returns the TokenID of the token to be unpaused.
    73  func (tx *TokenUnpauseTransaction) GetTokenID() TokenID {
    74  	if tx.tokenID == nil {
    75  		return TokenID{}
    76  	}
    77  
    78  	return *tx.tokenID
    79  }
    80  
    81  // ---- Required Interfaces ---- //
    82  
    83  // Sign uses the provided privateKey to sign the transaction.
    84  func (tx *TokenUnpauseTransaction) Sign(privateKey PrivateKey) *TokenUnpauseTransaction {
    85  	tx.Transaction.Sign(privateKey)
    86  	return tx
    87  }
    88  
    89  // SignWithOperator signs the transaction with client's operator privateKey.
    90  func (tx *TokenUnpauseTransaction) SignWithOperator(client *Client) (*TokenUnpauseTransaction, error) {
    91  	_, err := tx.Transaction.signWithOperator(client, tx)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	return tx, nil
    96  }
    97  
    98  // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map
    99  // with the publicKey as the map key.
   100  func (tx *TokenUnpauseTransaction) SignWith(
   101  	publicKey PublicKey,
   102  	signer TransactionSigner,
   103  ) *TokenUnpauseTransaction {
   104  	tx.Transaction.SignWith(publicKey, signer)
   105  	return tx
   106  }
   107  
   108  // AddSignature adds a signature to the transaction.
   109  func (tx *TokenUnpauseTransaction) AddSignature(publicKey PublicKey, signature []byte) *TokenUnpauseTransaction {
   110  	tx.Transaction.AddSignature(publicKey, signature)
   111  	return tx
   112  }
   113  
   114  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
   115  func (tx *TokenUnpauseTransaction) SetGrpcDeadline(deadline *time.Duration) *TokenUnpauseTransaction {
   116  	tx.Transaction.SetGrpcDeadline(deadline)
   117  	return tx
   118  }
   119  
   120  func (tx *TokenUnpauseTransaction) Freeze() (*TokenUnpauseTransaction, error) {
   121  	return tx.FreezeWith(nil)
   122  }
   123  
   124  func (tx *TokenUnpauseTransaction) FreezeWith(client *Client) (*TokenUnpauseTransaction, error) {
   125  	_, err := tx.Transaction.freezeWith(client, tx)
   126  	return tx, err
   127  }
   128  
   129  // SetMaxTransactionFee sets the max transaction fee for this TokenUnpauseTransaction.
   130  func (tx *TokenUnpauseTransaction) SetMaxTransactionFee(fee Hbar) *TokenUnpauseTransaction {
   131  	tx.Transaction.SetMaxTransactionFee(fee)
   132  	return tx
   133  }
   134  
   135  // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received
   136  func (tx *TokenUnpauseTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *TokenUnpauseTransaction {
   137  	tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID)
   138  	return tx
   139  }
   140  
   141  // SetTransactionMemo sets the memo for this TokenUnpauseTransaction.
   142  func (tx *TokenUnpauseTransaction) SetTransactionMemo(memo string) *TokenUnpauseTransaction {
   143  	tx.Transaction.SetTransactionMemo(memo)
   144  	return tx
   145  }
   146  
   147  // SetTransactionValidDuration sets the valid duration for this TokenUnpauseTransaction.
   148  func (tx *TokenUnpauseTransaction) SetTransactionValidDuration(duration time.Duration) *TokenUnpauseTransaction {
   149  	tx.Transaction.SetTransactionValidDuration(duration)
   150  	return tx
   151  }
   152  
   153  // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not
   154  func (tx *TokenUnpauseTransaction) ToBytes() ([]byte, error) {
   155  	bytes, err := tx.Transaction.toBytes(tx)
   156  	if err != nil {
   157  		return nil, err
   158  	}
   159  	return bytes, nil
   160  }
   161  
   162  // SetTransactionID sets the TransactionID for this TokenUnpauseTransaction.
   163  func (tx *TokenUnpauseTransaction) SetTransactionID(transactionID TransactionID) *TokenUnpauseTransaction {
   164  	tx.Transaction.SetTransactionID(transactionID)
   165  	return tx
   166  }
   167  
   168  // SetNodeAccountIDs sets the _Node AccountID for this TokenUnpauseTransaction.
   169  func (tx *TokenUnpauseTransaction) SetNodeAccountIDs(nodeID []AccountID) *TokenUnpauseTransaction {
   170  	tx.Transaction.SetNodeAccountIDs(nodeID)
   171  	return tx
   172  }
   173  
   174  // SetMaxRetry sets the max number of errors before execution will fail.
   175  func (tx *TokenUnpauseTransaction) SetMaxRetry(count int) *TokenUnpauseTransaction {
   176  	tx.Transaction.SetMaxRetry(count)
   177  	return tx
   178  }
   179  
   180  // SetMaxBackoff The maximum amount of time to wait between retries.
   181  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   182  func (tx *TokenUnpauseTransaction) SetMaxBackoff(max time.Duration) *TokenUnpauseTransaction {
   183  	tx.Transaction.SetMaxBackoff(max)
   184  	return tx
   185  }
   186  
   187  // SetMinBackoff sets the minimum amount of time to wait between retries.
   188  func (tx *TokenUnpauseTransaction) SetMinBackoff(min time.Duration) *TokenUnpauseTransaction {
   189  	tx.Transaction.SetMinBackoff(min)
   190  	return tx
   191  }
   192  
   193  func (tx *TokenUnpauseTransaction) SetLogLevel(level LogLevel) *TokenUnpauseTransaction {
   194  	tx.Transaction.SetLogLevel(level)
   195  	return tx
   196  }
   197  
   198  func (tx *TokenUnpauseTransaction) Execute(client *Client) (TransactionResponse, error) {
   199  	return tx.Transaction.execute(client, tx)
   200  }
   201  
   202  func (tx *TokenUnpauseTransaction) Schedule() (*ScheduleCreateTransaction, error) {
   203  	return tx.Transaction.schedule(tx)
   204  }
   205  
   206  // ----------- Overridden functions ----------------
   207  
   208  func (tx *TokenUnpauseTransaction) getName() string {
   209  	return "TokenUnpauseTransaction"
   210  }
   211  
   212  func (tx *TokenUnpauseTransaction) validateNetworkOnIDs(client *Client) error {
   213  	if client == nil || !client.autoValidateChecksums {
   214  		return nil
   215  	}
   216  
   217  	if tx.tokenID != nil {
   218  		if err := tx.tokenID.ValidateChecksum(client); err != nil {
   219  			return err
   220  		}
   221  	}
   222  
   223  	return nil
   224  }
   225  
   226  func (tx *TokenUnpauseTransaction) build() *services.TransactionBody {
   227  	return &services.TransactionBody{
   228  		TransactionFee:           tx.transactionFee,
   229  		Memo:                     tx.Transaction.memo,
   230  		TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()),
   231  		TransactionID:            tx.transactionID._ToProtobuf(),
   232  		Data: &services.TransactionBody_TokenUnpause{
   233  			TokenUnpause: tx.buildProtoBody(),
   234  		},
   235  	}
   236  }
   237  
   238  func (tx *TokenUnpauseTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) { //nolint
   239  	return &services.SchedulableTransactionBody{
   240  		TransactionFee: tx.transactionFee,
   241  		Memo:           tx.Transaction.memo,
   242  		Data: &services.SchedulableTransactionBody_TokenUnpause{
   243  			TokenUnpause: tx.buildProtoBody(),
   244  		},
   245  	}, nil
   246  }
   247  
   248  func (tx *TokenUnpauseTransaction) buildProtoBody() *services.TokenUnpauseTransactionBody { //nolint
   249  	body := &services.TokenUnpauseTransactionBody{}
   250  	if tx.tokenID != nil {
   251  		body.Token = tx.tokenID._ToProtobuf()
   252  	}
   253  
   254  	return body
   255  }
   256  
   257  func (tx *TokenUnpauseTransaction) getMethod(channel *_Channel) _Method {
   258  	return _Method{
   259  		transaction: channel._GetToken().DeleteToken,
   260  	}
   261  }
   262  func (tx *TokenUnpauseTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
   263  	return tx.buildScheduled()
   264  }