github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/request/script.go (about)

     1  package request
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/onflow/flow-go/engine/access/rest/util"
     8  )
     9  
    10  type scriptBody struct {
    11  	Script    string   `json:"script,omitempty"`
    12  	Arguments []string `json:"arguments,omitempty"`
    13  }
    14  
    15  type Script struct {
    16  	Args   Arguments
    17  	Source []byte
    18  }
    19  
    20  func (s *Script) Parse(raw io.Reader) error {
    21  	var body scriptBody
    22  	err := parseBody(raw, &body)
    23  	if err != nil {
    24  		return err
    25  	}
    26  
    27  	source, err := util.FromBase64(body.Script)
    28  	if err != nil {
    29  		return fmt.Errorf("invalid script source encoding")
    30  	}
    31  
    32  	var args Arguments
    33  	err = args.Parse(body.Arguments)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	s.Source = source
    39  	s.Args = args
    40  
    41  	return nil
    42  }