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