types

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BloomByteLength represents the number of bytes used in a header log bloom.
	BloomByteLength = 256

	// BloomBitLength represents the number of bits used in a header log bloom.
	BloomBitLength = 8 * BloomByteLength
)
View Source
const (
	AddressLength = 20
)
View Source
const (
	HashLength = 32
)

Variables

View Source
var (
	ErrEmptyString   = &decError{"empty hex string"}
	ErrSyntax        = &decError{"invalid hex string"}
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	ErrOddLength     = &decError{"hex string of odd length"}
	ErrEmptyNumber   = &decError{"hex string \"0x\""}
	ErrLeadingZero   = &decError{"hex number with leading zero digits"}
	ErrUint64Range   = &decError{"hex number > 64 bits"}
	ErrUintRange     = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	ErrBig256Range   = &decError{"hex number > 256 bits"}
)
View Source
var (
	ErrBytesTooLong = &decError{"bytes too long"}

	ErrRegisterFull    = &decError{"Can't register more type"}
	ErrRegisterFailure = &decError{"Register is failure"}
)

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

Copy bytes

Returns an exact copy of the provided bytes

func DecodeHex

func DecodeHex(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func DecodeHexBig

func DecodeHexBig(input string) (*big.Int, error)

DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.

func DecodeHexUint64

func DecodeHexUint64(input string) (uint64, error)

DecodeUint64 decodes a hex string with 0x prefix as a quantity.

func EncodeHex

func EncodeHex(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func EncodeHexBig

func EncodeHexBig(bigint *big.Int) string

EncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.

func EncodeHexUint64

func EncodeHexUint64(i uint64) string

EncodeUint64 encodes i as a hex string with 0x prefix.

func FromHex

func FromHex(s string) []byte

func HasHexPrefix

func HasHexPrefix(str string) bool

func Hex2Bytes

func Hex2Bytes(str string) []byte

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

func IsHex

func IsHex(str string) bool

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Bchain address or not.

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

func MustDecodeHex

func MustDecodeHex(input string) []byte

MustDecode decodes a hex string with 0x prefix. It panics for invalid input.

func MustDecodeHexBig

func MustDecodeHexBig(input string) *big.Int

MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func MustDecodeHexUint64

func MustDecodeHexUint64(input string) uint64

MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func RegisterExtension

func RegisterExtension(typ *int8, f func() msgp.Extension) error

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

func ToHex

func ToHex(b []byte) string

Types

type Address

type Address [AddressLength]byte

Address represents the 20 byte address of an bchain account.

func BigToAddress

func BigToAddress(b *big.Int) Address

func BytesToAddress

func BytesToAddress(b []byte) Address

func HexToAddress

func HexToAddress(s string) Address

func StringToAddress

func StringToAddress(s string) Address

func (Address) Big

func (a Address) Big() *big.Int

func (Address) Bytes

func (a Address) Bytes() []byte

func (*Address) DecodeMsg

func (z *Address) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Address) EncodeMsg

func (z *Address) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Address) ExtensionType

func (*Address) ExtensionType() int8

Here, we'll pick an arbitrary number between 0 and 127 that isn't already in use

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

for format print

func (Address) Hash

func (a Address) Hash() Hash

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) HexLower

func (a Address) HexLower() string

func (*Address) Len

func (*Address) Len() int

We'll always use 20 bytes to encode the data

func (*Address) MarshalBinaryTo

func (a *Address) MarshalBinaryTo(b []byte) error

MarshalBinaryTo simply copies the value of the bytes into 'b'

func (*Address) MarshalMsg

func (z *Address) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

for json marshal

func (*Address) Msgsize

func (z *Address) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

Sets the address to the value of b. If b is larger than len(a) it will panic

func (Address) Str

func (a Address) Str() string

Get the string representation of the underlying address

func (*Address) UnmarshalBinary

func (a *Address) UnmarshalBinary(b []byte) error

UnmarshalBinary copies the value of 'b' into the BYTE8 object. (We might want to add a sanity check here later that len(b) <= HashLength.)

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) error

for json unmarshal

func (*Address) UnmarshalMsg

func (z *Address) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type BigInt

type BigInt struct {
	IntVal big.Int `msg:"bigint"`
}

func NewBigInt

func NewBigInt(in big.Int) *BigInt

func (*BigInt) DecodeMsg

func (z *BigInt) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (BigInt) EncodeMsg

func (z BigInt) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*BigInt) ExtensionType

func (bigInt *BigInt) ExtensionType() int8

Here, we'll pick an arbitrary number between 0 and 127 that isn't already in use

func (BigInt) Get

func (bigInt BigInt) Get() big.Int

func (*BigInt) Len

func (bigInt *BigInt) Len() int

We'll always use 1 + len(big.int.x) bytes to encode the data

func (*BigInt) MarshalBinaryTo

func (bigInt *BigInt) MarshalBinaryTo(b []byte) error

func (BigInt) MarshalMsg

func (z BigInt) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (BigInt) MarshalText

func (b BigInt) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (BigInt) Msgsize

func (z BigInt) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*BigInt) Put

func (bigInt *BigInt) Put(in big.Int) *BigInt

func (*BigInt) String

func (b *BigInt) String() string

String returns the hex encoding of b.

func (*BigInt) ToInt

func (b *BigInt) ToInt() *big.Int

ToInt converts b to a big.Int.

func (*BigInt) UnmarshalBinary

func (bigInt *BigInt) UnmarshalBinary(b []byte) error

func (*BigInt) UnmarshalJSON

