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