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