github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/request/get_script.go (about)

     1  package request
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/koko1123/flow-go-1/model/flow"
     8  )
     9  
    10  const blockIDQuery = "block_id"
    11  
    12  type GetScript struct {
    13  	BlockID     flow.Identifier
    14  	BlockHeight uint64
    15  	Script      Script
    16  }
    17  
    18  func (g *GetScript) Build(r *Request) error {
    19  	return g.Parse(
    20  		r.GetQueryParam(blockHeightQuery),
    21  		r.GetQueryParam(blockIDQuery),
    22  		r.Body,
    23  	)
    24  }
    25  
    26  func (g *GetScript) Parse(rawHeight string, rawID string, rawScript io.Reader) error {
    27  	var height Height
    28  	err := height.Parse(rawHeight)
    29  	if err != nil {
    30  		return err
    31  	}
    32  	g.BlockHeight = height.Flow()
    33  
    34  	var id ID
    35  	err = id.Parse(rawID)
    36  	if err != nil {
    37  		return err
    38  	}
    39  	g.BlockID = id.Flow()
    40  
    41  	var script Script
    42  	err = script.Parse(rawScript)
    43  	if err != nil {
    44  		return err
    45  	}
    46  	g.Script = script
    47  
    48  	// default to last sealed block
    49  	if g.BlockHeight == EmptyHeight && g.BlockID == flow.ZeroID {
    50  		g.BlockHeight = SealedHeight
    51  	}
    52  
    53  	if g.BlockID != flow.ZeroID && g.BlockHeight != EmptyHeight {
    54  		return fmt.Errorf("can not provide both block ID and block height")
    55  	}
    56  
    57  	return nil
    58  }