func (a AccountID) ToName() (Name, bool) {
	if len(a.Value) == 0 {
		return Name{}, false
	}
	if a.Value[0] == accountIDTypeName {
		return NewNameFromBytes(a.Value), true
	}
	return Name{}, false
}
ToName if `a` is a name return name and true
package types
import (
	"bytes"
	"encoding/json"
	"fmt"
	sdk "github.com/cosmos/cosmos-sdk/types"
	"github.com/pkg/errors"
	"github.com/tendermint/tendermint/libs/math"
)
const (
	accountIDTypeNil byte = iota
	accountIDTypeName
	accountIDTypeAccAddress
	accountIDTypeIdxLen
)
const (
	AccIDStoreKeyLen = sdk.AddrLen + 1
)
var _ sdk.Address = &AccountID{}
type AccountID struct {
	Value []byte `json:"value,omitempty" yaml:"value"`
}
type AccountIDes struct {
	Addresses []AccountID `json:"addresses"`
}
func NewAccountIDFromName(n Name) (res AccountID) {
	res.Value = make([]byte, len(n.Value))
	copy(res.Value, n.Value)
	return res
}
func NewAccountIDFromByte(bytes []byte) AccountID {
	return AccountID{
		Value: bytes,
	}
}
func NewAccountIDFromAccAdd(add sdk.AccAddress) AccountID {
	bs := make([]byte, 0, len(add)+1)
	bs = append(bs, accountIDTypeAccAddress)
	bs = append(bs, add...)
	return AccountID{bs}
}
func NewAccountIDFromAdd(add sdk.Address) AccountID {
	bs := make([]byte, 0, len(add.Bytes())+1)
	bs = append(bs, accountIDTypeAccAddress)
	bs = append(bs, add.Bytes()...)
	return AccountID{bs}
}
func NewAccountIDFromValAdd(add sdk.ValAddress) AccountID {
	return NewAccountIDFromAccAdd(sdk.AccAddress(add))
}
func NewAccountIDFromConsAdd(add sdk.ConsAddress) AccountID {
	return NewAccountIDFromAccAdd(sdk.AccAddress(add))
}
func EmptyAccountID() AccountID {
	return AccountID{
		Value: []byte{accountIDTypeNil}[:],
	}
}
func NewAccountIDFromStr(str string) (AccountID, error) {
	if str == "" {
		return EmptyAccountID(), nil
	}
	if len(str) <= NameStrLenMax {
		n, err := NewName(str)
		if err != nil {
			return AccountID{}, err
		}
		return NewAccountIDFromName(n), nil
	}
	accAdd, err := sdk.AccAddressFromBech32(str)
	if err != nil {
		return AccountID{}, err
	}
	return NewAccountIDFromAccAdd(accAdd), nil
}
func MustAccountID(str string) AccountID {
	res, err := NewAccountIDFromStr(str)
	if err != nil {
		panic(errors.Wrapf(err, "must accountID %s", str))
	}
	return res
}
func (a AccountID) Equals(o sdk.Address) bool {
	if a.Empty() && o.Empty() {
		return true
	}
	if acc, ok := o.(sdk.AccAddress); ok {
		acc2, ok := a.ToAccAddress()
		return ok && acc2.Equals(acc)
	}
	return bytes.Equal(a.Bytes(), o.Bytes())
}
func (a AccountID) Eq(o AccountID) bool {
	if a.Empty() && o.Empty() {
		return true
	}
	return bytes.Equal(a.Bytes(), o.Bytes())
}
func (a AccountID) Equal(o *AccountID) bool {
	if a.Empty() && o.Empty() {
		return true
	}
	return bytes.Equal(a.Bytes(), o.Bytes())
}
func (a AccountID) Empty() bool {
	if len(a.Value) == 0 {
		return true
	}
	if a.Value[0] == accountIDTypeNil {
		return true
	}
	if addr, ok := a.ToAddress(); ok {
		return addr.Empty()
	}
	if name, ok := a.ToName(); ok {
		return name.Empty()
	}
	return true
}
func (a AccountID) MarshalJSON() ([]byte, error) {
	if a.Empty() {
		return json.Marshal("")
	}
	if addr, ok := a.ToAddress(); ok {
		return addr.MarshalJSON()
	}
	if name, ok := a.ToName(); ok {
		return name.MarshalJSON()
	}
	return []byte{}, nil
}
func (a *AccountID) UnmarshalJSON(data []byte) error {
	var s string
	err := json.Unmarshal(data, &s)
	if err != nil {
		return err
	}
	if len(s) == 0 {
		*a = EmptyAccountID()
		return nil
	}
	if len(s) <= (NameStrLenMax + 2) {
		name, err := NewName(s)
		if err != nil {
			return err
		}
		*a = NewAccountIDFromName(name)
	} else {
		add := AccAddress{}
		if err := add.UnmarshalJSON(data); err != nil {
			return err
		}
		*a = NewAccountIDFromAccAdd(add)
	}
	return nil
}
func (a AccountID) MarshalYAML() (interface{}, error) {
	if a.Empty() {
		return "", nil
	}
	if addr, ok := a.ToAddress(); ok {
		return addr.String(), nil
	}
	if name, ok := a.ToName(); ok {
		return name.MarshalYAML()
	}
	return []byte{}, nil
}
func (a AccountID) Bytes() []byte {
	if a.Empty() {
		return []byte{}
	}
	if addr, ok := a.ToAddress(); ok {
		return addr.Bytes()
	}
	if name, ok := a.ToName(); ok {
		return name.Bytes()
	}
	return []byte{}
}
func (a AccountID) String() string {
	if a.Empty() {
		return ""
	}
	if addr, ok := a.ToAddress(); ok {
		return addr.String()
	}
	if name, ok := a.ToName(); ok {
		return name.String()
	}
	return ""
}
func (a AccountID) Marshal() ([]byte, error) {
	return a.Value, nil
}
func (a AccountID) Format(s fmt.State, verb rune) {
	if a.Empty() {
		s.Write([]byte{})
	}
	if addr, ok := a.ToAddress(); ok {
		addr.Format(s, verb)
	}
	if name, ok := a.ToName(); ok {
		name.Format(s, verb)
	}
}
func (a AccountID) ToAddress() (sdk.Address, bool) {
	if len(a.Value) == 0 {
		return nil, false
	}
	return a.ToAccAddress()
}
func (a AccountID) ToAccAddress() (sdk.AccAddress, bool) {
	if a.Value[0] == accountIDTypeAccAddress {
		cb := make([]byte, len(a.Value)-1)
		copy(cb, a.Value[1:])
		return cb, true
	}
	return nil, false
}