types

package
v0.0.0-...-508c5de Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: LGPL-2.1-or-later Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BloomLookup

func BloomLookup(bin, topic []byte) bool

This function is called by the function "bloomFilter" defined in the file core/filter.go

func CreateBloom

func CreateBloom(receipts Receipts) []byte

Creates the LogsBloom of a block. That is, the union of the LogsBloom of all the receipts in the block. Each block has many receipts. Each receipt has many logs (each log has 3 fields: the address, the topics and the data). The LogsBloom of a receipt will be the lower 11 bits of the modulo operation by 2048 of the kecchak(address and logs of the receipt) modulo 2048.

func DeriveSha

func DeriveSha(list DerivableList) []byte

Takes as an argument a list of DerivableList objects, constructs a trie and returns the root hash of the trie.

func IsContractAddr

func IsContractAddr(addr []byte) bool

Returns true if the provided 'addr' has a length of 0, false otherwise.

func LogsBloom

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

Returns the LogBloom of a receipt.

func Number

func Number(b1, b2 *Block) bool

Returns true if the block number of b1 is less than b2, false otherwise.

Types

type Block

type Block struct {
	PrevHash ethutil.Bytes
	Uncles   Blocks
	UncleSha []byte
	Coinbase []byte

	Difficulty *big.Int
	Time       int64
	Number     *big.Int
	GasLimit   *big.Int
	GasUsed    *big.Int
	Extra      string
	Nonce      ethutil.Bytes

	TxSha, ReceiptSha []byte
	LogsBloom         []byte
	Reward            *big.Int
	// contains filtered or unexported fields
}

PrevHash: The Keccak 256-bit hash of the parent block’s header, in its entirety;

Uncles : The uncles of the Block.

UncleSha: The Keccak 256-bit hash of the uncles of the Block.

CoinBase: The address of the beneficiary.

beneficiary: The 160-bit address to which all fees collected from the successful mining of this block are transferred.

state: The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed

Difficulty : Difficulty of the current block.

Time: Creation time of the Block.

Number: The number of the Block. This is equal to the number of ancestor blocks.

GasLimit: The maximum gas limit all the transactions inside this Block are allowed to consume.

GasUsed: The total gas used by the transactions of the Block.

Extra: An arbitrary byte array containing data relevant to this block. According to the Ethereum yellow paper this should be 32 bytes or less.

Nonce: The Block nonce. This is what miners keep changing to compute a solution to PoW.

transactions: List of transactions and/or contracts to be created included in this Block.

receipts: The receipts of the transactions

TxSha: The Keccak 256-bit hash of the root node of the transactions trie of the block

ReceiptSha: The Keccak 256-bit hash of the root node of the receipts trie of the block.

LogsBloom: The Bloom filter composed from indexable information (logger address and log topics) contained in each log entry from the receipt of each transaction in the transactions list

Reward: The reward of the beneficiary (miner)

func CreateBlock

func CreateBlock(root interface{},
	prevHash []byte,
	base []byte,
	Difficulty *big.Int,
	Nonce []byte,
	extra string) *Block

Creates a Block. See the Block data structure for an explanation of the fields used.

The root parameter is the root of the block's state trie.

The Block created will be created at the current Unix time.

Notice that there are no transactions and receipts passed as arguments to this function.

func NewBlockFromBytes

func NewBlockFromBytes(raw []byte) *Block

Creates a new Block from raw bytes. These bytes should be the bytes representation of result of the RLP-encoding of a Block.

func NewBlockFromRlpValue

func NewBlockFromRlpValue(rlpValue *ethutil.Value) *Block

Creates a new Block from the rlpValue object. Only the block's header, transactions and uncles are derived from the rlpValue object.

func NewUncleBlockFromValue

func NewUncleBlockFromValue(header *ethutil.Value) *Block

Creates and sets the uncle of a block based on an ethutil.Value object that contains that information.

'header' parameter: an ethutil.Value object containing the header of the uncle block.

The header of the uncle Block (and any Block) contains those fields: PrevHash, UncleSha, Coinbase, state, TxSha, ReceiptSha, LogsBloom, Difficulty, Number, GasLimit, GasUsed, Time, Extra, Nonce. See also the function Block.HashNoNonce() for details about these fields.

