types

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: Apache-2.0 Imports: 13 Imported by: 42

Documentation

Overview

Package types

@author: xwc1125

Package types

@author: xwc1125

Package types

@author: xwc1125

Package types

@author: xwc1125

Package types

@author: xwc1125

Package types

@author: xwc1125

Package types

@author: xwc1125

Index

Constants

View Source
const AddressLength = 20
View Source
const HashLength = 32

HashLength hash长度

View Source
const TxTypeUnknown = "UNKNOWN"

Variables

View Source
var (
	EmptyHash     = Hash{}
	EmptyCode     = sha3.Keccak256(nil)
	EmptyCodeHash = BytesToHash(EmptyCode)
	EmptyRootHash = HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)
View Source
var (
	EmptyAddress = Address{}
)
View Source
var (
	EmptyDomainAddress = DomainAddress{
		Addr: EmptyAddress,
	}
)

Functions

func IsEmptyHash

func IsEmptyHash(h Hash) bool

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded SuperChain address or not.

Types

type Addr

type Addr interface {
	Len() int                          // 地址长度
	Bytes() []byte                     // 地址bytes
	FromBytes(b []byte) (Addr, error)  // 将bytes转换为address对象
	String() string                    // 地址转换为string [implements fmt.Stringer]
	FromStr(addr string) (Addr, error) // 将字符串转换为address对象

	Validate(addr string) bool // 验证地址正确性
	Nil() bool                 // 判断地址是否为空
	Hash() Hash                // 地址的hash

	Format(s fmt.State, c rune) // 地址格式化
}

type Address

type Address [AddressLength]byte

Address represents the 20 byte address of an account.

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func DomainToAddress

func DomainToAddress(s string) Address

DomainToAddress domainAddr转Address。addr格式:xxx@chain5j.com或0xxxxxxxx

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func StringToAddress

func StringToAddress(s string) Address

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

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) FromBytes

func (a Address) FromBytes(b []byte) (Addr, error)

func (Address) FromStr

func (a Address) FromStr(addr string) (Addr, error)

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) Len

func (a Address) Len() int

func (Address) MarshalText

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

MarshalText returns the hex representation of a.

func (Address) Nil

func (a Address) Nil() bool

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (Address) TerminalString

func (a Address) TerminalString() string

TerminalString String implements fmt.Stringer.

func (*Address) UnmarshalJSON

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

UnmarshalJSON parses a hash in hex syntax.

func (*Address) UnmarshalText

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

UnmarshalText parses a hash in hex syntax.

func (Address) Validate

func (a Address) Validate(addr string) bool

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements valuer for database/sql.

type CallMsg

type CallMsg struct {
	From     Address  // the sender of the 'transaction'
	To       *Address // the destination contract (nil for contract creation)
	Gas      uint64   // if 0, the call executes with near-infinite gas
	GasPrice *big.Int // wei <-> gas exchange ratio
	Value    *big.Int // amount of wei sent along with the call
	Data     []byte   // input data, usually an ABI-encoded contract method invocation
}

CallMsg contains parameters for contract calls.

type DomainAddress

type DomainAddress struct {
	Addr       Address `json:"addr"`       // address
	DomainAddr string  `json:"domainAddr"` // domainAddr
}

func FromDomainAddress

func FromDomainAddress(addr string) DomainAddress

FromDomainAddress domainAddress 转换为DomainAddress对象。addr格式:xxx@chain5j.com:0xxxxxxxx

func NewDomainAddress

func NewDomainAddress(domain string, addr Address) DomainAddress

func (DomainAddress) Big

func (a DomainAddress) Big() *big.Int

func (DomainAddress) Bytes

func (a DomainAddress) Bytes() []byte

func (*DomainAddress) DecodeRLP

func (a *DomainAddress) DecodeRLP(s *rlp.Stream) error

func (*DomainAddress) EncodeRLP

func (a *DomainAddress) EncodeRLP(w io.Writer) error

func (DomainAddress) Format

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

func (DomainAddress) FromBytes

func (a DomainAddress) FromBytes(b []byte) (Addr, error)

func (DomainAddress) FromStr

