types

package
v0.0.0-...-8f649d9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashLength    = 32
	AddressLength = 20
)
View Source
const BloomByteLength = 256

Variables

View Source
var (
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big3   = big.NewInt(3)
	Big0   = big.NewInt(0)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)
)
View Source
var (
	// IstanbulDigest represents a hash of "Istanbul practical byzantine fault tolerance"
	// to identify whether the block is from Istanbul consensus engine
	IstanbulDigest = StringToHash("0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365")

	IstanbulExtraVanity = 32 // Fixed number of extra-data bytes reserved for validator vanity
	IstanbulExtraSeal   = 65 // Fixed number of extra-data bytes reserved for validator seal

	// ErrInvalidIstanbulHeaderExtra is returned if the length of extra-data is less than 32 bytes
	ErrInvalidIstanbulHeaderExtra = errors.New("invalid istanbul header extra-data")
)
View Source
var (
	// EmptyRootHash is the root when there are no transactions
	EmptyRootHash = StringToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
	// EmptyUncleHash is the root when there are no uncles
	EmptyUncleHash = StringToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")
)

Functions

func DeriveChainId

func DeriveChainId(v *big.Int) *big.Int

deriveChainId derives the chain id from the given v parameter

func EmptyHash

func EmptyHash(hash Hash) bool

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func ParseBytes

func ParseBytes(val *string) ([]byte, error)

func ParseInt64orHex

func ParseInt64orHex(val *string) (int64, error)

func ParseUint256orHex

func ParseUint256orHex(val *string) (*big.Int, error)

func ParseUint64orHex

func ParseUint64orHex(val *string) (uint64, error)

Types

type Address

type Address [AddressLength]byte

func BytesToAddress

func BytesToAddress(b []byte) Address

func StringToAddress

func StringToAddress(str string) Address

func (Address) Bytes

func (a Address) Bytes() []byte

func (Address) EIP55

func (a Address) EIP55() string

func (Address) MarshalText

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

func (*Address) Scan

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

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalText

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

UnmarshalText parses an address in hex syntax.

func (Address) Value

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

type Big

type Big big.Int

Big marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

Negative integers are not supported at this time. Attempting to marshal them will return an error. Values larger than 256bits are rejected by Unmarshal but will be marshaled without error.

func (Big) ImplementsGraphQLType

func (b Big) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Big implements the provided GraphQL type.

func (Big) MarshalText

func (b Big) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*Big) String

func (b *Big) String() string

String returns the hex encoding of b.

func (*Big) ToInt

func (b *Big) ToInt() *big.Int

ToInt converts b to a big.Int.

func (*Big) UnmarshalGraphQL

func (b *Big) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Big) UnmarshalJSON

func (b *Big) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Big) UnmarshalText

func (b *Big) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Block

type Block struct {
	Header       *Header
	Transactions []*Transaction
	Uncles       []*Header
}

func (*Block) Body

func (b *Block) Body() *Body

func (*Block) Hash

func (b *Block) Hash() Hash

func (*Block) MarshalWith

func (b *Block) MarshalWith(ar *fastrlp.Arena) *fastrlp.Value

func (*Block) Number

func (b *Block) Number() uint64

func (*Block) ParentHash

func (b *Block) ParentHash() Hash

func (*Block) String

func (b *Block) String() string

func (*Block) UnmarshalRLP

func (b *Block) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error

func (*Block) WithSeal

func (b *Block) WithSeal(header *Header) *Block

WithSeal returns a new block with the data from b but the header replaced with the sealed one.

type Bloom

type Bloom [BloomByteLength]byte

func CreateBloom

func CreateBloom(receipts []*Receipt) (b Bloom)

CreateBloom creates a new bloom filter from a set of receipts

func (*Bloom) Scan

func (b *Bloom) Scan(src interface{}) error

func (Bloom) String

func (b Bloom) String() string

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

func (Bloom) Value

func (b Bloom) Value() (driver.Value, error)

type Body

type Body struct {
	Transactions []*Transaction
	Uncles       []*Header
}

func (*Body) MarshalWith

func (b *Body) MarshalWith(ar *fastrlp.Arena) *fastrlp.Value

func (*Body) UnmarshalRLP

func (b *Body) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error

type Hash

type Hash [HashLength]byte

func BytesToHash

func BytesToHash(b []byte) Hash

func CalcUncleHash

