github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/file_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 "github.com/hashgraph/hedera-protobufs-go/services" 25 26 "time" 27 ) 28 29 // FileDeleteTransaction Deletes the given file. After deletion, it will be marked as deleted and will have no contents. 30 // But information about it will continue to exist until it expires. A list of keys was given when 31 // the file was created. All the top level keys on that list must sign transactions to create or 32 // modify the file, but any single one of the top level keys can be used to delete the file. This 33 // transaction must be signed by 1-of-M KeyList keys. If keys contains additional KeyList or 34 // ThresholdKey then 1-of-M secondary KeyList or ThresholdKey signing requirements must be meet. 35 type FileDeleteTransaction struct { 36 Transaction 37 fileID *FileID 38 } 39 40 // NewFileDeleteTransaction creates a FileDeleteTransaction which deletes the given file. After deletion, 41 // it will be marked as deleted and will have no contents. 42 // But information about it will continue to exist until it expires. A list of keys was given when 43 // the file was created. All the top level keys on that list must sign transactions to create or 44 // modify the file, but any single one of the top level keys can be used to delete the file. This 45 // transaction must be signed by 1-of-M KeyList keys. If keys contains additional KeyList or 46 // ThresholdKey then 1-of-M secondary KeyList or ThresholdKey signing requirements must be meet. 47 func NewFileDeleteTransaction() *FileDeleteTransaction { 48 tx := FileDeleteTransaction{ 49 Transaction: _NewTransaction(), 50 } 51 tx._SetDefaultMaxTransactionFee(NewHbar(5)) 52 53 return &tx 54 } 55 56 func _FileDeleteTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *FileDeleteTransaction { 57 return &FileDeleteTransaction{ 58 Transaction: tx, 59 fileID: _FileIDFromProtobuf(pb.GetFileDelete().GetFileID()), 60 } 61 } 62 63 // SetFileID Sets the FileID of the file to be deleted 64 func (tx *FileDeleteTransaction) SetFileID(fileID FileID) *FileDeleteTransaction { 65 tx._RequireNotFrozen() 66 tx.fileID = &fileID 67 return tx 68 } 69 70 // GetFileID returns the FileID of the file to be deleted 71 func (tx *FileDeleteTransaction) GetFileID() FileID { 72 if tx.fileID == nil { 73 return FileID{} 74 } 75 76 return *tx.fileID 77 } 78 79 // ---- Required Interfaces ---- // 80 81 // Sign uses the provided privateKey to sign the transaction. 82 func (tx *FileDeleteTransaction) Sign( 83 privateKey PrivateKey, 84 ) *FileDeleteTransaction { 85 tx.Transaction.Sign(privateKey) 86 return tx 87 } 88 89 // SignWithOperator signs the transaction with client's operator privateKey. 90 func (tx *FileDeleteTransaction) SignWithOperator( 91 client *Client, 92 ) (*FileDeleteTransaction, error) { 93 // If the transaction is not signed by the _Operator, we need 94 // to sign the transaction with the _Operator 95 _, err := tx.Transaction.signWithOperator(client, tx) 96 if err != nil { 97 return nil, err 98 } 99 return tx, nil 100 } 101 102 // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map 103 // with the publicKey as the map key. 104 func (tx *FileDeleteTransaction) SignWith( 105 publicKey PublicKey, 106 signer TransactionSigner, 107 ) *FileDeleteTransaction { 108 tx.Transaction.SignWith(publicKey, signer) 109 return tx 110 } 111 112 // AddSignature adds a signature to the transaction. 113 func (tx *FileDeleteTransaction) AddSignature(publicKey PublicKey, signature []byte) *FileDeleteTransaction { 114 tx.Transaction.AddSignature(publicKey, signature) 115 return tx 116 } 117 118 // When execution is attempted, a single attempt will timeout when tx deadline is reached. (The SDK may subsequently retry the execution.) 119 func (tx *FileDeleteTransaction) SetGrpcDeadline(deadline *time.Duration) *FileDeleteTransaction { 120 tx.Transaction.SetGrpcDeadline(deadline) 121 return tx 122 } 123 124 func (tx *FileDeleteTransaction) Freeze() (*FileDeleteTransaction, error) { 125 return tx.FreezeWith(nil) 126 } 127 128 func (tx *FileDeleteTransaction) FreezeWith(client *Client) (*FileDeleteTransaction, error) { 129 _, err := tx.Transaction.freezeWith(client, tx) 130 return tx, err 131 } 132 133 // GetMaxTransactionFee returns the maximum transaction fee the operator (paying account) is willing to pay. 134 func (tx *FileDeleteTransaction) GetMaxTransactionFee() Hbar { 135 return tx.Transaction.GetMaxTransactionFee() 136 } 137 138 // SetMaxTransactionFee sets the maximum transaction fee the operator (paying account) is willing to pay. 139 func (tx *FileDeleteTransaction) SetMaxTransactionFee(fee Hbar) *FileDeleteTransaction { 140 tx._RequireNotFrozen() 141 tx.Transaction.SetMaxTransactionFee(fee) 142 return tx 143 } 144 145 // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received 146 func (tx *FileDeleteTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *FileDeleteTransaction { 147 tx._RequireNotFrozen() 148 tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID) 149 return tx 150 } 151 152 // SetTransactionMemo sets the memo for this FileDeleteTransaction. 153 func (tx *FileDeleteTransaction) SetTransactionMemo(memo string) *FileDeleteTransaction { 154 tx._RequireNotFrozen() 155 tx.Transaction.SetTransactionMemo(memo) 156 return tx 157 } 158 159 // SetTransactionValidDuration sets the valid duration for this FileDeleteTransaction. 160 func (tx *FileDeleteTransaction) SetTransactionValidDuration(duration time.Duration) *FileDeleteTransaction { 161 tx._RequireNotFrozen() 162 tx.Transaction.SetTransactionValidDuration(duration) 163 return tx 164 } 165 166 // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not 167 func (tx *FileDeleteTransaction) ToBytes() ([]byte, error) { 168 bytes, err := tx.Transaction.toBytes(tx) 169 if err != nil { 170 return nil, err 171 } 172 return bytes, nil 173 } 174 175 // SetTransactionID sets the TransactionID for this FileDeleteTransaction. 176 func (tx *FileDeleteTransaction) SetTransactionID(transactionID TransactionID) *FileDeleteTransaction { 177 tx._RequireNotFrozen() 178 179 tx.Transaction.SetTransactionID(transactionID) 180 return tx 181 } 182 183 // SetNodeAccountID sets the _Node AccountID for this FileDeleteTransaction. 184 func (tx *FileDeleteTransaction) SetNodeAccountIDs(nodeID []AccountID) *FileDeleteTransaction { 185 tx._RequireNotFrozen() 186 tx.Transaction.SetNodeAccountIDs(nodeID) 187 return tx 188 } 189 190 // SetMaxRetry sets the max number of errors before execution will fail. 191 func (tx *FileDeleteTransaction) SetMaxRetry(count int) *FileDeleteTransaction { 192 tx.Transaction.SetMaxRetry(count) 193 return tx 194 } 195 196 // SetMaxBackoff The maximum amount of time to wait between retries. 197 // Every retry attempt will increase the wait time exponentially until it reaches this time. 198 func (tx *FileDeleteTransaction) SetMaxBackoff(max time.Duration) *FileDeleteTransaction { 199 tx.Transaction.SetMaxBackoff(max) 200 return tx 201 } 202 203 // SetMinBackoff sets the minimum amount of time to wait between retries. 204 func (tx *FileDeleteTransaction) SetMinBackoff(min time.Duration) *FileDeleteTransaction { 205 tx.Transaction.SetMinBackoff(min) 206 return tx 207 } 208 209 func (tx *FileDeleteTransaction) SetLogLevel(level LogLevel) *FileDeleteTransaction { 210 tx.Transaction.SetLogLevel(level) 211 return tx 212 } 213 214 func (tx *FileDeleteTransaction) Execute(client *Client) (TransactionResponse, error) { 215 return tx.Transaction.execute(client, tx) 216 } 217 218 func (tx *FileDeleteTransaction) Schedule() (*ScheduleCreateTransaction, error) { 219 return tx.Transaction.schedule(tx) 220 } 221 222 // ----------- Overridden functions ---------------- 223 224 func (tx *FileDeleteTransaction) getName() string { 225 return "FileDeleteTransaction" 226 } 227 func (tx *FileDeleteTransaction) validateNetworkOnIDs(client *Client) error { 228 if client == nil || !client.autoValidateChecksums { 229 return nil 230 } 231 232 if tx.fileID != nil { 233 if err := tx.fileID.ValidateChecksum(client); err != nil { 234 return err 235 } 236 } 237 238 return nil 239 } 240 241 func (tx *FileDeleteTransaction) build() *services.TransactionBody { 242 return &services.TransactionBody{ 243 TransactionFee: tx.transactionFee, 244 Memo: tx.Transaction.memo, 245 TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()), 246 TransactionID: tx.transactionID._ToProtobuf(), 247 Data: &services.TransactionBody_FileDelete{ 248 FileDelete: tx.buildProtoBody(), 249 }, 250 } 251 } 252 253 func (tx *FileDeleteTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) { 254 return &services.SchedulableTransactionBody{ 255 TransactionFee: tx.transactionFee, 256 Memo: tx.Transaction.memo, 257 Data: &services.SchedulableTransactionBody_FileDelete{ 258 FileDelete: tx.buildProtoBody(), 259 }, 260 }, nil 261 } 262 func (tx *FileDeleteTransaction) buildProtoBody() *services.FileDeleteTransactionBody { 263 body := &services.FileDeleteTransactionBody{} 264 if tx.fileID != nil { 265 body.FileID = tx.fileID._ToProtobuf() 266 } 267 return body 268 } 269 270 func (tx *FileDeleteTransaction) getMethod(channel *_Channel) _Method { 271 return _Method{ 272 transaction: channel._GetFile().DeleteFile, 273 } 274 } 275 func (tx *FileDeleteTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) { 276 return tx.buildScheduled() 277 }