address

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MainnetPrefix is the prefix added to the human readable address of mainnet
	MainnetPrefix = "io"
	// TestnetPrefix is the prefix added to the human readable address of testnet
	TestnetPrefix = "it"
)

Variables

View Source
var ErrInvalidAddr = errors.New("Invalid address")

ErrInvalidAddr indicates the invalid address error

View Source
var V1 = v1{
	AddressLength: 25,
	Version:       1,
}

V1 is a singleton and defines V1 address metadata

Functions

This section is empty.

Types

type AddrV1

type AddrV1 struct {
	// contains filtered or unexported fields
}

AddrV1 is V1 address format to be used on IoTeX blockchain and subchains. It is composed of parts in the following order: 1. uint32: chain ID 2. 20 bytes: hash derived from the the public key

func (*AddrV1) Bech32

func (addr *AddrV1) Bech32() string

Bech32 encodes an address struct into a a Bech32 encoded address string The encoded address string will start with "io" for mainnet, and with "it" for testnet

func (*AddrV1) Bytes

func (addr *AddrV1) Bytes() []byte

Bytes converts an address struct into a byte array

func (*AddrV1) ChainID

func (addr *AddrV1) ChainID() uint32

ChainID returns the chain ID

func (*AddrV1) IotxAddress

func (addr *AddrV1) IotxAddress() string

IotxAddress converts an address struct into an old address string This method is used for backward compatibility

func (*AddrV1) Payload

func (addr *AddrV1) Payload() []byte

Payload returns the payload, which is the public key hash

func (*AddrV1) PublicKeyHash

func (addr *AddrV1) PublicKeyHash() hash.PKHash

PublicKeyHash returns the public key hash

func (*AddrV1) Version

func (addr *AddrV1) Version() uint8

Version returns the address version

type Address

type Address interface {
	// ChainID returns the version
	ChainID() uint32
	// Version returns the version
	Version() uint8
	// Payload returns the payload
	Payload() []byte
	// Bech32 encodes the whole address into an address string encoded in Bech32 format
	Bech32() string
	// Bytes serializes the whole address struct into a byte slice, which is composed of the following parts in order:
	// 1. uint32: chain ID
	// 2. uint8: version of address
	// 3. byte slice: the payload to identify an address within one blockchain
	Bytes() []byte
	// IotxAddress converts an address struct into an old address string
	// This method is used for backward compatibility
	IotxAddress() string
}

Address defines the interface of the blockchain address

func Bech32ToAddress

func Bech32ToAddress(encodedAddr string) (Address, error)

Bech32ToAddress decodes an encoded address string into an address struct

func BytesToAddress

func BytesToAddress(bytes []byte) (Address, error)

BytesToAddress converts a byte array into an address struct

func IotxAddressToAddress

func IotxAddressToAddress(iotxRawAddr string) (Address, error)

IotxAddressToAddress converts an old address string into an address struct This method is used for backward compatibility

func New

func New(chainID uint32, payload []byte) Address

New constructs an address instance

Directories

Path Synopsis
Package bech32 includes a Bech32 string which is at most 90 characters long and consists of: The human-readable part, which is intended to convey the type of data, or anything else that is relevant to the reader.
Package bech32 includes a Bech32 string which is at most 90 characters long and consists of: The human-readable part, which is intended to convey the type of data, or anything else that is relevant to the reader.

Jump to

Keyboard shortcuts

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