func CalcUncleHash(uncles []*Header) Hash

func StringToHash

func StringToHash(str string) Hash

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) MarshalText

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

func (*Hash) Scan

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

func (Hash) String

func (h Hash) String() string

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)
type Header struct {
	ParentHash   Hash     `json:"parentHash" db:"parent_hash"`
	Sha3Uncles   Hash     `json:"sha3Uncles" db:"sha3_uncles"`
	Miner        Address  `json:"miner" db:"miner"`
	StateRoot    Hash     `json:"stateRoot" db:"state_root"`
	TxRoot       Hash     `json:"transactionsRoot" db:"transactions_root"`
	ReceiptsRoot Hash     `json:"receiptsRoot" db:"receipts_root"`
	LogsBloom    Bloom    `json:"logsBloom" db:"logs_bloom"`
	Difficulty   uint64   `json:"difficulty" db:"difficulty"`
	Number       uint64   `json:"number" db:"number"`
	GasLimit     uint64   `json:"gasLimit" db:"gas_limit"`
	GasUsed      uint64   `json:"gasUsed" db:"gas_used"`
	Timestamp    uint64   `json:"timestamp" db:"timestamp"`
	ExtraData    HexBytes `json:"extraData" db:"extradata"`
	MixHash      Hash     `json:"mixHash" db:"mixhash"`
	Nonce        Nonce    `json:"nonce" db:"nonce"`
	Hash         Hash
}

Header represents a block header in the Ethereum blockchain.

func (*Header) CalculateHash

func (h *Header) CalculateHash() (hash Hash)

func (*Header) ComputeHash

func (h *Header) ComputeHash() *Header

ComputeHash computes the hash of the header

func (*Header) Copy

func (h *Header) Copy() *Header

func (*Header) HasBody

func (h *Header) HasBody() bool

func (*Header) HasReceipts

func (h *Header) HasReceipts() bool

func (*Header) MarshalWith

func (h *Header) MarshalWith(arena *fastrlp.Arena) *fastrlp.Value

MarshalWith marshals the header to RLP with a specific fastrlp.Arena

func (*Header) SetNonce

func (h *Header) SetNonce(i uint64)

func (*Header) UnmarshalRLP

func (h *Header) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error

UnmarshalRLP unmarshals a Header in RLP format

type HeaderWithoutHash

type HeaderWithoutHash struct {
	ParentHash   Hash     `json:"parentHash" db:"parent_hash"`
	Sha3Uncles   Hash     `json:"sha3Uncles" db:"sha3_uncles"`
	Miner        Address  `json:"miner" db:"miner"`
	StateRoot    Hash     `json:"stateRoot" db:"state_root"`
	TxRoot       Hash     `json:"transactionsRoot" db:"transactions_root"`
	ReceiptsRoot Hash     `json:"receiptsRoot" db:"receipts_root"`
	LogsBloom    Bloom    `json:"logsBloom" db:"logs_bloom"`
	Difficulty   uint64   `json:"difficulty" db:"difficulty"`
	Number       uint64   `json:"number" db:"number"`
	GasLimit     uint64   `json:"gasLimit" db:"gas_limit"`
	GasUsed      uint64   `json:"gasUsed" db:"gas_used"`
	Timestamp    uint64   `json:"timestamp" db:"timestamp"`
	ExtraData    HexBytes `json:"extraData" db:"extradata"`
	MixHash      Hash     `json:"mixHash" db:"mixhash"`
	Nonce        Nonce    `json:"nonce" db:"nonce"`
}

func IstanbulFilteredHeader

func IstanbulFilteredHeader(h *Header, keepSeal bool) *HeaderWithoutHash

IstanbulFilteredHeader returns a filtered header which some information (like seal, committed seals) are clean to fulfill the Istanbul hash rules. It returns nil if the extra-data cannot be decoded/encoded by rlp.

type HexBytes

type HexBytes []byte

func (HexBytes) Bytes

func (h HexBytes) Bytes() []byte

func (HexBytes) MarshalText

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

func (*HexBytes) Scan

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

func (HexBytes) String

func (h HexBytes) String() string

func (HexBytes) Value

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

type IstanbulExtra

type IstanbulExtra struct {
	Validators    []Address
	Seal          []byte
	CommittedSeal [][]byte
}

func ExtractIstanbulExtra

func ExtractIstanbulExtra(h *Header) (*IstanbulExtra, error)

