cfxaddress

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: LGPL-3.0 Imports: 13 Imported by: 60

Documentation

Index

Constants

View Source
const (
	NetworkTypeMainnetPrefix NetworkType = "cfx"
	NetworkTypeTestNetPrefix NetworkType = "cfxtest"

	NetowrkTypeMainnetID uint32 = 1029
	NetworkTypeTestnetID uint32 = 1
)

Variables

View Source
var (
	ErrorBodyLen = errors.New("Body length must be 34")
)

Functions

func FormatAddressStrToHex

func FormatAddressStrToHex(address string) string

FormatAddressStrToHex format hex or base32 address to hex string

Types

type Address

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

Address represents base32 address accroding to CIP37 Use NewXXX or MustNewXXX to create an Address object and don't use Address{} which is an invalid address.

func MustNew

func MustNew(base32OrHex string, networkID ...uint32) Address

MustNew create conflux address by base32 string or hex40 string, if base32OrHex is base32 and networkID is setted it will check if networkID match, it will painc if error occured.

func MustNewFromBase32

func MustNewFromBase32(base32Str string) (address Address)

MustNewFromBase32 creates address by base32 string and panic if error

func MustNewFromBytes

func MustNewFromBytes(hexAddress []byte, networkID ...uint32) (address Address)

MustNewFromBytes creates an address from hexAddress byte slice with networkID and panic if error

func MustNewFromCommon

func MustNewFromCommon(commonAddress common.Address, networkID ...uint32) (address Address)

MustNewFromCommon creates an address from common.Address with networkID and panic if error

func MustNewFromHex

func MustNewFromHex(hexAddressStr string, networkID ...uint32) (val Address)

MustNewFromHex creates address by hex address string with networkID and panic if error

func New

func New(base32OrHex string, networkID ...uint32) (Address, error)

New create conflux address by base32 string or hex40 string, if base32OrHex is base32 and networkID is passed it will create cfx Address use networkID.

func NewFromBase32

func NewFromBase32(base32Str string) (cfxAddress Address, err error)

NewFromBase32 creates address by base32 string

func NewFromBytes

func NewFromBytes(hexAddress []byte, networkID ...uint32) (val Address, err error)

NewFromBytes creates an address from hexAddress byte slice with networkID

func NewFromCommon

func NewFromCommon(commonAddress common.Address, networkID ...uint32) (val Address, err error)

NewFromCommon creates an address from common.Address with networkID

func NewFromHex

func NewFromHex(hexAddressStr string, networkID ...uint32) (val Address, err error)

NewFromHex creates address by hex address string with networkID If not pass networkID, it will be auto completed when it could be obtained form context.

func (*Address) CompleteByClient

func (a *Address) CompleteByClient(client networkIDGetter) error

CompleteByClient will set networkID by client.GetNetworkID() if a.networkID not be 0

func (*Address) CompleteByNetworkID

func (a *Address) CompleteByNetworkID(networkID uint32) error

CompleteByNetworkID will set networkID if current networkID isn't 0

func (*Address) DecodeRLP

func (a *Address) DecodeRLP(r *rlp.Stream) error

DecodeRLP implements the rlp.Decoder interface.

func (Address) EncodeRLP

func (a Address) EncodeRLP(w io.Writer) error

EncodeRLP implements the rlp.Encoder interface.

func (*Address) Equals

func (a *Address) Equals(target *Address) bool

Equals reports whether a and target are equal

func (*Address) GetAddressType

func (a *Address) GetAddressType() AddressType

GetAddressType returuns address type

func (*Address) GetBody

func (a *Address) GetBody() Body

GetBody returns body

func (*Address) GetChecksum

func (a *Address) GetChecksum() Checksum

GetChecksum returns checksum

func (*Address) GetHexAddress

func (a *Address) GetHexAddress() string

GetHexAddress returns hex format address and panic if error

func (*Address) GetNetworkID

func (a *Address) GetNetworkID() uint32

GetNetworkID returns networkID and panic if error

func (*Address) GetNetworkType

