mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-12 00:56:42 +00:00

* [NOD-275] Moved getBlockTemplate and related functionality to a separate file. * [NOD-275] Started moving handlers to separate files. * [NOD-275] Fixed merge errors. * [NOD-275] Moved all handlers out of rpcserver.go. * [NOD-275] Moved non-shared functions out of rpcserver.go. * [NOD-275] Moved handleGetAllManualNodesInfo to a separate file. * [NOD-275] Moved handlers out of rpcwebsocket.go to separate files. * [NOD-275] Fixed import error. * [NOD-275] Renamed all handler files to include underscores. * [NOD-275] Moved common rpc helper functions to common.go.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package rpc
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"github.com/daglabs/btcd/btcjson"
|
|
"github.com/daglabs/btcd/util/daghash"
|
|
)
|
|
|
|
// handleGetTopHeaders implements the getTopHeaders command.
|
|
func handleGetTopHeaders(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
|
c := cmd.(*btcjson.GetTopHeadersCmd)
|
|
|
|
var startHash *daghash.Hash
|
|
if c.StartHash != nil {
|
|
startHash = &daghash.Hash{}
|
|
err := daghash.Decode(startHash, *c.StartHash)
|
|
if err != nil {
|
|
return nil, rpcDecodeHexError(*c.StartHash)
|
|
}
|
|
}
|
|
headers, err := s.cfg.DAG.GetTopHeaders(startHash)
|
|
if err != nil {
|
|
return nil, internalRPCError(err.Error(),
|
|
"Failed to get top headers")
|
|
}
|
|
|
|
// Return the serialized block headers as hex-encoded strings.
|
|
hexBlockHeaders := make([]string, len(headers))
|
|
var buf bytes.Buffer
|
|
for i, h := range headers {
|
|
err := h.Serialize(&buf)
|
|
if err != nil {
|
|
return nil, internalRPCError(err.Error(),
|
|
"Failed to serialize block header")
|
|
}
|
|
hexBlockHeaders[i] = hex.EncodeToString(buf.Bytes())
|
|
buf.Reset()
|
|
}
|
|
return hexBlockHeaders, nil
|
|
}
|