types

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package types contains data types related to Ethereum consensus.

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyRootHash  = DeriveSha(Transactions{})
	EmptyUncleHash = CalcUncleHash(nil)
)
View Source
var Bloom9 = bloom9
View Source
var ErrInvalidSig = errors.New("invalid transaction v, r, s values")

Functions

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func CalcUncleHash

func CalcUncleHash(uncles []*Header) common.Hash

func DeriveSha

func DeriveSha(list DerivableList) common.Hash

func LogsBloom

func LogsBloom(logs vm.Logs) *big.Int

func Number

func Number(b1, b2 *Block) bool

Types

type Block

type Block struct {

	// These fields are used by package eth to track
	// inter-peer block relay.
	ReceivedAt   time.Time
	ReceivedFrom interface{}
	// contains filtered or unexported fields
}

Block represents a block in the Ethereum blockchain.

func NewBlock

func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt) *Block

NewBlock creates a new block. The input data is copied, changes to header and to the field values will not affect the block.

The values of TxHash, UncleHash, ReceiptHash and Bloom in header are ignored and set to values derived from the given txs, uncles and receipts.

func NewBlockWithHeader

func NewBlockWithHeader(header *Header) *Block

NewBlockWithHeader creates a block with the given header data. The header data is copied, changes to header and to the field values will not affect the block.

func (*Block) Bloom

func (b *Block) Bloom() Bloom

func (*Block) Body

func (b *Block) Body() *Body

Body returns the non-header content of the block.

func (*Block) Coinbase

func (b *Block) Coinbase() common.Address

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(s *rlp.Stream) error

DecodeRLP decodes the Ethereum

func (*Block) DeprecatedTd

func (b *Block) DeprecatedTd() *big.Int

DeprecatedTd is an old relic for extracting the TD of a block. It is in the code solely to facilitate upgrading the database from the old format to the new, after which it should be deleted. Do not use!

func (*Block) Difficulty

func (b *Block) Difficulty() *big.Int

func (*Block) EncodeRLP

func (b *Block) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP block format.

func (*Block) Extra

func (b *Block) Extra() []byte

func (*Block) GasLimit

func (b *Block) GasLimit() *big.Int

func (*Block) GasUsed

func (b *Block) GasUsed() *big.Int

func (*Block) Hash

func (b *Block) Hash() common.Hash

Hash returns the keccak256 hash of b's header. The hash is computed on the first call and cached thereafter.

func (*Block) HashNoNonce

func (b *Block) HashNoNonce() common.Hash

func (*Block) Header

func (b *Block) Header() *Header

func (*Block) MixDigest

func (b *Block) MixDigest() common.Hash

func (*Block) Nonce

func (b *Block) Nonce() uint64

func (*Block) Number

func (b *Block) Number() *big.Int

func (*Block) NumberU64

func (b *Block) NumberU64() uint64

func (*Block) ParentHash

func (b *Block) ParentHash() common.Hash

func (*Block) ReceiptHash

func (b *Block) ReceiptHash() common.Hash

func (*Block) Root

func (b *Block) Root() common.Hash

func (*Block) Size

func (b *Block) Size() common.StorageSize

func (*Block) String

func (b *Block) String() string

func (*Block) Time

func (b *Block) Time() *big.Int

func (*Block) Transaction

func (b *Block) Transaction(hash common.Hash) *Transaction

func (*Block) Transactions

func (b *Block) Transactions() Transactions

func (*Block) TxHash

func (b *Block) TxHash() common.Hash

func (*Block) UncleHash

func (b *Block) UncleHash() common.Hash

func (*Block) Uncles

func (b *Block) Uncles() []*Header

func (*Block) WithBody

func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block

WithBody returns a new block with the given transaction and uncle contents.

func (*Block) WithCoinbase

func (b *Block) WithCoinbase(coinbase common.Address) *Block

WithCoinbase returns a new block with the data from b where coinbase is set to the provided value.

func (*Block) WithExtraData

func (b *Block) WithExtraData(extraData []byte) *Block

WithExtraData returns a new block with the data from b where extraData is set to the provided value.

type BlockBy

type BlockBy func(b1, b2 *Block) bool

func (BlockBy) Sort

