types

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: LGPL-3.0 Imports: 15 Imported by: 0

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 NewBigInt

func NewBigInt(x uint64) *hexutil.Big

NewBigInt creates a big number with specified uint64 value.

func NewBigIntByRaw

func NewBigIntByRaw(x *big.Int) *hexutil.Big

NewBigIntByRaw creates a hexutil.big with specified big.int value.

func NewBytes

func NewBytes(input []byte) hexutil.Bytes

NewBytes creates a hexutil.Bytes with specified input value.

func NewUint

func NewUint(x uint) *hexutil.Uint

NewUint creates a hexutil.Uint with specified uint value.

func NewUint64

func NewUint64(x uint64) *hexutil.Uint64

NewUint64 creates a hexutil.Uint64 with specified uint64 value.

Types

type AccountPendingTransactions

type AccountPendingTransactions struct {
	PendingTransactions []Transaction `json:"pendingTransactions"`
	// type maybe string/Pending
	FirstTxStatus *TransactionStatus `json:"firstTxStatus"`
	PendingCount  hexutil.Uint64     `json:"pendingCount"`
}

type Address

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

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

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

GetMappedEVMSpaceAddress calculate CFX space address's mapped EVM address, which is the last 20 bytes of cfx address's keccak256 hash

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

func (a *Address) GetShortenAddress(isTail4Char ...bool) string

GetShortenAddress returns shorten string for display in dapp. When isTail4Char is 'true', the result will be like 'cfx:aat…sa4w', otherwise 'cfx:aat…5m81sa4w'

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 Bloom

type Bloom string

Bloom is a hash type with 256 bytes.

type Body

type Body [34]byte

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

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 Epoch

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

Epoch represents an epoch in Conflux.

var (
	EpochEarliest         *Epoch = &Epoch{"earliest", nil}
	EpochLatestCheckpoint *Epoch = &Epoch{"latest_checkpoint", nil}
	EpochLatestConfirmed  *Epoch = &Epoch{"latest_confirmed", nil}
	EpochLatestState      *Epoch = &Epoch{"latest_state", nil}
	EpochLatestMined      *Epoch = &Epoch{"latest_mined", nil}
	EpochLatestFinalized  *Epoch = &Epoch{"latest_finalized", nil}
)

Const epoch definitions

func NewEpochNumber

func NewEpochNumber(number *hexutil.Big) *Epoch

NewEpochNumber creates an instance of Epoch with specified number.

func NewEpochNumberBig

func NewEpochNumberBig(number *big.Int) *Epoch

NewEpochNumberBig creates an instance of Epoch with specified big number.

func NewEpochNumberUint64

func NewEpochNumberUint64(number uint64) *Epoch

NewEpochNumberUint64 creates an instance of Epoch with specified uint64 number.

func (*Epoch) Equals

func (e *Epoch) Equals(target *Epoch) bool

Equals checks if e equals target

func (Epoch) MarshalText

func (e Epoch) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Epoch) String

func (e *Epoch) String() string

String implements the fmt.Stringer interface

func (*Epoch) ToInt

func (e *Epoch) ToInt() (result *big.Int, isSuccess bool)

ToInt returns epoch number in type big.Int

func (*Epoch) UnmarshalJSON

func (e *Epoch) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type EpochOrBlockHash

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

func NewEpochOrBlockHashWithBlockHash

func NewEpochOrBlockHashWithBlockHash(blockHash Hash, requirePivot ...bool) *EpochOrBlockHash

NewEpochOrBlockHashWithBlockHash creates an instance of Epoch with specified block hash.

func NewEpochOrBlockHashWithEpoch

func NewEpochOrBlockHashWithEpoch(epoch *Epoch) *EpochOrBlockHash

NewEpochOrBlockHashWithEpoch creates an instance of Epoch with specified epoch.

func (*EpochOrBlockHash) IsBlockHash

func (e *EpochOrBlockHash) IsBlockHash() (*common.Hash, bool, bool)

IsBlockHash returns "block hash" and "require pivot" if it is blockhash, and the 3rd return value represents if is block hash.

func (*EpochOrBlockHash) IsEpoch

func (e *EpochOrBlockHash) IsEpoch() (*Epoch, bool)

IsEpoch returns epoch if it is epoch, and the 2rd return value represents if is epoch.

func (EpochOrBlockHash) MarshalJSON

func (e EpochOrBlockHash) MarshalJSON() ([]byte, error)

func (EpochOrBlockHash) MarshalText