ExtractIstanbulExtra extracts all values of the IstanbulExtra from the header. It returns an error if the length of the given extra-data is less than 32 bytes or the extra-data can not be decoded.

func (*IstanbulExtra) DecodeRLP

func (ist *IstanbulExtra) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the istanbul fields from a RLP stream.

func (*IstanbulExtra) EncodeRLP

func (ist *IstanbulExtra) EncodeRLP(w io.Writer) error

EncodeRLP serializes ist into the Ethereum RLP format.

type Log

type Log struct {
	Address     Address  `json:"address"`
	Topics      []Hash   `json:"topics"`
	Data        HexBytes `json:"data"`
	BlockNumber uint64   `json:"blockNumber"`
	TxHash      Hash     `json:"transactionHash"`
	TxIndex     uint     `json:"transactionIndex"`
	BlockHash   Hash     `json:"blockHash"`
	LogIndex    uint     `json:"logIndex"`
	Removed     bool     `json:"removed"`
}

type Nonce

type Nonce [8]byte

func (*Nonce) Scan

func (n *Nonce) Scan(src interface{}) error

func (Nonce) String

func (n Nonce) String() string

func (Nonce) Value

func (n Nonce) Value() (driver.Value, error)

type Receipt

type Receipt struct {
	Root              Hash           `json:"root" db:"root"`
	CumulativeGasUsed uint64         `json:"cumulativeGasUsed" db:"cumulative_gas_used"`
	LogsBloom         Bloom          `json:"logsBloom" db:"bloom"`
	Logs              []*Log         `json:"logs"`
	Status            *ReceiptStatus `json:"status"`
	TxHash            Hash           `json:"transactionHash" db:"txhash"`
	ContractAddress   Address        `json:"contractAddress" db:"contract_address"`
	GasUsed           uint64         `json:"gasUsed" db:"gas_used"`
}

func (*Receipt) MarshalLogsWith

func (r *Receipt) MarshalLogsWith(a *fastrlp.Arena) *fastrlp.Value

MarshalLogsWith marshals the logs of the receipt to RLP with a specific fastrlp.Arena

func (*Receipt) MarshalWith

func (r *Receipt) MarshalWith(a *fastrlp.Arena) *fastrlp.Value

MarshalWith marshals a receipt with a specific fastrlp.Arena

func (*Receipt) SetStatus

func (r *Receipt) SetStatus(s ReceiptStatus)

func (*Receipt) UnmarshalRLP

func (r *Receipt) UnmarshalRLP(v *fastrlp.Value) error

UnmarshalRLP unmarshals a Receipt in RLP format

type ReceiptStatus

type ReceiptStatus uint64
const (
	ReceiptFailed ReceiptStatus = iota
	ReceiptSuccess
)

type Transaction

type Transaction struct {
	Nonce    uint64   `json:"nonce" db:"nonce"`
	GasPrice HexBytes `json:"gasPrice" db:"gas_price"`
	Gas      uint64   `json:"gas" db:"gas"`
	To       *Address `json:"to" db:"dst"`
	Value    HexBytes `json:"value" db:"value"`
	Input    HexBytes `json:"input" db:"input"`

	V byte     `json:"v" db:"v"`
	R HexBytes `json:"r" db:"r"`
	S HexBytes `json:"s" db:"s"`

	Hash Hash
	From Address
}

func (*Transaction) ComputeHash

func (t *Transaction) ComputeHash() *Transaction

ComputeHash computes the hash of the transaction

func (*Transaction) Copy

func (t *Transaction) Copy() *Transaction

func (*Transaction) GetGasPrice

func (t *Transaction) GetGasPrice() []byte

func (*Transaction) IsContractCreation

func (t *Transaction) IsContractCreation() bool

func (*Transaction) MarshalWith

func (t *Transaction) MarshalWith(arena *fastrlp.Arena) *fastrlp.Value

MarshalWith marshals the transaction to RLP with a specific fastrlp.Arena

func (*Transaction) UnmarshalRLP

func (t *Transaction) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error

UnmarshalRLP unmarshals a Transaction in RLP format

type Uint64

type Uint64 uint64

Uint64 marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (Uint64) MarshalText

func (b Uint64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint64) String

func (b Uint64) String() string

String returns the hex encoding of b.

func (*Uint64) UnmarshalJSON

func (b *Uint64) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint64) UnmarshalText

func (b *Uint64) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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