mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-24 15:02:32 +00:00

* [NOD-669] Remove the "get" from getBlueBlocksBetween. * [NOD-669] Remove the "Get" from GetBlueBlocksHeadersBetween. * [NOD-669] In blueBlocksBetween, rename startHash to lowHash and stopHash to highHash. * [NOD-669] Rename startHash to lowHash and stopHash to highHash in blockLocator logic. * [NOD-669] Remove zeroHash logic in blockLocator. * [NOD-669] Finish renaming startHash and stopHash in blockdag. * [NOD-669] Rename startHash and stopHash in blockdag where I previously missed it. * [NOD-669] Rename startHash and stopHash in blockdag where I previously missed it some more. * [NOD-669] Rename startHash and stopHash in blockdag where I previously missed it some more some more. * [NOD-669] Fix bad grammar in method names. * [NOD-669] Rename lowHash to blockHash in SelectedParentChain. * [NOD-669] Fix a comment.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package rpc
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"github.com/kaspanet/kaspad/rpcmodel"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
)
|
|
|
|
// handleGetTopHeaders implements the getTopHeaders command.
|
|
func handleGetTopHeaders(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
|
c := cmd.(*rpcmodel.GetTopHeadersCmd)
|
|
|
|
var highHash *daghash.Hash
|
|
if c.HighHash != nil {
|
|
highHash = &daghash.Hash{}
|
|
err := daghash.Decode(highHash, *c.HighHash)
|
|
if err != nil {
|
|
return nil, rpcDecodeHexError(*c.HighHash)
|
|
}
|
|
}
|
|
headers, err := s.cfg.DAG.GetTopHeaders(highHash)
|
|
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
|
|
}
|