func (*Block) BlockInfo

func (block *Block) BlockInfo() BlockInfo

Returns the BlockInfo representation of a Block.

func (*Block) CalcGasLimit

func (block *Block) CalcGasLimit(parent *Block) *big.Int

Calculates the gas limit.

If the Block passed as a parameter is the genesis block the gas limit is set to 10^6.

Otherwise the gas limit will be ~= 1023 * parent.GasLimit + parent.GasUsed*6/5

The minimum gas limit is set to 125000.

func (*Block) Diff

func (block *Block) Diff() *big.Int

Returns the block difficulty.

func (*Block) GetTransaction

func (self *Block) GetTransaction(hash []byte) *Transaction

Searches for a transaction in the current Block based on the transactions hash and the hash parameter and returns it if it exists. Otherwise returns nil.

func (*Block) Hash

func (block *Block) Hash() ethutil.Bytes

Returns the block's hash. To do so, the block's header is first converted to an ethutil.Value object and then the Encode function is called upon the latter.

func (*Block) HashNoNonce

func (block *Block) HashNoNonce() []byte

Returns the hash of an object that is almost the same as a Block. The differences are:

1. The object to be hashed contains only the uncles hash.

2. The object to be hashed contains the root of the state and not eh state as a whole.

3. The object to be hashed contains only the TxSha and not the receipts.

4. The object to be hashed contains only the ReceiptSha and not the transactions.

5. The object to be hashed does not contain the Reward of the miner.

Note: The object to be hashed if appended with the Nonce field of the Block will comprise the Block's header.

func (*Block) N

func (self *Block) N() []byte

Returns the Nonce field of the caller (Block)

func (*Block) Receipts

func (self *Block) Receipts() []*Receipt

Returns the block receipts.

func (*Block) RlpData

func (self *Block) RlpData() interface{}

Returns an object containing the fields of the caller (Block) that can be rlp-encoded.

func (*Block) RlpDecode

func (block *Block) RlpDecode(data []byte)

RLP-decodes a Block. To do so, a new ethutil.Value object is created from the 'data' parameter and then the function Block.RlpValueDecode(data) is called on the current Block. The 'data' parameter represents the rlp-encodable fields of a Block and can be obtained by using the function Block.RlpData().

func (*Block) RlpEncode

func (block *Block) RlpEncode() []byte

Calls Block.Value() function on the current Block and then rlp-encodes the Block. The rlp-encodable fields of a Block are it's header, transactions and uncles.

func (*Block) RlpValueDecode

func (block *Block) RlpValueDecode(decoder *ethutil.Value)

RLP-decodes the rlp-encodable fields of a Block, aka the header, transactions and uncles. parameter decoder: The above fields of the Block after having been cast to an ethutil.Value object.

func (*Block) Root

func (block *Block) Root() interface{}

Returns the block's state root

func (*Block) SetReceipts

func (self *Block) SetReceipts(receipts Receipts)

Sets the receipts of a Block to the parameter 'receipts'. Also calculates and sets the LogsBloom field which is derived by the receipts.

func (*Block) SetTransactions

func (self *Block) SetTransactions(txs Transactions)

Sets the transactions of a Block to the parameter 'transactions'. Also calculates and sets the TxSha field which is derived by the transactions.

func (*Block) SetUncles

func (block *Block) SetUncles(uncles []*Block)

Sets the uncles of a Block to the parameter 'uncles'. This function is also called by Block.CreateBlock. Also sets the UncleSha of the Block based on the provided parameter. To do so, an inner function called rlpUncles() is used.

func (*Block) Size

func (self *Block) Size() ethutil.StorageSize

Returns a float64 object representing the size of storage needed to save this block's rlp-encoding. The rlp-encodable fields of a Block are it's header, transactions and uncles.

func (*Block) State

func (block *Block) State() *state.StateDB

Returns the state of the Block. (not just the root)

func (*Block) String

func (block *Block) String() string

Returns the string representation of a Block object.

func (*Block) Sync

func (block *Block) Sync()

Sync the block's state and contract respectively. For more, see the state package of this go-ethereum version.

func (*Block) Transactions