func (e EpochOrBlockHash) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*EpochOrBlockHash) String

func (e *EpochOrBlockHash) String() string

String implements the fmt.Stringer interface

func (*EpochOrBlockHash) UnmarshalJSON

func (e *EpochOrBlockHash) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type EvmSpaceOutcome

type EvmSpaceOutcome uint8
const (
	EVM_SPACE_FAIL EvmSpaceOutcome = iota
	EVM_SPACE_SUCCESS
	EVM_SPACE_SKIPPED = 0xff
)

type Hash

type Hash string

func (Hash) String

func (hash Hash) String() string

String implements the interface stringer

func (Hash) ToCommonHash

func (hash Hash) ToCommonHash() *common.Hash

ToCommonHash converts hash to common.Hash

func (*Hash) UnmarshalJSON

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

type Log

type Log struct {
	Address             Address       `json:"address"`
	Topics              []Hash        `json:"topics"`
	Data                hexutil.Bytes `json:"data"`
	BlockHash           *Hash         `json:"blockHash,omitempty"`
	EpochNumber         *hexutil.Big  `json:"epochNumber,omitempty"`
	TransactionHash     *Hash         `json:"transactionHash,omitempty"`
	TransactionIndex    *hexutil.Big  `json:"transactionIndex,omitempty"`
	LogIndex            *hexutil.Big  `json:"logIndex,omitempty"`
	TransactionLogIndex *hexutil.Big  `json:"transactionLogIndex,omitempty"`
	Space               *SpaceType    `json:"space,omitempty"`
}

Log represents the event in a smart contract

func (*Log) DecodeRLP

func (log *Log) DecodeRLP(r *rlp.Stream) error

DecodeRLP implements the rlp.Decoder interface.

func (Log) EncodeRLP

func (log Log) EncodeRLP(w io.Writer) error

EncodeRLP implements the rlp.Encoder interface.

type LogFilter

type LogFilter struct {
	FromEpoch   *Epoch       `json:"fromEpoch,omitempty"`
	ToEpoch     *Epoch       `json:"toEpoch,omitempty"`
	FromBlock   *hexutil.Big `json:"fromBlock,omitempty"`
	ToBlock     *hexutil.Big `json:"toBlock,omitempty"`
	BlockHashes []Hash       `json:"blockHashes,omitempty"`
	Address     []Address    `json:"address,omitempty"`
	Topics      [][]Hash     `json:"topics,omitempty"`
}

func (*LogFilter) UnmarshalJSON

func (l *LogFilter) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type NativeSpaceOutcome

type NativeSpaceOutcome uint8
const (
	NATIVE_SPACE_SUCCESS                         NativeSpaceOutcome = iota
	NATIVE_SPACE_EXCEPTION_WITH_NONCE_BUMPING                       // gas fee charged
	NATIVE_SPACE_EXCEPTION_WITHOUT_NONCE_BUMPING                    // no gas fee charged
)

type NetworkType

type NetworkType string

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 NonceType

type NonceType int
const (
	NONCE_TYPE_AUTO NonceType = iota
	NONCE_TYPE_NONCE
	NONCE_TYPE_PENDING_NONCE
)

type PendingReason

type PendingReason string
const (
	PENDING_REASON_FUTURE_NONCE     PendingReason = "futureNonce"
	PENDING_REASON_NOT_ENOUGH_CASH  PendingReason = "notEnoughCash"
	PENDING_REASON_OLD_EPOCH_HEIGHT PendingReason = "oldEpochHeight"
	PENDING_REASON_OUTDATED_STATUS  PendingReason = "outdatedStatus"
)

type SpaceType

type SpaceType string
const (
	SPACE_EVM    SpaceType = "evm"
	SPACE_NATIVE SpaceType = "native"
	SPACE_NONE   SpaceType = "none"
)

type StorageChange

type StorageChange struct {
	Address Address `json:"address"`
	/// Number of storage collateral units to deposit / refund (absolute value).
	Collaterals hexutil.Uint64 `json:"collaterals"`
}

StorageChange represents storage change information of the address

type Transaction

