-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathnode_update_transaction.go
More file actions
430 lines (362 loc) · 12.9 KB
/
Copy pathnode_update_transaction.go
File metadata and controls
430 lines (362 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
package hiero
import (
"github.com/hiero-ledger/hiero-sdk-go/v2/proto/services"
"github.com/pkg/errors"
"google.golang.org/protobuf/types/known/wrapperspb"
)
// SPDX-License-Identifier: Apache-2.0
/**
* A transaction to modify address book node attributes.
*
* - This transaction SHALL enable the node operator, as identified by the
* `admin_key`, to modify operational attributes of the node.
* - This transaction MUST be signed by the active `admin_key` for the node.
* - If this transaction sets a new value for the `admin_key`, then both the
* current `admin_key`, and the new `admin_key` MUST sign this transaction.
* - This transaction SHALL NOT change any field that is not set (is null) in
* this transaction body.
* - This SHALL create a pending update to the node, but the change SHALL NOT
* be immediately applied to the active configuration.
* - All pending node updates SHALL be applied to the active network
* configuration during the next `freeze` transaction with the field
* `freeze_type` set to `PREPARE_UPGRADE`.
*
* ### Record Stream Effects
* Upon completion the `node_id` for the updated entry SHALL be in the
* transaction receipt.
*/
type NodeUpdateTransaction struct {
*Transaction[*NodeUpdateTransaction]
nodeID *uint64
accountID *AccountID
description string
gossipEndpoints []Endpoint
serviceEndpoints []Endpoint
gossipCaCertificate *[]byte
grpcCertificateHash []byte
adminKey Key
declineReward *bool
grpcWebProxyEndpoint *Endpoint
}
func NewNodeUpdateTransaction() *NodeUpdateTransaction {
tx := &NodeUpdateTransaction{}
tx.Transaction = _NewTransaction(tx)
return tx
}
func _NodeUpdateTransactionFromProtobuf(tx Transaction[*NodeUpdateTransaction], pb *services.TransactionBody) NodeUpdateTransaction {
var adminKey Key
if pb.GetNodeUpdate().GetAdminKey() != nil {
adminKey, _ = _KeyFromProtobuf(pb.GetNodeUpdate().GetAdminKey())
}
accountID := _AccountIDFromProtobuf(pb.GetNodeUpdate().GetAccountId())
gossipEndpoints := make([]Endpoint, 0)
for _, endpoint := range pb.GetNodeUpdate().GetGossipEndpoint() {
gossipEndpoints = append(gossipEndpoints, EndpointFromProtobuf(endpoint))
}
serviceEndpoints := make([]Endpoint, 0)
for _, endpoint := range pb.GetNodeUpdate().GetServiceEndpoint() {
serviceEndpoints = append(serviceEndpoints, EndpointFromProtobuf(endpoint))
}
var grpcProxyEndpoint *Endpoint
if pb.GetNodeUpdate().GetGrpcProxyEndpoint() != nil {
grpcProxyEndpointValue := EndpointFromProtobuf(pb.GetNodeUpdate().GetGrpcProxyEndpoint())
grpcProxyEndpoint = &grpcProxyEndpointValue
}
var certificate []byte
if pb.GetNodeUpdate().GetGossipCaCertificate() != nil {
certificate = pb.GetNodeUpdate().GetGossipCaCertificate().Value
}
var description string
if pb.GetNodeUpdate().GetDescription() != nil {
description = pb.GetNodeUpdate().GetDescription().Value
}
var certificateHash []byte
if pb.GetNodeUpdate().GetGrpcCertificateHash() != nil {
certificateHash = pb.GetNodeUpdate().GetGrpcCertificateHash().Value
}
var declineReward *bool
if pb.GetNodeUpdate().GetDeclineReward() != nil {
declineRewardValue := pb.GetNodeUpdate().GetDeclineReward().Value
declineReward = &declineRewardValue
}
nodeID := pb.GetNodeUpdate().GetNodeId()
nodeUpdateTransaction := NodeUpdateTransaction{
nodeID: &nodeID,
accountID: accountID,
description: description,
gossipEndpoints: gossipEndpoints,
serviceEndpoints: serviceEndpoints,
gossipCaCertificate: &certificate,
grpcCertificateHash: certificateHash,
adminKey: adminKey,
grpcWebProxyEndpoint: grpcProxyEndpoint,
declineReward: declineReward,
}
tx.childTransaction = &nodeUpdateTransaction
nodeUpdateTransaction.Transaction = &tx
return nodeUpdateTransaction
}
// GetNodeID he consensus node identifier in the network state.
func (tx *NodeUpdateTransaction) GetNodeID() uint64 {
if tx.nodeID == nil {
return 0
}
return *tx.nodeID
}
// SetNodeID the consensus node identifier in the network state.
func (tx *NodeUpdateTransaction) SetNodeID(nodeID uint64) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.nodeID = &nodeID
return tx
}
// GetAccountID AccountID of the node
func (tx *NodeUpdateTransaction) GetAccountID() AccountID {
if tx.accountID == nil {
return AccountID{}
}
return *tx.accountID
}
// SetAccountID get the AccountID of the node
func (tx *NodeUpdateTransaction) SetAccountID(accountID AccountID) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.accountID = &accountID
return tx
}
// GetDescription get the description of the node
func (tx *NodeUpdateTransaction) GetDescription() string {
return tx.description
}
// SetDescription set the description of the node
func (tx *NodeUpdateTransaction) SetDescription(description string) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.description = description
return tx
}
// SetDescription remove the description contents.
func (tx *NodeUpdateTransaction) ClearDescription(description string) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.description = ""
return tx
}
// GetServiceEndpoints the list of service endpoints for gossip.
func (tx *NodeUpdateTransaction) GetGossipEndpoints() []Endpoint {
return tx.gossipEndpoints
}
// SetServiceEndpoints the list of service endpoints for gossip.
func (tx *NodeUpdateTransaction) SetGossipEndpoints(gossipEndpoints []Endpoint) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.gossipEndpoints = gossipEndpoints
return tx
}
// AddGossipEndpoint add an endpoint for gossip to the list of service endpoints for gossip.
func (tx *NodeUpdateTransaction) AddGossipEndpoint(endpoint Endpoint) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.gossipEndpoints = append(tx.gossipEndpoints, endpoint)
return tx
}
// GetServiceEndpoints the list of service endpoints for gRPC calls.
func (tx *NodeUpdateTransaction) GetServiceEndpoints() []Endpoint {
return tx.serviceEndpoints
}
// SetServiceEndpoints the list of service endpoints for gRPC calls.
func (tx *NodeUpdateTransaction) SetServiceEndpoints(serviceEndpoints []Endpoint) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.serviceEndpoints = serviceEndpoints
return tx
}
// AddServiceEndpoint the list of service endpoints for gRPC calls.
func (tx *NodeUpdateTransaction) AddServiceEndpoint(endpoint Endpoint) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.serviceEndpoints = append(tx.serviceEndpoints, endpoint)
return tx
}
// GetGossipCaCertificate the certificate used to sign gossip events.
func (tx *NodeUpdateTransaction) GetGossipCaCertificate() []byte {
if tx.gossipCaCertificate == nil {
return []byte{}
}
return *tx.gossipCaCertificate
}
// SetGossipCaCertificate the certificate used to sign gossip events.
// This value MUST be the DER encoding of the certificate presented.
func (tx *NodeUpdateTransaction) SetGossipCaCertificate(gossipCaCertificate []byte) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.gossipCaCertificate = &gossipCaCertificate
return tx
}
// GetGrpcCertificateHash the hash of the node gRPC TLS certificate.
func (tx *NodeUpdateTransaction) GetGrpcCertificateHash() []byte {
return tx.grpcCertificateHash
}
// SetGrpcCertificateHash the hash of the node gRPC TLS certificate.
// This value MUST be a SHA-384 hash.
func (tx *NodeUpdateTransaction) SetGrpcCertificateHash(grpcCertificateHash []byte) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.grpcCertificateHash = grpcCertificateHash
return tx
}
// GetAdminKey an administrative key controlled by the node operator.
func (tx *NodeUpdateTransaction) GetAdminKey() Key {
return tx.adminKey
}
// SetAdminKey an administrative key controlled by the node operator.
func (tx *NodeUpdateTransaction) SetAdminKey(adminKey Key) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.adminKey = adminKey
return tx
}
// GetDeclineReward Gets whether this node declines rewards.
func (tx *NodeUpdateTransaction) GetDeclineReward() *bool {
return tx.declineReward
}
// SetDeclineReward Sets whether this node declines rewards, true to decline rewards, false to accept.
// if not set - no change will be made
func (tx *NodeUpdateTransaction) SetDeclineReward(declineReward bool) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.declineReward = &declineReward
return tx
}
// GetGrpcWebProxyEndpoint Gets the gRPC proxy endpoint.
func (tx *NodeUpdateTransaction) GetGrpcWebProxyEndpoint() *Endpoint {
return tx.grpcWebProxyEndpoint
}
// SetGrpcWebProxyEndpoint Sets the gRPC proxy endpoint.
// if not set - no change will be made
func (tx *NodeUpdateTransaction) SetGrpcWebProxyEndpoint(grpcWebProxyEndpoint Endpoint) *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.grpcWebProxyEndpoint = &grpcWebProxyEndpoint
return tx
}
// DeleteGrpcWebProxyEndpoint Deletes the gRPC proxy endpoint and sets it to null in the mirror node.
func (tx *NodeUpdateTransaction) DeleteGrpcWebProxyEndpoint() *NodeUpdateTransaction {
tx._RequireNotFrozen()
tx.grpcWebProxyEndpoint = &Endpoint{}
return tx
}
// ----------- Overridden functions ----------------
func (tx NodeUpdateTransaction) getName() string {
return "NodeUpdateTransaction"
}
func (tx NodeUpdateTransaction) validateNetworkOnIDs(client *Client) error {
if client == nil || !client.autoValidateChecksums {
return nil
}
if tx.accountID != nil {
if err := tx.accountID.ValidateChecksum(client); err != nil {
return err
}
}
return nil
}
func (tx NodeUpdateTransaction) build() *services.TransactionBody {
return &services.TransactionBody{
TransactionFee: tx.transactionFee,
Memo: tx.Transaction.memo,
TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()),
TransactionID: tx.transactionID._ToProtobuf(),
Data: &services.TransactionBody_NodeUpdate{
NodeUpdate: tx.buildProtoBody(),
},
}
}
func (tx NodeUpdateTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) {
return &services.SchedulableTransactionBody{
TransactionFee: tx.transactionFee,
Memo: tx.Transaction.memo,
Data: &services.SchedulableTransactionBody_NodeUpdate{
NodeUpdate: tx.buildProtoBody(),
},
}, nil
}
func (tx NodeUpdateTransaction) buildProtoBody() *services.NodeUpdateTransactionBody {
body := &services.NodeUpdateTransactionBody{}
if tx.description != "" {
body.Description = wrapperspb.String(tx.description)
}
if tx.nodeID != nil {
body.NodeId = *tx.nodeID
}
if tx.accountID != nil {
body.AccountId = tx.accountID._ToProtobuf()
}
for _, endpoint := range tx.gossipEndpoints {
body.GossipEndpoint = append(body.GossipEndpoint, endpoint._ToProtobuf())
}
for _, endpoint := range tx.serviceEndpoints {
body.ServiceEndpoint = append(body.ServiceEndpoint, endpoint._ToProtobuf())
}
if tx.grpcWebProxyEndpoint != nil {
body.GrpcProxyEndpoint = tx.grpcWebProxyEndpoint._ToProtobuf()
}
if tx.gossipCaCertificate != nil {
body.GossipCaCertificate = wrapperspb.Bytes(*tx.gossipCaCertificate)
}
if tx.grpcCertificateHash != nil {
body.GrpcCertificateHash = wrapperspb.Bytes(tx.grpcCertificateHash)
}
if tx.adminKey != nil {
body.AdminKey = tx.adminKey._ToProtoKey()
}
if tx.declineReward != nil {
body.DeclineReward = wrapperspb.Bool(*tx.declineReward)
}
return body
}
func (tx NodeUpdateTransaction) preFreezeWith(client *Client, self TransactionInterface) {
if tx.gossipEndpoints != nil {
if len(tx.gossipEndpoints) > 10 {
tx.freezeError = errors.New("gossip endpoints must not contain more than 10 entries")
return
}
for _, endpoint := range tx.gossipEndpoints {
if err := endpoint.Validate(); err != nil {
tx.freezeError = err
return
}
}
}
if tx.serviceEndpoints != nil {
if len(tx.serviceEndpoints) > 8 {
tx.freezeError = errors.New("service endpoints must not contain more than 10 entries")
return
}
for _, endpoint := range tx.serviceEndpoints {
if err := endpoint.Validate(); err != nil {
tx.freezeError = err
return
}
}
}
// if tx.grpcWebProxyEndpoint != nil {
// if err := tx.grpcWebProxyEndpoint.Validate(); err != nil {
// tx.freezeError = err
// return
// }
// }
if tx.gossipCaCertificate != nil {
if len(*tx.gossipCaCertificate) == 0 {
tx.freezeError = errors.New("gossip ca certificate must not be empty")
return
}
}
if tx.description != "" {
if len(tx.description) > 100 {
tx.freezeError = errors.New("description must be less than 100 characters")
return
}
}
if tx.nodeID == nil {
tx.freezeError = errNodeIdIsRequired
}
}
func (tx NodeUpdateTransaction) getMethod(channel *_Channel) _Method {
return _Method{
transaction: channel._GetAddressBook().UpdateNode,
}
}
func (tx NodeUpdateTransaction) constructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
return tx.buildScheduled()
}
func (tx NodeUpdateTransaction) getBaseTransaction() *Transaction[TransactionInterface] {
return castFromConcreteToBaseTransaction(tx.Transaction, &tx)
}