Skip to content

Commit

Permalink
fixed logic to return proper json using CometBFT libs/json (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
andynog committed Jun 21, 2023
1 parent 3c9a97a commit 4a8c39b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rpc/service.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package rpc

import (
"encoding/json"
"fmt"
cmtjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/rpc/jsonrpc/types"
"github.com/cometbft/rpc-companion/storage"
"log"
Expand Down Expand Up @@ -67,20 +67,20 @@ func (s *Service) handleBlock(writer http.ResponseWriter, request *http.Request)
writer.Write([]byte("Internal Server Error"))
}
// Return response
blockJSON, err := json.Marshal(block)
id := types.JSONRPCStringID("id")
//TODO: Empty objects return 'null' should return '[]'
blockJSON, err := cmtjson.Marshal(block)
if err != nil {
log.Println("Error marshalling block: ", err)
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte("Internal Server Error"))
} else {
RPCResponse := types.RPCResponse{
var RPCResponse = types.RPCResponse{
JSONRPC: "2.0",
ID: id,
ID: nil, //TODO: Figure out a way to properly return this avoiding error 'cannot encode unregistered type types.JSONRPCIntID'
Result: blockJSON,
Error: nil,
}
resp, err := json.Marshal(RPCResponse)
resp, err := cmtjson.Marshal(RPCResponse)
if err != nil {
log.Println("Error marshalling RPCResponse: ", err)
writer.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 4a8c39b

Please sign in to comment.