Documentation ¶
Index ¶
- Constants
- Variables
- func FormatAddressStrToHex(address string) string
- type Address
- func MustNew(base32OrHex string, networkID ...uint32) Address
- func MustNewFromBase32(base32Str string) (address Address)
- func MustNewFromBytes(hexAddress []byte, networkID ...uint32) (address Address)
- func MustNewFromCommon(commonAddress common.Address, networkID ...uint32) (address Address)
- func MustNewFromHex(hexAddressStr string, networkID ...uint32) (val Address)
- func New(base32OrHex string, networkID ...uint32) (Address, error)
- func NewFromBase32(base32Str string) (cfxAddress Address, err error)
- func NewFromBytes(hexAddress []byte, networkID ...uint32) (val Address, err error)
- func NewFromCommon(commonAddress common.Address, networkID ...uint32) (val Address, err error)
- func NewFromHex(hexAddressStr string, networkID ...uint32) (val Address, err error)
- func (a *Address) CompleteByClient(client networkIDGetter) error
- func (a *Address) CompleteByNetworkID(networkID uint32) error
- func (a *Address) DecodeRLP(r *rlp.Stream) error
- func (a Address) EncodeRLP(w io.Writer) error
- func (a *Address) Equals(target *Address) bool
- func (a *Address) GetAddressType() AddressType
- func (a *Address) GetBody() Body
- func (a *Address) GetChecksum() Checksum
- func (a *Address) GetHexAddress() string
- func (a *Address) GetNetworkID() uint32
- func (a *Address) GetNetworkType() NetworkType
- func (a *Address) IsValid() bool
- func (a Address) MarshalText() ([]byte, error)
- func (a *Address) MustGetBase32Address() string
- func (a *Address) MustGetCommonAddress() common.Address
- func (a *Address) MustGetVerboseBase32Address() string
- func (a Address) String() string
- func (a *Address) ToCommon() (address common.Address, networkID uint32, err error)
- func (a *Address) ToHex() (hexAddressStr string, networkID uint32)
- func (a *Address) UnmarshalJSON(data []byte) error
- func (a *Address) UnmarshalText(data []byte) error
- type AddressType
- type Body
- type Checksum
- type NetworkType
- type VersionByte
Constants ¶
const ( NetworkTypeMainnetPrefix NetworkType = "cfx" NetworkTypeTestNetPrefix NetworkType = "cfxtest" NetowrkTypeMainnetID uint32 = 1029 NetworkTypeTestnetID uint32 = 1 )
Variables ¶
var (
ErrorBodyLen = errors.New("Body length must be 34")
)
Functions ¶
func FormatAddressStrToHex ¶
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 ¶
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 ¶
MustNewFromBase32 creates address by base32 string and panic if error
func MustNewFromBytes ¶
MustNewFromBytes creates an address from hexAddress byte slice with networkID and panic if error
func MustNewFromCommon ¶
MustNewFromCommon creates an address from common.Address with networkID and panic if error
func MustNewFromHex ¶
MustNewFromHex creates address by hex address string with networkID and panic if error
func New ¶
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 ¶
NewFromBase32 creates address by base32 string
func NewFromBytes ¶
NewFromBytes creates an address from hexAddress byte slice with networkID
func NewFromCommon ¶
NewFromCommon creates an address from common.Address with networkID
func NewFromHex ¶
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 ¶
CompleteByClient will set networkID by client.GetNetworkID() if a.networkID not be 0
func (*Address) CompleteByNetworkID ¶
CompleteByNetworkID will set networkID if current networkID isn't 0
func (*Address) GetAddressType ¶
func (a *Address) GetAddressType() AddressType
GetAddressType returuns address type
func (*Address) GetHexAddress ¶
GetHexAddress returns hex format address and panic if error
func (*Address) GetNetworkID ¶
GetNetworkID returns networkID and panic if error
func (*Address) GetNetworkType ¶
func (a *Address) GetNetworkType() NetworkType
GetNetworkType returns network type
func (Address) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Address) MustGetBase32Address ¶
MustGetBase32Address returns base32 string of address which doesn't include address type
func (*Address) MustGetCommonAddress ¶
MustGetCommonAddress returns common address and panic if error
func (*Address) MustGetVerboseBase32Address ¶
MustGetVerboseBase32Address returns base32 string of address with address type
func (*Address) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Address) UnmarshalText ¶
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 ¶
NewBodyByString creates body by base32 string which contains version byte and hex address
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
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