func (a DomainAddress) FromStr(addr string) (Addr, error)

func (DomainAddress) Hash

func (a DomainAddress) Hash() Hash

func (DomainAddress) Len

func (a DomainAddress) Len() int

func (DomainAddress) Nil

func (a DomainAddress) Nil() bool

func (DomainAddress) String

func (a DomainAddress) String() string

func (*DomainAddress) UnmarshalJSON

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

func (DomainAddress) Validate

func (a DomainAddress) Validate(addr string) bool

func (DomainAddress) Value

func (a DomainAddress) Value() (driver.Value, error)

type Hash

type Hash [HashLength]byte

func BigToHash

func BigToHash(b *big.Int) Hash

func BytesToHash

func BytesToHash(b []byte) Hash

func HexToHash

func HexToHash(s string) Hash

func StringToHash

func StringToHash(s string) Hash

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

func (h Hash) 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 (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) HexNoPrefix

func (h Hash) HexNoPrefix() string

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (Hash) Nil

func (h Hash) Nil() bool

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements valuer for database/sql.

type MixedcaseAddress

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

MixedcaseAddress retains the original string, which may or may not be correctly checksummed

func NewMixedcaseAddress

func NewMixedcaseAddress(addr Address) MixedcaseAddress

NewMixedcaseAddress constructor (mainly for testing)

func NewMixedcaseAddressFromString

func NewMixedcaseAddressFromString(hexaddr string) (*MixedcaseAddress, error)

NewMixedcaseAddressFromString is mainly meant for unit-testing

func (*MixedcaseAddress) Address

func (ma *MixedcaseAddress) Address() Address

Address returns the address

func (*MixedcaseAddress) MarshalJSON

func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)

MarshalJSON marshals the original value

func (*MixedcaseAddress) Original

func (ma *MixedcaseAddress) Original() string

Original returns the mixed-case input string

func (*MixedcaseAddress) String

func (ma *MixedcaseAddress) String() string

String implements fmt.Stringer

func (*MixedcaseAddress) UnmarshalJSON

func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error

UnmarshalJSON parses MixedcaseAddress

func (*MixedcaseAddress) ValidChecksum

func (ma *MixedcaseAddress) ValidChecksum() bool

ValidChecksum returns true if the address has valid checksum

type StorageSize

type StorageSize float64

StorageSize is a wrapper around a float value that supports user friendly formatting.

func (StorageSize) String

func (s StorageSize) String() string

String implements the stringer interface.

func (StorageSize) TerminalString

func (s StorageSize) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type TxType

type TxType string

TxType the transaction type

func (*TxType) Value

func (txType *TxType) Value() string

Value value of txType

func (*TxType) ValueOf

func (txType *TxType) ValueOf(v string) TxType

ValueOf string to txType

type TxTypes

type TxTypes []TxType

TxTypes the array of txType

func (TxTypes) Len

func (types TxTypes) Len() int

Len len

func (TxTypes) Less

func (types TxTypes) Less(i, j int) bool

Less less

func (TxTypes) Swap

func (types TxTypes) Swap(i, j int)

Swap swap

type UnprefixedAddress

type UnprefixedAddress Address

UnprefixedAddress allows marshaling an Address without 0x prefix.

func (UnprefixedAddress) MarshalText

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

MarshalText encodes the address as hex.

func (*UnprefixedAddress) UnmarshalText

func (a *UnprefixedAddress) UnmarshalText(input []byte) error

UnmarshalText decodes the address from hex. The 0x prefix is optional.

type UnprefixedHash

type UnprefixedHash Hash

UnprefixedHash allows marshaling a Hash without 0x prefix.

func (UnprefixedHash) MarshalText

func (h UnprefixedHash) MarshalText() ([]byte, error)

MarshalText encodes the hash as hex.

func (*UnprefixedHash) UnmarshalText

func (h *UnprefixedHash) UnmarshalText(input []byte) error

UnmarshalText decodes the hash from hex. The 0x prefix is optional.

type WriteCounter

type WriteCounter StorageSize

func (*WriteCounter) Write

func (c *WriteCounter) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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