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