func (block *Block) Transactions() Transactions

Returns the transactions of the block.

func (*Block) Trie

func (block *Block) Trie() *trie.Trie

Returns the block's state trie

func (*Block) Undo

func (block *Block) Undo()

Resets the state to nil.

func (*Block) Value

func (block *Block) Value() *ethutil.Value

Casts a block to an ethutil.Value object containing the header, the transactions and the uncles of the block and then returns it.

type BlockBy

type BlockBy func(b1, b2 *Block) bool

Used for sorting Blocks

func (BlockBy) Sort

func (self BlockBy) Sort(blocks Blocks)

Sorts Blocks using a blockSorter object

type BlockInfo

type BlockInfo struct {
	Number uint64
	Hash   []byte
	Parent []byte
	TD     *big.Int
}

An object used to represent a Block's main info.

Number: The number of the block

Hash: The hash of the block

Parent: The parent of the block.

TD: used by the package core to store the total difficulty of the chain up to and including this block.

TD(Block) = TD(Block.parent) + Block.difficulty + sum(u.difficulty for u in Block.uncles)

func (*BlockInfo) RlpDecode

func (bi *BlockInfo) RlpDecode(data []byte)

Only a BlockInfo object can call this function.

Param: data: Should be the bytes representation of the RLP-encoding of the caller.

Description: Sets the caller's fields to the RLP-decoded parts of the 'data' parameter. To do so, the parameter `data` is converted to an ethutil.Value object and the RLP-decoding operation happens on the Value object.

More information about the ethutil.Value object can be found in the file ethutil/README.md

func (*BlockInfo) RlpEncode

func (bi *BlockInfo) RlpEncode() []byte

Returns the rlp-encoded object of a BlockInfo object by calling the function Encode defined in ethutil/rlp.go

type BlockProcessor

type BlockProcessor interface {
	Process(*Block) (*big.Int, state.Messages, error)
}

Any type that implements this interface must also implement the function Process which calculates and returns in that order: the total difficulty of the block as a bigInt, the messages of the block (aka the transactions) and/or an error.

In case of an error the values returned by the function Process for the td and messages are nil.

type Blocks

type Blocks []*Block

func (Blocks) AsSet

func (self Blocks) AsSet() ethutil.UniqueSet

Returns Blocks as a set where the elements of the set are the hashes of the Blocks.

type Broadcaster

type Broadcaster interface {
	Broadcast(wire.MsgType, []interface{})
}

A Broadcaster is a type that can broadcast messages of a given type to a list of recipients.

type DerivableList

type DerivableList interface {
	Len() int
	GetRlp(i int) []byte
}

Any type that implements this interface can then call the function types.DeriveSha(list DerivableList) Len(): returns the number of the elements of the object that implements this interface. GetRlp(i int): returns the RLP-encoding of i-th element of the object that implements this interface.

type Receipt

type Receipt struct {
	PostState         []byte
	CumulativeGasUsed *big.Int
	Bloom             []byte
	// contains filtered or unexported fields
}

Represents the receipts field of a Transaction. The receipt contains certain information regarding the execution of the transaction. Each receipt is placed on a trie.

PostState: the state after the execution of the transaction

CumulativeGasUsed: The cumulative gas used up to and including the current transaction of a Block.

Bloom: A hash (2048 bits)

logs: A series of log entries. Each entry is a tuple of the logger’s address, a possibly empty series of 32-byte log topics, and some number of bytes of data. See state/log.go for more.

func NewReceipt

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

Creates a new Receipt object provided the 'root' of the receipts trie and the cumulative gas used.

func NewRecieptFromValue

func NewRecieptFromValue(val *ethutil.Value) *Receipt

Creates a new Receipt object from an rlp-encoded ethutil.Value object 'val'.

func (*Receipt) Cmp

func (self *Receipt) Cmp(other *Receipt) bool

Returns true if the caller Receipt is the same as the 'other', false otherwise. Two Receipt objects are the same if their PostState fields are equal.

func (*Receipt) RlpData

func (self *Receipt) RlpData() interface{}

Returns the rlp-encodable fields of the caller. The only difference between what this function returns and the caller's fields is that this function returns the result of the RlpData() function called on the logs field.

