github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/request/address.go (about) 1 package request 2 3 import ( 4 "fmt" 5 "regexp" 6 "strings" 7 8 "github.com/onflow/flow-go/engine/common/rpc/convert" 9 "github.com/onflow/flow-go/model/flow" 10 ) 11 12 func ParseAddress(raw string, chain flow.Chain) (flow.Address, error) { 13 raw = strings.ReplaceAll(raw, "0x", "") // remove 0x prefix 14 15 valid, _ := regexp.MatchString(`^[0-9a-fA-F]{16}$`, raw) 16 if !valid { 17 return flow.EmptyAddress, fmt.Errorf("invalid address") 18 } 19 20 address, err := convert.HexToAddress(raw, chain) 21 if err != nil { 22 return flow.EmptyAddress, err 23 } 24 25 return address, nil 26 }