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