Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Commit 2ad008c

Browse files
committed
update rpc store
1 parent bcd4022 commit 2ad008c

3 files changed

Lines changed: 14 additions & 260 deletions

File tree

testing/README.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,14 @@
22

33
This directory contains tools for testing the Clearnode API by creating properly signed RPC messages and interacting with the Clearnode server.
44

5-
## Overview
6-
7-
The testing toolkit consists of:
8-
9-
1. **Go Client** - A command-line utility for creating and sending signed RPC messages
10-
2. **Interactive Shell Script** - A bash-based interactive menu for common testing operations
11-
12-
These tools automatically handle authentication, private key management, and message signing according to the Clearnode protocol.
5+
The tool automatically handle authentication, private key management, and message signing according to the Clearnode protocol.
136

147
## Quick Start
158

16-
For most testing scenarios, use the interactive test script:
17-
189
```bash
19-
# Set a custom server (optional)
20-
export SERVER="ws://your-server.com:8000/ws"
21-
22-
# Run the interactive test menu
23-
./test_api.sh
24-
```
25-
26-
Or use the Go client directly for specific operations:
10+
# Generate a signer key
11+
go run . --genkey 1 # Creates signer_key_1.hex
2712

28-
```bash
2913
# Generate a signed message only
3014
go run . --method ping
3115

testing/test_api.sh

Lines changed: 0 additions & 233 deletions
This file was deleted.

ws.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)