func (b *BigInt) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*BigInt) UnmarshalMsg

func (z *BigInt) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*BigInt) UnmarshalText

func (b *BigInt) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Bloom

type Bloom [BloomByteLength]byte

Bloom represents a 2048 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

func (*Bloom) DecodeMsg

func (z *Bloom) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Bloom) EncodeMsg

func (z *Bloom) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Bloom) ExtensionType

func (bloom *Bloom) ExtensionType() int8

Here, we'll pick an arbitrary number between 0 and 127 that isn't already in use

func (*Bloom) Len

func (bloom *Bloom) Len() int

We'll always use 256 bytes to encode the data

func (*Bloom) MarshalBinaryTo

func (bloom *Bloom) MarshalBinaryTo(b []byte) error

func (*Bloom) MarshalMsg

func (z *Bloom) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) Msgsize

func (z *Bloom) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (*Bloom) UnmarshalBinary

func (bloom *Bloom) UnmarshalBinary(b []byte) error

func (*Bloom) UnmarshalMsg

func (z *Bloom) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

type BytesForJson

type BytesForJson []byte

Bytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".

func (BytesForJson) MarshalText

func (b BytesForJson) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (BytesForJson) String

func (b BytesForJson) String() string

String returns the hex encoding of b.

func (*BytesForJson) UnmarshalJSON

func (b *BytesForJson) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*BytesForJson) UnmarshalText

func (b *BytesForJson) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data. It's a hex string/num

func BigToHash

func BigToHash(b *big.Int) Hash

func BytesToHash

func BytesToHash(b []byte) Hash

func HexToHash

func HexToHash(s string) Hash

func StringToHash

func StringToHash(s string) Hash

func (Hash) Big

func (h Hash) Big() *big.Int

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (*Hash) DecodeMsg

func (z *Hash) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Hash) EncodeMsg

func (z *Hash) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Hash) Equal

func (h *Hash) Equal(in *Hash) bool

func (*Hash) ExtensionType

func (*Hash) ExtensionType() int8

Here, we'll pick an arbitrary number between 0 and 127 that isn't already in use

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

for format print

func (Hash) Hex

func (h Hash) Hex() string

func (*Hash) Len

func (*Hash) Len() int

We'll always use 32 bytes to encode the data

func (*Hash) MarshalBinaryTo

func (h *Hash) MarshalBinaryTo(b []byte) error

MarshalBinaryTo simply copies the value of the bytes into 'b'

func (*Hash) MarshalMsg

func (z *Hash) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

for json marshal

func (*Hash) Msgsize

func (z *Hash) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

Sets the hash to the value of b. If b is larger than len(h), 'b' will be cropped (from the left).

func (Hash) Str

func (h Hash) Str() string

Get the string representation of the underlying hash

func (Hash) String

func (h Hash) String() string

func (Hash) TerminalString

func (h Hash) TerminalString() string

func (*Hash) UnmarshalBinary

func (h *Hash) UnmarshalBinary(b []byte) error

UnmarshalBinary copies the value of 'b' into the Hash object. (We might want to add a sanity check here later that len(b) <= HashLength.)

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(b []byte) error

for json unmarshal

func (*Hash) UnmarshalMsg

func (z *Hash) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(b []byte) error

for json unmarshal

type Hashs

type Hashs struct {
	Hashs []*Hash
}

func (*Hashs) DecodeMsg

func (z *Hashs) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Hashs) EncodeMsg

func (z *Hashs) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Hashs) MarshalMsg

func (z *Hashs) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Hashs) Msgsize

func (z *Hashs) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Hashs) UnmarshalMsg

func (z *Hashs) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type IP

type IP struct {
	Ip net.IP `msg:"ip"`
}

func NewIP

func NewIP(in net.IP) *IP

func (*IP) DecodeMsg

func (z *IP) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*IP) EncodeMsg

func (z *IP) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*IP) ExtensionType

func (*IP) ExtensionType() int8

Here, we'll pick an arbitrary number between 0 and 127 that isn't already in use

func (IP) Get

func (ip IP) Get() net.IP

func (*IP) Len

func (ip *IP) Len() int

We'll always use 16 bytes to encode the data

func (*IP) MarshalBinaryTo

func (ip *IP) MarshalBinaryTo(b []byte) error

MarshalBinaryTo simply copies the value of the bytes into 'b'

func (*IP) MarshalMsg

func (z *IP) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*IP) Msgsize

func (z *IP) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*IP) Put

func (ip *IP) Put(in net.IP) *IP

func (*IP) UnmarshalBinary

func (ip *IP) UnmarshalBinary(b []byte) error

UnmarshalBinary copies the value of 'b' into the Hash object. (We might want to add a sanity check here later that len(b) <= HashLength.)

func (*IP) UnmarshalMsg

func (z *IP) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Uint64ForJson

type Uint64ForJson uint64

Uint64 marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (Uint64ForJson) MarshalText

func (b Uint64ForJson) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint64ForJson) String

func (b Uint64ForJson) String() string

String returns the hex encoding of b.

func (*Uint64ForJson) UnmarshalJSON

func (b *Uint64ForJson) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint64ForJson) UnmarshalText

func (b *Uint64ForJson) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type UintForJson

type UintForJson uint

Uint marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (UintForJson) MarshalText

func (b UintForJson) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (UintForJson) String

func (b UintForJson) String() string

String returns the hex encoding of b.

func (*UintForJson) UnmarshalJSON

func (b *UintForJson) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*UintForJson) UnmarshalText

func (b *UintForJson) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL