mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +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.
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package rpc
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"github.com/kaspanet/kaspad/rpcmodel"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
)
|
|
|
|
// handleGetHeaders implements the getHeaders command.
|
|
func handleGetHeaders(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
|
c := cmd.(*rpcmodel.GetHeadersCmd)
|
|
|
|
lowHash := &daghash.ZeroHash
|
|
if c.LowHash != "" {
|
|
err := daghash.Decode(lowHash, c.LowHash)
|
|
if err != nil {
|
|
return nil, rpcDecodeHexError(c.HighHash)
|
|
}
|
|
}
|
|
highHash := &daghash.ZeroHash
|
|
if c.HighHash != "" {
|
|
err := daghash.Decode(highHash, c.HighHash)
|
|
if err != nil {
|
|
return nil, rpcDecodeHexError(c.HighHash)
|
|
}
|
|
}
|
|
headers, err := s.cfg.SyncMgr.BlueBlockHeadersBetween(lowHash, highHash)
|
|
if err != nil {
|
|
return nil, &rpcmodel.RPCError{
|
|
Code: rpcmodel.ErrRPCMisc,
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|