github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/node_delete_transaction.go (about) 1 package hedera 2 3 import ( 4 "time" 5 6 "github.com/hashgraph/hedera-protobufs-go/services" 7 ) 8 9 /*- 10 * 11 * Hedera Go SDK 12 * 13 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 * 27 */ 28 29 /** 30 * A transaction to delete a node from the network address book. 31 * 32 * This transaction body SHALL be considered a "privileged transaction". 33 * 34 * - A transaction MUST be signed by the governing council. 35 * - Upon success, the address book entry SHALL enter a "pending delete" 36 * state. 37 * - All address book entries pending deletion SHALL be removed from the 38 * active network configuration during the next `freeze` transaction with 39 * the field `freeze_type` set to `PREPARE_UPGRADE`.<br/> 40 * - A deleted address book node SHALL be removed entirely from network state. 41 * - A deleted address book node identifier SHALL NOT be reused. 42 * 43 * ### Record Stream Effects 44 * Upon completion the "deleted" `node_id` SHALL be in the transaction 45 * receipt. 46 */ 47 type NodeDeleteTransaction struct { 48 Transaction 49 nodeID uint64 50 } 51 52 func NewNodeDeleteTransaction() *NodeDeleteTransaction { 53 tx := &NodeDeleteTransaction{ 54 Transaction: _NewTransaction(), 55 } 56 tx._SetDefaultMaxTransactionFee(NewHbar(5)) 57 58 return tx 59 } 60 61 func _NodeDeleteTransactionFromProtobuf(transaction Transaction, pb *services.TransactionBody) *NodeDeleteTransaction { 62 return &NodeDeleteTransaction{ 63 Transaction: transaction, 64 nodeID: pb.GetNodeDelete().NodeId, 65 } 66 } 67 68 // GetNodeID he consensus node identifier in the network state. 69 func (tx *NodeDeleteTransaction) GetNodeID() uint64 { 70 return tx.nodeID 71 } 72 73 // SetNodeID the consensus node identifier in the network state. 74 func (tx *NodeDeleteTransaction) SetNodeID(nodeID uint64) *NodeDeleteTransaction { 75 tx._RequireNotFrozen() 76 tx.nodeID = nodeID 77 return tx 78 } 79 80 // ---- Required Interfaces ---- // 81 82 // Sign uses the provided privateKey to sign the transaction. 83 func (tx *NodeDeleteTransaction) Sign(privateKey PrivateKey) *NodeDeleteTransaction { 84 tx.Transaction.Sign(privateKey) 85 return tx 86 } 87 88 // SignWithOperator signs the transaction with client's operator privateKey. 89 func (tx *NodeDeleteTransaction) SignWithOperator(client *Client) (*NodeDeleteTransaction, error) { 90 _, err := tx.Transaction.signWithOperator(client, tx) 91 if err != nil { 92 return nil, err 93 } 94 return tx, nil 95 } 96 97 // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map 98 // with the publicKey as the map key. 99 func (tx *NodeDeleteTransaction) SignWith( 100 publicKey PublicKey, 101 signer TransactionSigner, 102 ) *NodeDeleteTransaction { 103 tx.Transaction.SignWith(publicKey, signer) 104 return tx 105 } 106 107 // AddSignature adds a signature to the transaction. 108 func (tx *NodeDeleteTransaction) AddSignature(publicKey PublicKey, signature []byte) *NodeDeleteTransaction { 109 tx.Transaction.AddSignature(publicKey, signature) 110 return tx 111 } 112 113 // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.) 114 func (tx *NodeDeleteTransaction) SetGrpcDeadline(deadline *time.Duration) *NodeDeleteTransaction { 115 tx.Transaction.SetGrpcDeadline(deadline) 116 return tx 117 } 118 119 func (tx *NodeDeleteTransaction) Freeze() (*NodeDeleteTransaction, error) { 120 return tx.FreezeWith(nil) 121 } 122 123 func (tx *NodeDeleteTransaction) FreezeWith(client *Client) (*NodeDeleteTransaction, error) { 124 _, err := tx.Transaction.freezeWith(client, tx) 125 return tx, err 126 } 127 128 // SetMaxTransactionFee sets the max transaction fee for this NodeDeleteTransaction. 129 func (tx *NodeDeleteTransaction) SetMaxTransactionFee(fee Hbar) *NodeDeleteTransaction { 130 tx.Transaction.SetMaxTransactionFee(fee) 131 return tx 132 } 133 134 // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received 135 func (tx *NodeDeleteTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *NodeDeleteTransaction { 136 tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID) 137 return tx 138 } 139 140 // SetTransactionMemo sets the memo for this NodeDeleteTransaction. 141 func (tx *NodeDeleteTransaction) SetTransactionMemo(memo string) *NodeDeleteTransaction { 142 tx.Transaction.SetTransactionMemo(memo) 143 return tx 144 } 145 146 // SetTransactionValidDuration sets the valid duration for this NodeDeleteTransaction. 147 func (tx *NodeDeleteTransaction) SetTransactionValidDuration(duration time.Duration) *NodeDeleteTransaction { 148 tx.Transaction.SetTransactionValidDuration(duration) 149 return tx 150 } 151 152 // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not 153 func (tx *NodeDeleteTransaction) ToBytes() ([]byte, error) { 154 bytes, err := tx.Transaction.toBytes(tx) 155 if err != nil { 156 return nil, err 157 } 158 return bytes, nil 159 } 160 161 // SetTransactionID sets the TransactionID for this NodeDeleteTransaction. 162 func (tx *NodeDeleteTransaction) SetTransactionID(transactionID TransactionID) *NodeDeleteTransaction { 163 tx.Transaction.SetTransactionID(transactionID) 164 return tx 165 } 166 167 // SetNodeAccountIDs sets the _Node AccountID for this NodeDeleteTransaction. 168 func (tx *NodeDeleteTransaction) SetNodeAccountIDs(nodeID []AccountID) *NodeDeleteTransaction { 169 tx.Transaction.SetNodeAccountIDs(nodeID) 170 return tx 171 } 172 173 // SetMaxRetry sets the max number of errors before execution will fail. 174 func (tx *NodeDeleteTransaction) SetMaxRetry(count int) *NodeDeleteTransaction { 175 tx.Transaction.SetMaxRetry(count) 176 return tx 177 } 178 179 // SetMaxBackoff The maximum amount of time to wait between retries. 180 // Every retry attempt will increase the wait time exponentially until it reaches this time. 181 func (tx *NodeDeleteTransaction) SetMaxBackoff(max time.Duration) *NodeDeleteTransaction { 182 tx.Transaction.SetMaxBackoff(max) 183 return tx 184 } 185 186 // SetMinBackoff sets the minimum amount of time to wait between retries. 187 func (tx *NodeDeleteTransaction) SetMinBackoff(min time.Duration) *NodeDeleteTransaction { 188 tx.Transaction.SetMinBackoff(min) 189 return tx 190 } 191 192 func (tx *NodeDeleteTransaction) SetLogLevel(level LogLevel) *NodeDeleteTransaction { 193 tx.Transaction.SetLogLevel(level) 194 return tx 195 } 196 197 func (tx *NodeDeleteTransaction) Execute(client *Client) (TransactionResponse, error) { 198 return tx.Transaction.execute(client, tx) 199 } 200 201 func (tx *NodeDeleteTransaction) Schedule() (*ScheduleCreateTransaction, error) { 202 return tx.Transaction.schedule(tx) 203 } 204 205 // ----------- Overridden functions ---------------- 206 207 func (tx *NodeDeleteTransaction) getName() string { 208 return "NodeDeleteTransaction" 209 } 210 211 func (tx *NodeDeleteTransaction) validateNetworkOnIDs(client *Client) error { 212 return nil 213 } 214 215 func (tx *NodeDeleteTransaction) build() *services.TransactionBody { 216 return &services.TransactionBody{ 217 TransactionFee: tx.transactionFee, 218 Memo: tx.Transaction.memo, 219 TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()), 220 TransactionID: tx.transactionID._ToProtobuf(), 221 Data: &services.TransactionBody_NodeDelete{ 222 NodeDelete: tx.buildProtoBody(), 223 }, 224 } 225 } 226 227 func (tx *NodeDeleteTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) { 228 return &services.SchedulableTransactionBody{ 229 TransactionFee: tx.transactionFee, 230 Memo: tx.Transaction.memo, 231 Data: &services.SchedulableTransactionBody_NodeDelete{ 232 NodeDelete: tx.buildProtoBody(), 233 }, 234 }, nil 235 } 236 237 func (tx *NodeDeleteTransaction) buildProtoBody() *services.NodeDeleteTransactionBody { 238 return &services.NodeDeleteTransactionBody{ 239 NodeId: tx.nodeID, 240 } 241 } 242 243 func (tx *NodeDeleteTransaction) getMethod(channel *_Channel) _Method { 244 return _Method{ 245 transaction: channel._GetAddressBook().DeleteNode, 246 } 247 } 248 249 func (tx *NodeDeleteTransaction) preFreezeWith(client *Client) { 250 // No special actions needed. 251 } 252 253 func (tx *NodeDeleteTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) { 254 return tx.buildScheduled() 255 }