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