func BFromHex(str string) (B, error) {
	if strings.HasPrefix(str, "0x") {
		str = str[2:]
	}
	h, err := hex.DecodeString(str)
	if err != nil {
		return B([]byte{}), err
	}
	return B(h), nil
}
BFromHex returns a B Value decoded from a hex encoded string. The "0x"
prefix is optional.
package v0
import (
	"bytes"
	"encoding"
	"encoding/base64"
	"encoding/binary"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"math/big"
	"sort"
	"strings"
	"github.com/ethereum/go-ethereum/common/math"
)
type Type string
const (
	TypeAddress = "address"
	TypeStr     = "str"
	TypeB32     = "b32"
	TypeB       = "b"
	TypeI8      = "i8"
	TypeI16     = "i16"
	TypeI32     = "i32"
	TypeI64     = "i64"
	TypeI128    = "i128"
	TypeI256    = "i256"
	TypeU8      = "u8"
	TypeU16     = "u16"
	TypeU32     = "u32"
	TypeU64     = "u64"
	TypeU128    = "u128"
	TypeU256    = "u256"
	TypeRecord  = "record"
	TypeList    = "list"
)
type Value interface {
	encoding.BinaryMarshaler
	Type() Type
	Equal(Value) bool
}
type Address string
func (Address) Type() Type {
	return TypeAddress
}
func (address Address) Equal(other Value) bool {
	if other.Type() != TypeAddress {
		return false
	}
	return address == other.(Address)
}
func (address *Address) UnmarshalJSON(data []byte) error {
	var v string
	err := json.Unmarshal(data, &v)
	*address = Address(v)
	return err
}
func (address Address) MarshalBinary() ([]byte, error) {
	buf := new(bytes.Buffer)
	addressBytes := []byte(address)
	if err := binary.Write(buf, binary.LittleEndian, uint64(len(addressBytes))); err != nil {
		return buf.Bytes(), fmt.Errorf("cannot write address len: %v", err)
	}
	if err := binary.Write(buf, binary.LittleEndian, addressBytes); err != nil {
		return buf.Bytes(), fmt.Errorf("cannot write address data: %v", err)
	}
	return buf.Bytes(), nil
}
func (address *Address) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)
	var numBytes uint64
	if err := binary.Read(buf, binary.LittleEndian, &numBytes); err != nil {
		return fmt.Errorf("cannot read address len: %v", err)
	}
	if numBytes > 10*1024 {
		return fmt.Errorf("cannot read address: too many bytes")
	}
	addressBytes := make([]byte, numBytes)
	if _, err := buf.Read(addressBytes); err != nil {
		return fmt.Errorf("cannot read address data: %v", err)
	}
	*address = Address(addressBytes)
	return nil
}
type Str string
func (Str) Type() Type {
	return TypeStr
}
func (str Str) Equal(other Value) bool {
	if other.Type() != TypeStr {
		return false
	}
	return str == other.(Str)
}
func (str *Str) UnmarshalJSON(data []byte) error {
	var v string
	err := json.Unmarshal(data, &v)
	*str = Str(v)
	return err
}
func (str Str) MarshalBinary() ([]byte, error) {
	buf := new(bytes.Buffer)
	strBytes := []byte(str)
	if err := binary.Write(buf, binary.LittleEndian, uint64(len(strBytes))); err != nil {
		return buf.Bytes(), fmt.Errorf("cannot write str len: %v", err)
	}
	if err := binary.Write(buf, binary.LittleEndian, strBytes); err != nil {
		return buf.Bytes(), fmt.Errorf("cannot write str data: %v", err)
	}
	return buf.Bytes(), nil
}
func (str *Str) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)
	var numBytes uint64
	if err := binary.Read(buf, binary.LittleEndian, &numBytes); err != nil {
		return fmt.Errorf("cannot read str len: %v", err)
	}
	if numBytes > 10*1024 {
		return fmt.Errorf("cannot read str: too many bytes")
	}
	strBytes := make([]byte, numBytes)
	if _, err := buf.Read(strBytes); err != nil {
		return fmt.Errorf("cannot read str data: %v", err)
	}
	*str = Str(strBytes)
	return nil
}
type B32 [32]byte
func B32FromHex(str string) (B32, error) {
	if strings.HasPrefix(str, "0x") {
		str = str[2:]
	}
	h, err := hex.DecodeString(str)
	if err != nil {
		return B32([32]byte{}), err
	}
	if len(h) != 32 {
		return B32([32]byte{}), fmt.Errorf("expected %v bytes, got %v byte", 32, len(h))
	}
	b32 := [32]byte{}
	copy(b32[:], h)
	return B32(b32), nil
}
func (B32) Type() Type {
	return TypeB32
}
func (b32 B32) Equal(other Value) bool {
	if other.Type() != TypeB32 {
		return false
	}
	val := other.(B32)
	return bytes.Equal(b32[:], val[:])
}
func (b32 B32) MarshalJSON() ([]byte, error) {
	return json.Marshal(b32[:])
}
func (b32 *B32) UnmarshalJSON(data []byte) error {
	v := []byte{}
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	copy(b32[:], v)
	return nil
}
func (b32 B32) MarshalBinary() ([]byte, error) {
	buf := new(bytes.Buffer)
	if err := binary.Write(buf, binary.LittleEndian, b32); err != nil {
		return buf.Bytes(), fmt.Errorf("cannot write b32 data: %v", err)
	}
	return buf.Bytes(), nil
}
func (b32 *B32) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)
	if err := binary.Read(buf, binary.LittleEndian, b32); err != nil {
		return fmt.Errorf("cannot read b32 data: %v", err)
	}
	return nil
}
func (b32 B32) String() string {
	return base64.StdEncoding.EncodeToString(b32[:])
}
type B []byte