github.com/koko1123/flow-go-1@v0.29.6/engine/access/state_stream/handler.go (about)

     1  package state_stream
     2  
     3  import (
     4  	"context"
     5  
     6  	access "github.com/onflow/flow/protobuf/go/flow/executiondata"
     7  
     8  	"github.com/koko1123/flow-go-1/engine/common/rpc/convert"
     9  	"github.com/koko1123/flow-go-1/model/flow"
    10  )
    11  
    12  type Handler struct {
    13  	api   API
    14  	chain flow.Chain
    15  }
    16  
    17  // HandlerOption is used to hand over optional constructor parameters
    18  type HandlerOption func(*Handler)
    19  
    20  func NewHandler(api API, chain flow.Chain, options ...HandlerOption) *Handler {
    21  	h := &Handler{
    22  		api:   api,
    23  		chain: chain,
    24  	}
    25  	for _, opt := range options {
    26  		opt(h)
    27  	}
    28  	return h
    29  }
    30  
    31  func (h *Handler) GetExecutionDataByBlockID(ctx context.Context, request *access.GetExecutionDataByBlockIDRequest) (*access.GetExecutionDataByBlockIDResponse, error) {
    32  	blockID, err := convert.BlockID(request.GetBlockId())
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	execData, err := h.api.GetExecutionDataByBlockID(ctx, blockID)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	return &access.GetExecutionDataByBlockIDResponse{BlockExecutionData: execData}, nil
    43  }