func (*Receipt) RlpEncode

func (self *Receipt) RlpEncode() []byte

Rlp-encoded the rlp-encodable fields of a Receipt object. These fields are obtained through the function Receipt.RlpData().

func (*Receipt) RlpValueDecode

func (self *Receipt) RlpValueDecode(decoder *ethutil.Value)

Sets the caller's receipt fields to the rlp-decoded fields of the decoder parameter.

func (*Receipt) SetLogs

func (self *Receipt) SetLogs(logs state.Logs)

Sets the Receipt logs field equal to the 'logs' parameter.

func (*Receipt) String

func (self *Receipt) String() string

Returns the string representation of the caller.

type Receipts

type Receipts []*Receipt

An array of Receipts.

func (Receipts) GetRlp

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

Returns the rlp-encoding of the i-th Receipt of the caller. This function, along with the Len function are implemented so as that a Receipt object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.

func (Receipts) Len

func (self Receipts) Len() int

Returns the number of Receipts that the caller consists of. This function, along with the GetRlp function are implemented so as that a Receipt object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.

func (Receipts) RlpData

func (self Receipts) RlpData() interface{}

Returns the rlp-encodable fields of the caller, aka an array that contains the result of each of the Receipt.RlpData() calls on each Receipt that the caller consists of.

func (Receipts) RlpEncode

func (self Receipts) RlpEncode() []byte

Returns the rlp-encoding of the caller, aka rlp-encodes each Receipt object that the caller consists of and returns the result.

type Transaction

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

Definition of a transaction object.

Nonce: A value equal to the number of transactions that originated from this address or, in the case of accounts with associated code, the number of contract-creations made by this account.

recipient: The 160-bit address of the transaction's recipient or, for a contract creation transaction, nil.

value: This is equal to the number of Wei to be transferred to the transaction's recipient or, in the case of contract creation, as an endowment to the newly created account.

gas: The gas limit equal to the maximum amount of gas that should be used when executing this transaction.

gasPrice: This is equal to the number of Wei to be paid per unit of gas for all computation costs incurred as a result of the execution of this transaction.

data: An unlimited size byte array specifying the input data of the transaction. The first 4 bytes of this field specify which function to call when the transaction will execute by using the hash of the function's name to be called and it's arguments. The rest of the data field are the arguments passed to the function. If the data field is empty, it means a transaction is for a payment and not an execution of the contract.

v, r, s: Values corresponding to the ECDSA digital signature of the transaction and used to determine the originating Externally Owned Account.

func NewContractCreationTx

func NewContractCreationTx(value, gas, gasPrice *big.Int, script []byte) *Transaction

Creates and returns a new Transaction which represents the creation of a contract. The Transaction's 'recipient' field will be set to nil and the Transaction's 'data' field will be set equal to the 'script' parameter. All other Transaction fields will be set to the corresponing parameters passed to this function ( except of course for the fields nonce,v,r,s which are not set)

func NewTransactionFromBytes

func NewTransactionFromBytes(data []byte) *Transaction

Creates and returns a new Transaction based on the 'data' parameter. The latter should be a valid rlp-encoding of a Transaction object. (The 'data' parameter is converted to an ethutil.Value object first and then gets decoded)

func NewTransactionFromValue

func NewTransactionFromValue(val *ethutil.Value) *Transaction

Creates and returns a new Transaction based on the 'val' parameter. The latter should be a valid rlp-encoding of a Transaction object that has been cast to an ethutil.Value object.

func NewTransactionMessage

func NewTransactionMessage(to []byte, value, gas, gasPrice *big.Int, data []byte) *Transaction

Creates and returns a new Transaction. All Transaction fields will be set to the corresponing parameters passed to this function ( except of course for the fields nonce,v,r,s which are not set)

func (*Transaction) Curve

func (tx *Transaction) Curve() (v byte, r []byte, s []byte)

Returns v, r, s of the Transaction. r and s are left-padded to 32 bytes. For more, see the function ethutil.leftPadBytes

func (*Transaction) Data

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

Returns the data field of the caller.

func (*Transaction) From

func (self *Transaction) From() []byte

Returns the sender of the transaction.

