Fix RPC handler registration and BlockGetChunkResp name.
This commit is contained in:
parent
8c8871b4d2
commit
b298454727
3 changed files with 21 additions and 9 deletions
|
@ -88,10 +88,10 @@ func min[Ord constraints.Ordered](x, y Ord) Ord {
|
|||
}
|
||||
|
||||
type BlockGetChunkReq uint32
|
||||
type blockGetChunkResp string
|
||||
type BlockGetChunkResp string
|
||||
|
||||
// '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)
|
||||
db_headers, err := s.DB.GetHeaders(index*CHUNK_SIZE, CHUNK_SIZE)
|
||||
if err != nil {
|
||||
|
@ -101,7 +101,7 @@ func (s *BlockchainService) Get_chunk(r *http.Request, req *BlockGetChunkReq, re
|
|||
for _, h := range db_headers {
|
||||
raw = append(raw, h[:]...)
|
||||
}
|
||||
headers := blockGetChunkResp(hex.EncodeToString(raw))
|
||||
headers := BlockGetChunkResp(hex.EncodeToString(raw))
|
||||
*resp = &headers
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestGetChunk(t *testing.T) {
|
|||
|
||||
for index := 0; index < 10; index++ {
|
||||
req := BlockGetChunkReq(index)
|
||||
var resp *blockGetChunkResp
|
||||
var resp *BlockGetChunkResp
|
||||
err := s.Get_chunk(nil, &req, &resp)
|
||||
if err != nil {
|
||||
t.Errorf("index: %v handler err: %v", index, err)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -9,6 +8,7 @@ import (
|
|||
"github.com/gorilla/rpc/json"
|
||||
"github.com/lbryio/herald.go/db"
|
||||
pb "github.com/lbryio/herald.go/protobuf/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ClaimtrieService struct {
|
||||
|
@ -41,13 +41,25 @@ func (s *Server) StartJsonRPC() error {
|
|||
|
||||
// Register "blockchain.claimtrie.*"" handlers.
|
||||
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.
|
||||
blockchainSvc := &BlockchainService{s.DB, s.Chain}
|
||||
s1.RegisterService(&blockchainSvc, "blockchain_block")
|
||||
s1.RegisterService(&BlockchainAddressService{*blockchainSvc}, "blockchain_address")
|
||||
s1.RegisterService(&BlockchainScripthashService{*blockchainSvc}, "blockchain_scripthash")
|
||||
err = s1.RegisterService(blockchainSvc, "blockchain_block")
|
||||
if err != nil {
|
||||
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.Handle("/rpc", s1)
|
||||
|
|
Loading…
Add table
Reference in a new issue