func (self BlockBy) Sort(blocks Blocks)

type BlockNonce

type BlockNonce [8]byte

A BlockNonce is a 64-bit hash which proves (combined with the mix-hash) that a sufficient amount of computation has been carried out on a block.

func EncodeNonce

func EncodeNonce(i uint64) BlockNonce

EncodeNonce converts the given integer to a block nonce.

func (BlockNonce) MarshalJSON

func (n BlockNonce) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (BlockNonce) Uint64

func (n BlockNonce) Uint64() uint64

Uint64 returns the integer value of a block nonce.

func (*BlockNonce) UnmarshalJSON

func (n *BlockNonce) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler

type Blocks

type Blocks []*Block

type Bloom

type Bloom [bloomLength]byte

Bloom represents a 256 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func CreateBloom

func CreateBloom(receipts Receipts) Bloom

func (*Bloom) Add

func (b *Bloom) Add(d *big.Int)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

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

Big converts b to a big integer.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

func (Bloom) MarshalJSON

func (b Bloom) MarshalJSON() ([]byte, error)

MarshalJSON encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(test *big.Int) bool

func (Bloom) TestBytes

func (b Bloom) TestBytes(test []byte) bool

func (*Bloom) UnmarshalJSON

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

UnmarshalJSON b as a hex string with 0x prefix.

type Body

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

Body is a simple (mutable, non-safe) data container for storing and moving a block's data contents (transactions and uncles) together.

type DerivableList

type DerivableList interface {
	Len() int
	GetRlp(i int) []byte
}
type Header struct {
	ParentHash  common.Hash    // Hash to the previous block
	UncleHash   common.Hash    // Uncles of this block
	Coinbase    common.Address // The coin base address
	Root        common.Hash    // Block Trie state
	TxHash      common.Hash    // Tx sha
	ReceiptHash common.Hash    // Receipt sha
	Bloom       Bloom          // Bloom
	Difficulty  *big.Int       // Difficulty for the current block
	Number      *big.Int       // The block number
	GasLimit    *big.Int       // Gas limit
	GasUsed     *big.Int       // Gas used
	Time        *big.Int       // Creation time
	Extra       []byte         // Extra data
	MixDigest   common.Hash    // for quick difficulty verification
	Nonce       BlockNonce
}

Header represents Ethereum block headers.

func CopyHeader

func CopyHeader(h *Header) *Header

CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.

func (*Header) Hash

func (h *Header) Hash() common.Hash

Hash returns the block hash of the header, which is simply the keccak256 hash of its RLP encoding.

func (*Header) HashNoNonce

func (h *Header) HashNoNonce() common.Hash

HashNoNonce returns the hash which is used as input for the proof-of-work search.

func (*Header) MarshalJSON

func (h *Header) MarshalJSON() ([]byte, error)

MarshalJSON encodes headers into the web3 RPC response block format.

func (*Header) QuorumHash

func (h *Header) QuorumHash() common.Hash

QuorumHash returns a RLP hash of header fields relevant to determine if a block was created/signed by an authorized block maker.

func (*Header) String

func (h *Header) String() string

func (*Header) UnmarshalJSON

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

UnmarshalJSON decodes headers from the web3 RPC response block format.

type Receipt

type Receipt struct {
	// Consensus fields
	PostState         []byte
	CumulativeGasUsed *big.Int
	Bloom             Bloom
	Logs              vm.Logs

	// Implementation fields (don't reorder!)
	TxHash          common.Hash
	ContractAddress common.Address
	GasUsed         *big.Int
}

Receipt represents the results of a transaction.

func NewReceipt

func NewReceipt(root []byte, cumulativeGasUsed *big.Int) *Receipt

NewReceipt creates a barebone transaction receipt, copying the init fields.

func (*Receipt) DecodeRLP

func (r *Receipt) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt from an RLP stream.

func (*Receipt) EncodeRLP

func (r *Receipt) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt into an RLP stream.

func (*Receipt) MarshalJSON

func (r *Receipt) MarshalJSON() ([]byte, error)

MarshalJSON encodes receipts into the web3 RPC response block format.

func (*Receipt) String

func (r *Receipt) String() string

