formatting

package
v1.0.4-update-id-2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: BSD-3-Clause Imports: 9 Imported by: 160

Documentation

Index

Constants

View Source
const (
	// HexEncoding specifies a hex plus 4 byte checksum encoding format
	HexEncoding = "hex"
	// CB58Encoding specifies the CB58 encoding format
	CB58Encoding = "cb58"
)

Variables

This section is empty.

Functions

func FormatAddress added in v0.8.0

func FormatAddress(
	chainIDAlias string,
	hrp string,
	addr []byte,
) (string, error)

FormatAddress takes in a chain prefix, HRP, and byte slice to produce a string for an address.

func FormatBech32 added in v0.8.0

func FormatBech32(hrp string, payload []byte) (string, error)

FormatBech32 takes an address's bytes as input and returns a bech32 address

func IntFormat

func IntFormat(maxValue int) string

IntFormat ...

func ParseAddress added in v0.8.0

func ParseAddress(addrStr string) (string, string, []byte, error)

ParseAddress takes in an address string and splits returns the corresponding parts. This returns the chain ID alias, bech32 HRP, address bytes, and an error if it occurs.

func ParseBech32 added in v0.8.0

func ParseBech32(addrStr string) (string, []byte, error)

ParseBech32 takes a bech32 address as input and returns the HRP and data section of a bech32 address

Types

type CB58

type CB58 struct{ Bytes []byte }

CB58 formats bytes in checksummed base-58 encoding

func (CB58) ConvertBytes added in v1.0.3

func (cb58 CB58) ConvertBytes(b []byte) string

ConvertBytes ...

func (CB58) ConvertString added in v1.0.3

func (cb58 CB58) ConvertString(str string) ([]byte, error)

ConvertString ...

func (*CB58) Encoding added in v1.0.3

func (cb58 *CB58) Encoding() string

Encoding ...

func (*CB58) FromString

func (cb58 *CB58) FromString(str string) error

FromString ...

func (CB58) MarshalJSON

func (cb58 CB58) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (CB58) String

func (cb58 CB58) String() string

String ...

func (*CB58) UnmarshalJSON

func (cb58 *CB58) UnmarshalJSON(b []byte) error

UnmarshalJSON ...

type CustomStringer

type CustomStringer struct{ Stringer func() string }

CustomStringer ...

func (CustomStringer) String

func (cs CustomStringer) String() string

type DumpBytes

type DumpBytes struct{ Bytes []byte }

DumpBytes ...

func (DumpBytes) String

func (db DumpBytes) String() string

type Encoding added in v1.0.3

type Encoding interface {
	ConvertBytes([]byte) string
	ConvertString(str string) ([]byte, error)
	Encoding() string
}

Encoding returns a struct used to format bytes for a specific encoding

type EncodingManager added in v1.0.3

type EncodingManager interface {
	GetEncoding(encoding string) (Encoding, error)
}

EncodingManager is an interface to provide an Encoding interface

func NewEncodingManager added in v1.0.3

func NewEncodingManager(defaultEnc string) (EncodingManager, error)

NewEncodingManager returns an EncodingManager with the provided default

type Hex added in v1.0.3

type Hex struct{ Bytes []byte }

Hex implements the Encoding interface Provides a hex format with 4 byte checksum

func (Hex) ConvertBytes added in v1.0.3

func (h Hex) ConvertBytes(b []byte) string

ConvertBytes ...

func (Hex) ConvertString added in v1.0.3

func (h Hex) ConvertString(str string) ([]byte, error)

ConvertString ...

func (*Hex) Encoding added in v1.0.3

func (h *Hex) Encoding() string

Encoding ...

func (*Hex) FromString added in v1.0.3

func (h *Hex) FromString(str string) error

FromString ...

func (Hex) MarshalJSON added in v1.0.3

func (h Hex) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (Hex) String added in v1.0.3

func (h Hex) String() string

String ...

func (*Hex) UnmarshalJSON added in v1.0.3

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

UnmarshalJSON ...

type PrefixedStringer

type PrefixedStringer interface {
	fmt.Stringer

	PrefixedString(prefix string) string
}

PrefixedStringer extends a stringer that adds a prefix

Jump to

Keyboard shortcuts

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