@@ -219,6 +219,7 @@ func (h *UnifiedWSHandler) HandleConnection(w http.ResponseWriter, r *http.Reque
219219
220220 var rpcResponse = & RPCMessage {}
221221 var handlerErr error
222+ var recordHistory = false
222223
223224 // Track RPC request by method
224225 h .metrics .RPCRequests .WithLabelValues (msg .Req .Method ).Inc ()
@@ -280,7 +281,7 @@ func (h *UnifiedWSHandler) HandleConnection(w http.ResponseWriter, r *http.Reque
280281 continue
281282 }
282283 h .sendBalanceUpdate (address )
283-
284+ recordHistory = true
284285 case "close_app_session" :
285286 rpcResponse , handlerErr = HandleCloseApplication (& msg , h .db )
286287 if handlerErr != nil {
@@ -289,7 +290,7 @@ func (h *UnifiedWSHandler) HandleConnection(w http.ResponseWriter, r *http.Reque
289290 continue
290291 }
291292 h .sendBalanceUpdate (address )
292-
293+ recordHistory = true
293294 case "get_app_sessions" :
294295 rpcResponse , handlerErr = HandleGetAppSessions (& msg , h .db )
295296 if handlerErr != nil {
@@ -305,15 +306,15 @@ func (h *UnifiedWSHandler) HandleConnection(w http.ResponseWriter, r *http.Reque
305306 h .sendErrorResponse (address , & msg , conn , "Failed to resize channel: " + handlerErr .Error ())
306307 continue
307308 }
308-
309+ recordHistory = true
309310 case "close_channel" :
310311 rpcResponse , handlerErr = HandleCloseChannel (& msg , h .db , h .signer )
311312 if handlerErr != nil {
312313 log .Printf ("Error handling close_channel: %v" , handlerErr )
313314 h .sendErrorResponse (address , & msg , conn , "Failed to close channel: " + handlerErr .Error ())
314315 continue
315316 }
316-
317+ recordHistory = true
317318 case "get_channels" :
318319 rpcResponse , handlerErr = HandleGetChannels (& msg , h .db )
319320 if handlerErr != nil {
@@ -336,14 +337,16 @@ func (h *UnifiedWSHandler) HandleConnection(w http.ResponseWriter, r *http.Reque
336337 }
337338
338339 // For broker methods, send back a signed RPC response.
339- byteData , _ := json .Marshal (rpcResponse .Req )
340+ byteData , _ := json .Marshal (rpcResponse .Res )
340341 signature , _ := h .signer .Sign (byteData )
341342 rpcResponse .Sig = []string {hexutil .Encode (signature )}
342343 wsResponseData , _ := json .Marshal (rpcResponse )
343344
344- if err := h .rpcStore .StoreMessage (address , msg .Req , msg .Sig , byteData , rpcResponse .Sig ); err != nil {
345- log .Printf ("Failed to store RPC message: %v" , err )
346- // continue processing even if storage fails
345+ if recordHistory {
346+ if err := h .rpcStore .StoreMessage (address , msg .Req , msg .Sig , byteData , rpcResponse .Sig ); err != nil {
347+ log .Printf ("Failed to store RPC message: %v" , err )
348+ // continue processing even if storage fails
349+ }
347350 }
348351
349352 // Use NextWriter for safer message delivery
0 commit comments