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