Fix RPC handler registration and BlockGetChunkResp name.

This commit is contained in:
Jonathan Moody 2022-09-08 11:50:06 -05:00
parent 8c8871b4d2
commit b298454727
3 changed files with 21 additions and 9 deletions

View file

@ -88,10 +88,10 @@ func min[Ord constraints.Ordered](x, y Ord) Ord {
} }
type BlockGetChunkReq uint32 type BlockGetChunkReq uint32
type blockGetChunkResp string type BlockGetChunkResp string
// 'blockchain.block.get_chunk' // 'blockchain.block.get_chunk'
func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, resp **blockGetChunkResp) error { func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, resp **BlockGetChunkResp) error {
index := uint32(*req) index := uint32(*req)
db_headers, err := s.DB.GetHeaders(index*CHUNK_SIZE, CHUNK_SIZE) db_headers, err := s.DB.GetHeaders(index*CHUNK_SIZE, CHUNK_SIZE)
if err != nil { if err != nil {
@ -101,7 +101,7 @@ func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, re
for _, h := range db_headers { for _, h := range db_headers {
raw = append(raw, h[:]...) raw = append(raw, h[:]...)
} }
headers := blockGetChunkResp(hex.EncodeToString(raw)) headers := BlockGetChunkResp(hex.EncodeToString(raw))
*resp = &headers *resp = &headers
return err return err
} }

View file

@ -27,7 +27,7 @@ func TestGetChunk(t *testing.T) {
for index := 0; index < 10; index++ { for index := 0; index < 10; index++ {
req := BlockGetChunkReq(index) req := BlockGetChunkReq(index)
var resp *blockGetChunkResp var resp *BlockGetChunkResp
err := s.Get_chunk(nil, &req, &resp) err := s.Get_chunk(nil, &req, &resp)
if err != nil { if err != nil {
t.Errorf("index: %v handler err: %v", index, err) t.Errorf("index: %v handler err: %v", index, err)

View file

@ -1,7 +1,6 @@
package server package server
import ( import (
"log"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -9,6 +8,7 @@ import (
"github.com/gorilla/rpc/json" "github.com/gorilla/rpc/json"
"github.com/lbryio/herald.go/db" "github.com/lbryio/herald.go/db"
pb "github.com/lbryio/herald.go/protobuf/go" pb "github.com/lbryio/herald.go/protobuf/go"
log "github.com/sirupsen/logrus"
) )
type ClaimtrieService struct { type ClaimtrieService struct {
@ -41,13 +41,25 @@ func (s *Server) StartJsonRPC() error {
// Register "blockchain.claimtrie.*"" handlers. // Register "blockchain.claimtrie.*"" handlers.
claimtrieSvc := &ClaimtrieService{s.DB} claimtrieSvc := &ClaimtrieService{s.DB}
s1.RegisterService(claimtrieSvc, "blockchain_claimtrie") err := s1.RegisterService(claimtrieSvc, "blockchain_claimtrie")
if err != nil {
log.Errorf("RegisterService: %v\n", err)
}
// Register other "blockchain.{block,address,scripthash}.*" handlers. // Register other "blockchain.{block,address,scripthash}.*" handlers.
blockchainSvc := &BlockchainService{s.DB, s.Chain} blockchainSvc := &BlockchainService{s.DB, s.Chain}
s1.RegisterService(&blockchainSvc, "blockchain_block") err = s1.RegisterService(blockchainSvc, "blockchain_block")
s1.RegisterService(&BlockchainAddressService{*blockchainSvc}, "blockchain_address") if err != nil {
s1.RegisterService(&BlockchainScripthashService{*blockchainSvc}, "blockchain_scripthash") log.Errorf("RegisterService: %v\n", err)
}
err = s1.RegisterService(&BlockchainAddressService{*blockchainSvc}, "blockchain_address")
if err != nil {
log.Errorf("RegisterService: %v\n", err)
}
err = s1.RegisterService(&BlockchainScripthashService{*blockchainSvc}, "blockchain_scripthash")
if err != nil {
log.Errorf("RegisterService: %v\n", err)
}
r := mux.NewRouter() r := mux.NewRouter()
r.Handle("/rpc", s1) r.Handle("/rpc", s1)