type Transaction struct {
	// Space            *string          `json:"space,omitempty"` //currently it is always "nil", so comment it now and uncomment it if need later
	Hash             Hash            `json:"hash"`
	Nonce            *hexutil.Big    `json:"nonce"`
	BlockHash        *Hash           `json:"blockHash"`
	TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
	From             Address         `json:"from"`
	To               *Address        `json:"to"`
	Value            *hexutil.Big    `json:"value"`
	GasPrice         *hexutil.Big    `json:"gasPrice"`
	Gas              *hexutil.Big    `json:"gas"`
	ContractCreated  *Address        `json:"contractCreated"`
	Data             string          `json:"data"`
	StorageLimit     *hexutil.Big    `json:"storageLimit"`
	EpochHeight      *hexutil.Big    `json:"epochHeight"`
	ChainID          *hexutil.Big    `json:"chainId"`
	Status           *hexutil.Uint64 `json:"status"`

	//signature
	V *hexutil.Big `json:"v"`
	R *hexutil.Big `json:"r"`
	S *hexutil.Big `json:"s"`
}

func (*Transaction) DecodeRLP

func (tx *Transaction) DecodeRLP(r *rlp.Stream) error

DecodeRLP implements the rlp.Decoder interface.

func (Transaction) EncodeRLP

func (tx Transaction) EncodeRLP(w io.Writer) error

EncodeRLP implements the rlp.Encoder interface.

type TransactionOutcome

type TransactionOutcome uint8
const (
	TRANSACTION_OUTCOME_SUCCESS TransactionOutcome = iota
	TRANSACTION_OUTCOME_FAILURE
	TRANSACTION_OUTCOME_SKIPPED
)

type TransactionReceipt

type TransactionReceipt struct {
	TransactionHash    Hash            `json:"transactionHash"`
	Index              hexutil.Uint64  `json:"index"`
	BlockHash          Hash            `json:"blockHash"`
	EpochNumber        *hexutil.Uint64 `json:"epochNumber"`
	From               Address         `json:"from"`
	To                 *Address        `json:"to"`
	GasUsed            *hexutil.Big    `json:"gasUsed"`
	AccumulatedGasUsed *hexutil.Big    `json:"accumulatedGasUsed,omitempty"`
	GasFee             *hexutil.Big    `json:"gasFee"`
	ContractCreated    *Address        `json:"contractCreated"`
	Logs               []Log           `json:"logs"`
	LogsBloom          Bloom           `json:"logsBloom"`
	StateRoot          Hash            `json:"stateRoot"`
	OutcomeStatus      hexutil.Uint64  `json:"outcomeStatus"`
	TxExecErrorMsg     *string         `json:"txExecErrorMsg"`
	// Whether gas costs were covered by the sponsor.
	GasCoveredBySponsor bool `json:"gasCoveredBySponsor"`
	// Whether storage costs were covered by the sponsor.
	StorageCoveredBySponsor bool `json:"storageCoveredBySponsor"`
	// The amount of storage collateralized by the sender.
	StorageCollateralized hexutil.Uint64 `json:"storageCollateralized"`
	// Storage collaterals released during the execution of the transaction.
	StorageReleased []StorageChange `json:"storageReleased"`
	Space           *SpaceType      `json:"space,omitempty"`
}

TransactionReceipt represents the transaction execution result in Conflux. it is the response from conflux node when sending rpc request, such as cfx_getTransactionReceipt

func (*TransactionReceipt) DecodeRLP

func (tr *TransactionReceipt) DecodeRLP(r *rlp.Stream) error

DecodeRLP implements the rlp.Decoder interface.

func (TransactionReceipt) EncodeRLP

func (tr TransactionReceipt) EncodeRLP(w io.Writer) error

EncodeRLP implements the rlp.Encoder interface.

func (*TransactionReceipt) GetOutcomeType

func (r *TransactionReceipt) GetOutcomeType() (TransactionOutcome, error)

func (*TransactionReceipt) MustGetOutcomeType

func (r *TransactionReceipt) MustGetOutcomeType() TransactionOutcome

type TransactionStatus

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

func (*TransactionStatus) IsPending

func (ts *TransactionStatus) IsPending() (bool, PendingReason)

func (TransactionStatus) MarshalJSON

func (ts TransactionStatus) MarshalJSON() ([]byte, error)

func (TransactionStatus) String

func (ts TransactionStatus) String() string

func (*TransactionStatus) UnmarshalJSON

func (ts *TransactionStatus) UnmarshalJSON(data []byte) error

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
}

func CalcVersionByte

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

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

type WebsocketEpochResponse

type WebsocketEpochResponse struct {
	EpochHashesOrdered []Hash       `json:"epochHashesOrdered"`
	EpochNumber        *hexutil.Big `json:"epochNumber"`
}

WebsocketEpochResponse represents result of epoch websocket subscription

Jump to

Keyboard shortcuts

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