address

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 5 Imported by: 4

README

address

Utilities related to Spacemesh account addresses.

Documentation

Index

Constants

View Source
const (
	// AddressLength is the expected length of the address.
	AddressLength = 24
	// AddressReservedSpace define how much bytes from top is reserved in address for future.
	AddressReservedSpace = 4
)

Variables

View Source
var (
	// ErrWrongAddressLength is returned when the length of the address is not correct.
	ErrWrongAddressLength = errors.New("wrong address length")
	// ErrUnsupportedNetwork is returned when a network is not supported.
	ErrUnsupportedNetwork = errors.New("unsupported network")
	// ErrDecodeBech32 is returned when an error occurs during decoding bech32.
	ErrDecodeBech32 = errors.New("error decode to bech32")
	// ErrMissingReservedSpace is returned if top bytes of address is not 0.
	ErrMissingReservedSpace = errors.New("missing reserved space")
)

Functions

This section is empty.

Types

type Address

type Address [AddressLength]byte

Address represents the address of a spacemesh account with AddressLength length.

func GenerateAddress

func GenerateAddress(publicKey []byte) Address

GenerateAddress generates an address from a public key.

func StringToAddress

func StringToAddress(src string) (Address, error)

StringToAddress returns a new Address from a given string like `sm1abc...`.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (*Address) DecodeScale

func (a *Address) DecodeScale(d *scale.Decoder) (int, error)

DecodeScale implements scale codec interface.

func (*Address) EncodeScale

func (a *Address) EncodeScale(e *scale.Encoder) (int, error)

EncodeScale implements scale codec interface.

func (Address) Field

func (a Address) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (Address) Format

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

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Address) GetHRPNetwork

func (a Address) GetHRPNetwork() string

GetHRPNetwork returns the Human-Readable-Part of bech32 addresses for a networkID.

func (Address) IsEmpty

func (a Address) IsEmpty() bool

IsEmpty checks if address is empty.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

type Config

type Config struct {
	NetworkHRP string `mapstructure:"network-hrp"`
}

Config is the configuration of the address package.

func DefaultAddressConfig

func DefaultAddressConfig() *Config

DefaultAddressConfig returns the default configuration of the address package.

func DefaultTestAddressConfig

func DefaultTestAddressConfig() *Config

DefaultTestAddressConfig returns the default test configuration of the address package.

func SetAddressConfig

func SetAddressConfig(networkHRP string) *Config

SetAddressConfig set hrp prefix for pkg configuration.

Jump to

Keyboard shortcuts

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