github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/request/get_account_key.go (about) 1 package request 2 3 import ( 4 "fmt" 5 6 "github.com/onflow/flow-go/engine/access/rest/util" 7 "github.com/onflow/flow-go/model/flow" 8 ) 9 10 const indexVar = "index" 11 12 type GetAccountKey struct { 13 Address flow.Address 14 Index uint64 15 Height uint64 16 } 17 18 func (g *GetAccountKey) Build(r *Request) error { 19 return g.Parse( 20 r.GetVar(addressVar), 21 r.GetVar(indexVar), 22 r.GetQueryParam(blockHeightQuery), 23 r.Chain, 24 ) 25 } 26 27 func (g *GetAccountKey) Parse( 28 rawAddress string, 29 rawIndex string, 30 rawHeight string, 31 chain flow.Chain, 32 ) error { 33 address, err := ParseAddress(rawAddress, chain) 34 if err != nil { 35 return err 36 } 37 38 index, err := util.ToUint64(rawIndex) 39 if err != nil { 40 return fmt.Errorf("invalid key index: %w", err) 41 } 42 43 var height Height 44 err = height.Parse(rawHeight) 45 if err != nil { 46 return err 47 } 48 49 g.Address = address 50 g.Index = index 51 g.Height = height.Flow() 52 53 // default to last block 54 if g.Height == EmptyHeight { 55 g.Height = SealedHeight 56 } 57 58 return nil 59 }