github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/request/address.go (about)

     1  package request
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"strings"
     7  
     8  	"github.com/koko1123/flow-go-1/model/flow"
     9  )
    10  
    11  type Address flow.Address
    12  
    13  func (a *Address) Parse(raw string) error {
    14  	raw = strings.ReplaceAll(raw, "0x", "") // remove 0x prefix
    15  
    16  	valid, _ := regexp.MatchString(`^[0-9a-fA-F]{16}$`, raw)
    17  	if !valid {
    18  		return fmt.Errorf("invalid address")
    19  	}
    20  
    21  	*a = Address(flow.HexToAddress(raw))
    22  	return nil
    23  }
    24  
    25  func (a Address) Flow() flow.Address {
    26  	return flow.Address(a)
    27  }