func (*Transaction) Gas

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

Returns the gas field of the caller.

func (*Transaction) GasPrice

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

Returns the gasPrice field of the caller.

func (*Transaction) Hash

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

Returns the hash of the caller. The hash will be the Kecchak-256 hash of these Transaction fields: nonce, gasPrice, gas, recipient, value, data.

func (*Transaction) Nonce

func (self *Transaction) Nonce() uint64

Returns the nonce field of the caller.

func (*Transaction) PublicKey

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

Retrieves and returns the public key of the transaction. The public key used to be obtained through the github.com/obscuren/secp256k1-go package repo but this package no longer exists. One may now use the function RecoverPubKey from https://github.com/ethereum/go-ethereum/blob/master/crypto/secp256k1/secp256.go

func (*Transaction) RlpData

func (tx *Transaction) RlpData() interface{}

Returns the rlp-encodable fields of the caller (all fields of a Transaction object).

func (*Transaction) RlpDecode

func (tx *Transaction) RlpDecode(data []byte)

Sets the caller's fields equal to the rlp-decoding of the 'data' parameter. The 'data' parameter must be a valid bytes representation of a Transaction that has been cast to an ethutil.Value object.

func (*Transaction) RlpEncode

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

Returns the rlp-encoding of the cast of the caller object to an ethutil.Value object. The cast is done through the Transaction.RlpValue() function)

func (*Transaction) RlpValue

func (tx *Transaction) RlpValue() *ethutil.Value

Casts and returns the caller to an ethutil.Value object.

func (*Transaction) RlpValueDecode

func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value)

Sets the caller's fields equal to the rlp-decoding of the 'decoder'. The 'decoder' must be Transaction cast to an ethutil.Value object.

func (*Transaction) Sender

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

Returns the sender of the transaction. To do so, the public key of the transaction is retrieved first through the function Transaction.PublicKey(). If the public key passes validation then the last 12 bytes of the public key are returned (aka the sender address)

func (*Transaction) SetNonce

func (self *Transaction) SetNonce(nonce uint64)

Sets the caller's nonce field equal to the 'nonce' parameter.

func (*Transaction) Sign

func (tx *Transaction) Sign(privk []byte) error

Signes the transaction. To do so, the function Transaction.Signature is called, which makes use of a non-existent package. Refer to the Transaction.Signature for more. After the transaction has been signed the r,s,v fields of the Transaction are set to the signatures appropriate fields.

r is set to the first 32 bytes of the signature.

s is set to the 32-th up to and including the 63-th bytes of the signature.

v is set to the sum of the last bit of the transaction and the number 27.

func (*Transaction) Signature

func (tx *Transaction) Signature(key []byte) []byte

Calculates and returns the signature of the hash of a transaction with the param key. The signature used to be obtained through the github.com/obscuren/secp256k1-go package repo but this package no longer exists. One may now use the function Sign from https://github.com/ethereum/go-ethereum/blob/master/crypto/secp256k1/secp256.go

func (*Transaction) String

func (tx *Transaction) String() string

Returns the string representation of the caller.

func (*Transaction) To

func (self *Transaction) To() []byte

Returns the recipient field of the caller.

func (*Transaction) Value

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

Returns the value field of the caller.

type Transactions

type Transactions []*Transaction

Transaction slice type for basic sorting

func (Transactions) GetRlp

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

Returns the rlp-encoding of the i-th Transaction of the caller. This function, along with the Len function are implemented so as that a Transaction object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.

func (Transactions) Len

func (s Transactions) Len() int

Returns the number of the Transaction objects that the caller consists of. This function, along with the GetRlp function are implemented so as that a Transaction object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.

func (Transactions) RlpData

func (self Transactions) RlpData() interface{}

Returns the rlp-encodable fields of all the Transaction objects that the caller consists of.

func (Transactions) Swap

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

Swaps two Transaction objects.

type TxByNonce

type TxByNonce struct{ Transactions }

Data type used for performing comparison operations on Transaction objects.

func (TxByNonce) Less

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

Returns true if the i-th Transaction of a list of Transactions is less than the j-th Transaction. This is determined only by comparing the two Transactions' nonces.

Jump to

Keyboard shortcuts

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