mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 01:41:48 +00:00
Merge pull request #982 from nspcc-dev/neo3/protocol/getblockdata
protocol: implement getblockdata p2p command
This commit is contained in:
commit
bd98940a54
5 changed files with 105 additions and 26 deletions
|
@ -560,6 +560,19 @@ func (s *Server) handleGetBlocksCmd(p Peer, gb *payload.GetBlocks) error {
|
|||
return p.EnqueueP2PMessage(msg)
|
||||
}
|
||||
|
||||
// handleGetBlockDataCmd processes the getblockdata request.
|
||||
func (s *Server) handleGetBlockDataCmd(p Peer, gbd *payload.GetBlockData) error {
|
||||
for i := gbd.IndexStart; i < gbd.IndexStart+uint32(gbd.Count); i++ {
|
||||
b, err := s.chain.GetBlock(s.chain.GetHeaderHash(int(i)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := NewMessage(CMDBlock, b)
|
||||
return p.EnqueueP2PMessage(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleGetHeadersCmd processes the getheaders request.
|
||||
func (s *Server) handleGetHeadersCmd(p Peer, gh *payload.GetBlocks) error {
|
||||
count := gh.Count
|
||||
|
@ -685,6 +698,9 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error {
|
|||
case CMDGetBlocks:
|
||||
gb := msg.Payload.(*payload.GetBlocks)
|
||||
return s.handleGetBlocksCmd(peer, gb)
|
||||
case CMDGetBlockData:
|
||||
gbd := msg.Payload.(*payload.GetBlockData)
|
||||
return s.handleGetBlockDataCmd(peer, gbd)
|
||||
case CMDGetData:
|
||||
inv := msg.Payload.(*payload.Inventory)
|
||||
return s.handleGetDataCmd(peer, inv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue