-
Notifications
You must be signed in to change notification settings - Fork 175
/
get_account_key.go
59 lines (48 loc) · 967 Bytes
/
get_account_key.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
59
package request
import (
"fmt"
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)
const indexVar = "index"
type GetAccountKey struct {
Address flow.Address
Index uint64
Height uint64
}
func (g *GetAccountKey) Build(r *Request) error {
return g.Parse(
r.GetVar(addressVar),
r.GetVar(indexVar),
r.GetQueryParam(blockHeightQuery),
r.Chain,
)
}
func (g *GetAccountKey) Parse(
rawAddress string,
rawIndex string,
rawHeight string,
chain flow.Chain,
) error {
address, err := ParseAddress(rawAddress, chain)
if err != nil {
return err
}
index, err := util.ToUint64(rawIndex)
if err != nil {
return fmt.Errorf("invalid key index: %w", err)
}
var height Height
err = height.Parse(rawHeight)
if err != nil {
return err
}
g.Address = address
g.Index = index
g.Height = height.Flow()
// default to last block
if g.Height == EmptyHeight {
g.Height = SealedHeight
}
return nil
}