String implements the Stringer interface.

func (*Receipt) UnmarshalJSON

func (r *Receipt) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the web3 RPC receipt format.

type ReceiptForStorage

type ReceiptForStorage Receipt

ReceiptForStorage is a wrapper around a Receipt that flattens and parses the entire content of a receipt, as opposed to only the consensus fields originally.

func (*ReceiptForStorage) DecodeRLP

func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and loads both consensus and implementation fields of a receipt from an RLP stream.

func (*ReceiptForStorage) EncodeRLP

func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt into an RLP stream.

type Receipts

type Receipts []*Receipt

Receipts is a wrapper around a Receipt array to implement DerivableList.

func (Receipts) GetRlp

func (r Receipts) GetRlp(i int) []byte

GetRlp returns the RLP encoding of one receipt from the list.

func (Receipts) Len

func (r Receipts) Len() int

Len returns the number of receipts in this list.

type StorageBlock

type StorageBlock Block

[deprecated by eth/63] StorageBlock defines the RLP encoding of a Block stored in the state database. The StorageBlock encoding contains fields that would otherwise need to be recomputed.

func (*StorageBlock) DecodeRLP

func (b *StorageBlock) DecodeRLP(s *rlp.Stream) error

[deprecated by eth/63]

type Transaction

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

func NewContractCreation

func NewContractCreation(nonce uint64, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction

NewContractCreation creates a new transaction with no recipient.

func NewTransaction

func NewTransaction(nonce uint64, to common.Address, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction

NewTransaction creates a new transaction with the given fields.

func (*Transaction) CheckNonce

func (tx *Transaction) CheckNonce() bool

func (*Transaction) Cost

func (tx *Transaction) Cost() *big.Int

Cost returns amount + gasprice * gaslimit.

func (*Transaction) Data

func (tx *Transaction) Data() []byte

func (*Transaction) DecodeRLP

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

DecodeRLP implements rlp.Decoder

func (*Transaction) EncodeRLP

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

DecodeRLP implements rlp.Encoder

func (*Transaction) From

func (tx *Transaction) From() (common.Address, error)

From returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

From Uses the homestead consensus rules to determine whether the signature is valid.

From caches the address, allowing it to be used regardless of Frontier / Homestead. however, the first time called it runs signature validations, so we need two versions. This makes it easier to ensure backwards compatibility of things like package rpc where eth_getblockbynumber uses tx.From() and needs to work for both txs before and after the first homestead block. Signatures valid in homestead are a subset of valid ones in Frontier)

func (*Transaction) FromFrontier

func (tx *Transaction) FromFrontier() (common.Address, error)

FromFrontier returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

FromFrantier uses the frontier consensus rules to determine whether the signature is valid.

FromFrontier caches the address, allowing it to be used regardless of Frontier / Homestead. however, the first time called it runs signature validations, so we need two versions. This makes it easier to ensure backwards compatibility of things like package rpc where eth_getblockbynumber uses tx.From() and needs to work for both txs before and after the first homestead block. Signatures valid in homestead are a subset of valid ones in Frontier)

func (*Transaction) Gas

func (tx *Transaction) Gas() *big.Int

func (*Transaction) GasPrice

func (tx *Transaction) GasPrice() *big.Int

func (*Transaction) Hash

func (tx *Transaction) Hash() common.Hash

Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.

func (*Transaction) IsPrivate

func (tx *Transaction) IsPrivate() bool

func (*Transaction) MarshalJSON

func (tx *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON encodes transactions into the web3 RPC response block format.

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

func (*Transaction) SetPrivate

func (tx *Transaction) SetPrivate()

func (*Transaction) SigHash

func (tx *Transaction) SigHash() common.Hash

SigHash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (*Transaction) SignECDSA

func (tx *Transaction) SignECDSA(prv *ecdsa.PrivateKey) (*Transaction, error)

func (*Transaction) SignatureValues

func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int)

SignatureValues returns the ECDSA signature values contained in the transaction.

func (*Transaction) Size

func (tx *Transaction) Size() common.StorageSize

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) To

func (tx *Transaction) To() *common.Address

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the web3 RPC transaction format.

func (*Transaction) Value

