From a52fae2afa1bc24c74b9d8dcfa1a3f5584a7b243 Mon Sep 17 00:00:00 2001
From: a <a@tuxpa.in>
Date: Sun, 4 Dec 2022 02:02:09 -0600
Subject: [PATCH] organize

---
 handler.go | 7 +++----
 json.go    | 7 +++++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/handler.go b/handler.go
index 7c2581e..7cf36e1 100644
--- a/handler.go
+++ b/handler.go
@@ -212,7 +212,7 @@ func (h *handler) handleImmediate(msg *jsonrpcMessage) bool {
 		}
 		return false
 	case msg.isResponse():
-		h.handleResponse(msg)
+		h.handleResponse(msg.toResponse())
 		h.log.Trace().Str("reqid", string(msg.ID.RawMessage())).Dur("duration", time.Since(start)).Msg("Handled RPC response")
 		return true
 	default:
@@ -231,8 +231,7 @@ func (h *handler) handleSubscriptionResult(msg *jsonrpcMessage) {
 	}
 }
 
-// handleResponse processes method call responses.
-func (h *handler) handleResponse(msg *jsonrpcMessage) {
+func (h *handler) handleResponse(msg *Response) {
 	op := h.respWait[string(msg.ID.RawMessage())]
 	if op == nil {
 		h.log.Debug().Str("reqid", string(msg.ID.RawMessage())).Msg("Unsolicited RPC response")
@@ -241,7 +240,7 @@ func (h *handler) handleResponse(msg *jsonrpcMessage) {
 	delete(h.respWait, string(msg.ID.RawMessage()))
 	if op.sub == nil {
 		// not a sub, so just send the msg back
-		op.resp <- msg
+		op.resp <- msg.Msg()
 		return
 	}
 	// For subscription responses, start the subscription if the server
diff --git a/json.go b/json.go
index 77f48e8..daa1fad 100644
--- a/json.go
+++ b/json.go
@@ -52,6 +52,13 @@ func (msg *jsonrpcMessage) isCall() bool {
 func (msg *jsonrpcMessage) isResponse() bool {
 	return msg.hasValidID() && len(msg.Method) == 0 && msg.Params == nil && (msg.Result != nil || msg.Error != nil)
 }
+func (msg *jsonrpcMessage) toResponse() *Response {
+	return &Response{
+		ID:     msg.ID,
+		Result: msg.Result,
+		Error:  msg.Error,
+	}
+}
 func (msg *jsonrpcMessage) hasValidID() bool {
 	return msg.ID != nil && !msg.ID.null
 }
-- 
GitLab