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