func (tx *Transaction) Value() *big.Int

func (*Transaction) WithSignature

func (tx *Transaction) WithSignature(sig []byte) (*Transaction, error)

WithSignature returns a new transaction with the given signature. This signature needs to be formatted as described in the yellow paper (v+27).

type Transactions

type Transactions []*Transaction

Transaction slice type for basic sorting.

func TxDifference

func TxDifference(a, b Transactions) (keep Transactions)

Returns a new set t which is the difference between a to b

func (Transactions) GetRlp

func (s Transactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp

func (Transactions) Len

func (s Transactions) Len() int

Len returns the length of s

func (Transactions) Swap

func (s Transactions) Swap(i, j int)

Swap swaps the i'th and the j'th element in s

type TransactionsByPriceAndNonce

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

TransactionsByPriceAndNonce represents a set of transactions that can return transactions in a profit-maximising sorted order, while supporting removing entire batches of transactions for non-executable accounts.

func NewTransactionsByPriceAndNonce

func NewTransactionsByPriceAndNonce(txs map[common.Address]Transactions) *TransactionsByPriceAndNonce

NewTransactionsByPriceAndNonce creates a transaction set that can retrieve price sorted transactions in a nonce-honouring way.

Note, the input map is reowned so the caller should not interact any more with if after providing it to the constructor.

func (*TransactionsByPriceAndNonce) Peek

Peek returns the next transaction by price.

func (*TransactionsByPriceAndNonce) Pop

func (t *TransactionsByPriceAndNonce) Pop()

Pop removes the best transaction, *not* replacing it with the next one from the same account. This should be used when a transaction cannot be executed and hence all subsequent ones should be discarded from the same account.

func (*TransactionsByPriceAndNonce) Shift

func (t *TransactionsByPriceAndNonce) Shift()

Shift replaces the current best head with the next one from the same account.

type TransactionsByPriorityAndNonce

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

func NewTransactionsByPriorityAndNonce

func NewTransactionsByPriorityAndNonce(txs map[common.Address]Transactions) *TransactionsByPriorityAndNonce

NewTransactionsByPriorityAndNonce creates a transaction set that can retrieve vote tx sorted transactions in a nonce-honouring way.

Note, the input map is reowned so the caller should not interact any more with it after providing it to the constructor.

func (*TransactionsByPriorityAndNonce) Peek

func (*TransactionsByPriorityAndNonce) Pop

func (*TransactionsByPriorityAndNonce) Shift

func (t *TransactionsByPriorityAndNonce) Shift()

type TxByNonce

type TxByNonce Transactions

TxByNonce implements the sort interface to allow sorting a list of transactions by their nonces. This is usually only useful for sorting transactions from a single account, otherwise a nonce comparison doesn't make much sense.

func (TxByNonce) Len

func (s TxByNonce) Len() int

func (TxByNonce) Less

func (s TxByNonce) Less(i, j int) bool

func (TxByNonce) Swap

func (s TxByNonce) Swap(i, j int)

type TxByPrice

type TxByPrice Transactions

TxByPrice implements both the sort and the heap interface, making it useful for all at once sorting as well as individually adding and removing elements.

func (TxByPrice) Len

func (s TxByPrice) Len() int

func (TxByPrice) Less

func (s TxByPrice) Less(i, j int) bool

func (*TxByPrice) Pop

func (s *TxByPrice) Pop() interface{}

func (*TxByPrice) Push

func (s *TxByPrice) Push(x interface{})

func (TxByPrice) Swap

func (s TxByPrice) Swap(i, j int)

type TxByPriority

type TxByPriority Transactions

TxByPriority implements both sort and the heap interface, making it useful for all at once sorting as well as individual adding and removing elements.

It will prioritise transaction to the voting contract.

func (TxByPriority) Len

func (s TxByPriority) Len() int

func (TxByPriority) Less

func (s TxByPriority) Less(i, j int) bool

func (*TxByPriority) Pop

func (s *TxByPriority) Pop() interface{}

func (*TxByPriority) Push

func (s *TxByPriority) Push(x interface{})

func (TxByPriority) Swap

func (s TxByPriority) Swap(i, j int)

Jump to

Keyboard shortcuts

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