func (a *Address) GetNetworkType() NetworkType

GetNetworkType returns network type

func (*Address) IsValid

func (a *Address) IsValid() bool

IsValid return true if address is valid

func (Address) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*Address) MustGetBase32Address

func (a *Address) MustGetBase32Address() string

MustGetBase32Address returns base32 string of address which doesn't include address type

func (*Address) MustGetCommonAddress

func (a *Address) MustGetCommonAddress() common.Address

MustGetCommonAddress returns common address and panic if error

func (*Address) MustGetVerboseBase32Address

func (a *Address) MustGetVerboseBase32Address() string

MustGetVerboseBase32Address returns base32 string of address with address type

func (Address) String

func (a Address) String() string

String returns verbose base32 string of address

func (*Address) ToCommon

func (a *Address) ToCommon() (address common.Address, networkID uint32, err error)

ToCommon returns common.Address and networkID

func (*Address) ToHex

func (a *Address) ToHex() (hexAddressStr string, networkID uint32)

ToHex returns hex address and networkID

func (*Address) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Address) UnmarshalText

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

type AddressType

type AddressType string
const (
	AddressTypeBuiltin  AddressType = "builtin"
	AddressTypeUser     AddressType = "user"
	AddressTypeContract AddressType = "contract"
	AddressTypeNull     AddressType = "null"
	AddressTypeUnknown  AddressType = "unknown"
)

func CalcAddressType

func CalcAddressType(hexAddress []byte) (AddressType, error)

CalcAddressType calculate address type of hexAddress

func (AddressType) String

func (a AddressType) String() string

func (AddressType) ToByte

func (a AddressType) ToByte() (byte, error)

ToByte returns byte represents of address type according to CIP-37

type Body

type Body [34]byte

Body reperents 5bits byte array of concating version byte with hex address

func NewBodyByHexAddress

func NewBodyByHexAddress(vrsByte VersionByte, hexAddress []byte) (b Body, err error)

NewBodyByHexAddress convert concat of version type and hex address to 5 bits slice

func NewBodyByString

func NewBodyByString(base32Str string) (body Body, err error)

NewBodyByString creates body by base32 string which contains version byte and hex address

func (Body) String

func (b Body) String() string

String return base32 string

func (Body) ToHexAddress

func (b Body) ToHexAddress() (vrsType VersionByte, hexAddress []byte, err error)

ToHexAddress decode bits5 array to version byte and hex address

type Checksum

type Checksum [8]byte

Checksum represents by 5bits byte array

func CalcChecksum

func CalcChecksum(nt NetworkType, body Body) (c Checksum, err error)

CalcChecksum calculates checksum by network type and body

func (Checksum) String

func (c Checksum) String() string

String returns base32 string of checksum according to CIP-37

type NetworkType

type NetworkType string

NetworkType reprents network type mapped with network-id

func NewNetowrkType

func NewNetowrkType(netType string) (NetworkType, error)

NewNetowrkType creates network type by string

func NewNetworkTypeByID

func NewNetworkTypeByID(networkID uint32) NetworkType

NewNetworkTypeByID creates network type by network ID

func (NetworkType) String

func (n NetworkType) String() string

func (NetworkType) ToNetworkID

func (n NetworkType) ToNetworkID() (uint32, error)

ToNetworkID returns network ID

type VersionByte

type VersionByte struct {
	TypeBits uint8
	// current is constant 0, it's different with AddressType defined in address_type.go
	AddressType uint8
	SizeBits    uint8
}

VersionByte conmposites by type bits, address type and size bits according above description from CIP-37

func CalcVersionByte

func CalcVersionByte(hexAddress []byte) (versionByte VersionByte, err error)

CalcVersionByte calculates version byte of hex address

func NewVersionByte

func NewVersionByte(b byte) (vt VersionByte)

NewVersionByte creates version byte by byte

func (VersionByte) ToByte

func (v VersionByte) ToByte() (byte, error)

ToByte returns byte

Jump to

Keyboard shortcuts

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