From 71e79c553e51939f1ce5d7d85abdd0c83d131eb7 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Thu, 8 Sep 2022 13:17:52 -0500 Subject: [PATCH] One more RPC (get_server_height), and update comment to include full RPC name. --- server/jsonrpc_blockchain.go | 12 ++++++++++++ server/jsonrpc_blockchain_test.go | 30 ++++++++++++++++++++++++++++++ server/jsonrpc_service.go | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/server/jsonrpc_blockchain.go b/server/jsonrpc_blockchain.go index dc091da..41b6809 100644 --- a/server/jsonrpc_blockchain.go +++ b/server/jsonrpc_blockchain.go @@ -87,6 +87,18 @@ func min[Ord constraints.Ordered](x, y Ord) Ord { return y } +type BlockGetServerHeightReq struct{} +type BlockGetServerHeightResp uint32 + +func (s *BlockchainService) Get_server_height(r *http.Request, req *BlockGetServerHeightReq, resp **BlockGetServerHeightResp) error { + if s.DB == nil || s.DB.LastState == nil { + return fmt.Errorf("unknown height") + } + result := BlockGetServerHeightResp(s.DB.LastState.Height) + *resp = &result + return nil +} + type BlockGetChunkReq uint32 type BlockGetChunkResp string diff --git a/server/jsonrpc_blockchain_test.go b/server/jsonrpc_blockchain_test.go index 339ec5d..1799aa2 100644 --- a/server/jsonrpc_blockchain_test.go +++ b/server/jsonrpc_blockchain_test.go @@ -8,6 +8,36 @@ import ( "github.com/lbryio/lbcd/chaincfg" ) +func TestServerGetHeight(t *testing.T) { + dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb" + // dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/" + secondaryPath := "asdf" + db, toDefer, err := db.GetProdDB(dbPath, secondaryPath) + defer toDefer() + if err != nil { + t.Skip("DB not found") + t.Error(err) + return + } + + s := &BlockchainService{ + DB: db, + Chain: &chaincfg.MainNetParams, + } + + req := BlockGetServerHeightReq{} + var resp *BlockGetServerHeightResp + err = s.Get_server_height(nil, &req, &resp) + if err != nil { + t.Errorf("handler err: %v", err) + } + marshalled, err := json.MarshalIndent(resp, "", " ") + if err != nil { + t.Errorf("unmarshal err: %v", err) + } + t.Logf("resp: %v", string(marshalled)) +} + func TestGetChunk(t *testing.T) { dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb" // dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/" diff --git a/server/jsonrpc_service.go b/server/jsonrpc_service.go index cd94e5d..130d2d3 100644 --- a/server/jsonrpc_service.go +++ b/server/jsonrpc_service.go @@ -23,7 +23,7 @@ type Result struct { Data string `json:"data"` } -// Resolve is the json rpc endpoint for resolve +// Resolve is the json rpc endpoint for 'blockchain.claimtrie.resolve'. func (t *ClaimtrieService) Resolve(r *http.Request, args *ResolveData, result **pb.Outputs) error { log.Println("Resolve") res, err := InternalResolve(args.Data, t.DB)