github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/message/block_request.go (about)

     1  // (c) 2021-2022, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package message
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  
    10  	"github.com/MetalBlockchain/metalgo/ids"
    11  
    12  	"github.com/ethereum/go-ethereum/common"
    13  )
    14  
    15  var (
    16  	_ Request = BlockRequest{}
    17  )
    18  
    19  // BlockRequest is a request to retrieve Parents number of blocks starting from Hash from newest-oldest manner
    20  type BlockRequest struct {
    21  	Hash    common.Hash `serialize:"true"`
    22  	Height  uint64      `serialize:"true"`
    23  	Parents uint16      `serialize:"true"`
    24  }
    25  
    26  func (b BlockRequest) String() string {
    27  	return fmt.Sprintf(
    28  		"BlockRequest(Hash=%s, Height=%d, Parents=%d)",
    29  		b.Hash, b.Height, b.Parents,
    30  	)
    31  }
    32  
    33  func (b BlockRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) {
    34  	return handler.HandleBlockRequest(ctx, nodeID, requestID, b)
    35  }
    36  
    37  // BlockResponse is a response to a BlockRequest
    38  // Blocks is slice of RLP encoded blocks starting with the block
    39  // requested in BlockRequest.Hash. The next block is the parent, etc.
    40  // handler: handlers.BlockRequestHandler
    41  type BlockResponse struct {
    42  	Blocks [][]byte `serialize:"true"`
    43  }