@@ -5,6 +5,7 @@ package methods
55import (
66 "context"
77 "encoding/hex"
8+ "errors"
89 "strconv"
910
1011 "github.com/hiero-ledger/hiero-sdk-go/tck/param"
@@ -107,6 +108,136 @@ func (n *NodeService) CreateNode(_ context.Context, params param.CreateNodeParam
107108 return & response.NodeResponse {NodeId : nodeId , Status : receipt .Status .String ()}, nil
108109}
109110
111+ func (n * NodeService ) UpdateNode (_ context.Context , params param.UpdateNodeParams ) (* response.NodeResponse , error ) {
112+ transaction := hiero .NewNodeUpdateTransaction ().SetGrpcDeadline (& threeSecondsDuration )
113+
114+ if params .NodeId != nil {
115+ nodeId , err := strconv .ParseUint (* params .NodeId , 10 , 64 )
116+ if err != nil {
117+ return nil , err
118+ }
119+ transaction .SetNodeID (nodeId )
120+ }
121+
122+ if err := utils .SetAccountIDIfPresent (params .AccountId , transaction .SetAccountID ); err != nil {
123+ return nil , err
124+ }
125+
126+ if params .Description != nil {
127+ transaction .SetDescription (* params .Description )
128+ }
129+
130+ if params .GossipEndpoints != nil {
131+ if len (* params .GossipEndpoints ) == 0 {
132+ return nil , errors .New ("gossip endpoints must not be empty" )
133+ }
134+ for _ , endpointParam := range * params .GossipEndpoints {
135+ endpoint , err := convertEndpointParam (endpointParam )
136+ if err != nil {
137+ return nil , err
138+ }
139+ transaction .AddGossipEndpoint (endpoint )
140+ }
141+ }
142+
143+ if params .ServiceEndpoints != nil {
144+ if len (* params .ServiceEndpoints ) == 0 {
145+ return nil , errors .New ("service endpoints must not be empty" )
146+ }
147+ for _ , endpointParam := range * params .ServiceEndpoints {
148+ endpoint , err := convertEndpointParam (endpointParam )
149+ if err != nil {
150+ return nil , err
151+ }
152+ transaction .AddServiceEndpoint (endpoint )
153+ }
154+ }
155+
156+ if params .GossipCaCertificate != nil {
157+ certBytes , err := hex .DecodeString (* params .GossipCaCertificate )
158+ if err != nil {
159+ return nil , err
160+ }
161+ transaction .SetGossipCaCertificate (certBytes )
162+ }
163+
164+ if params .GrpcCertificateHash != nil {
165+ hashBytes , err := hex .DecodeString (* params .GrpcCertificateHash )
166+ if err != nil {
167+ return nil , err
168+ }
169+ transaction .SetGrpcCertificateHash (hashBytes )
170+ }
171+
172+ if err := utils .SetKeyIfPresent (params .AdminKey , transaction .SetAdminKey ); err != nil {
173+ return nil , err
174+ }
175+
176+ if params .DeclineReward != nil {
177+ transaction .SetDeclineReward (* params .DeclineReward )
178+ }
179+
180+ if params .GrpcWebProxyEndpoint != nil {
181+ endpoint , err := convertEndpointParam (* params .GrpcWebProxyEndpoint )
182+ if err != nil {
183+ return nil , err
184+ }
185+ transaction .SetGrpcWebProxyEndpoint (endpoint )
186+ }
187+
188+ if params .CommonTransactionParams != nil {
189+ err := params .CommonTransactionParams .FillOutTransaction (transaction , n .sdkService .Client )
190+ if err != nil {
191+ return nil , err
192+ }
193+ }
194+
195+ txResponse , err := transaction .Execute (n .sdkService .Client )
196+ if err != nil {
197+ return nil , err
198+ }
199+
200+ receipt , err := txResponse .SetValidateStatus (true ).GetReceipt (n .sdkService .Client )
201+ if err != nil {
202+ return nil , err
203+ }
204+
205+ var nodeId = strconv .FormatUint (receipt .NodeID , 10 )
206+
207+ return & response.NodeResponse {NodeId : nodeId , Status : receipt .Status .String ()}, nil
208+ }
209+
210+ func (n * NodeService ) DeleteNode (_ context.Context , params param.DeleteNodeParams ) (* response.NodeResponse , error ) {
211+ transaction := hiero .NewNodeDeleteTransaction ().SetGrpcDeadline (& threeSecondsDuration )
212+
213+ if params .NodeId != nil {
214+ nodeId , err := strconv .ParseUint (* params .NodeId , 10 , 64 )
215+ if err != nil {
216+ return nil , err
217+ }
218+ transaction .SetNodeID (nodeId )
219+ }
220+
221+ if params .CommonTransactionParams != nil {
222+ err := params .CommonTransactionParams .FillOutTransaction (transaction , n .sdkService .Client )
223+ if err != nil {
224+ return nil , err
225+ }
226+ }
227+
228+ txResponse , err := transaction .Execute (n .sdkService .Client )
229+ if err != nil {
230+ return nil , err
231+ }
232+
233+ receipt , err := txResponse .SetValidateStatus (true ).GetReceipt (n .sdkService .Client )
234+ if err != nil {
235+ return nil , err
236+ }
237+
238+ return & response.NodeResponse {Status : receipt .Status .String ()}, nil
239+ }
240+
110241func convertEndpointParam (endpointParam param.EndpointParams ) (hiero.Endpoint , error ) {
111242 endpoint := hiero.Endpoint {}
112243
0 commit comments