network: allow to use -1 to specify GetBlockByIndex.Count

This commit is contained in:
Anna Shaleva 2020-07-31 14:17:14 +03:00
parent 0b856033b0
commit 0b0591fc34
2 changed files with 10 additions and 6 deletions

View file

@ -611,7 +611,11 @@ func (s *Server) handleGetBlocksCmd(p Peer, gb *payload.GetBlocks) error {
// handleGetBlockByIndexCmd processes the getblockbyindex request.
func (s *Server) handleGetBlockByIndexCmd(p Peer, gbd *payload.GetBlockByIndex) error {
for i := gbd.IndexStart; i < gbd.IndexStart+uint32(gbd.Count); i++ {
count := gbd.Count
if gbd.Count < 0 || gbd.Count > payload.MaxHashesCount {
count = payload.MaxHashesCount
}
for i := gbd.IndexStart; i < gbd.IndexStart+uint32(count); i++ {
b, err := s.chain.GetBlock(s.chain.GetHeaderHash(int(i)))
if err != nil {
return err