core

package
v0.0.0-...-e021808 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2018 License: LGPL-2.1 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BlockNumberErr   = errors.New("block number invalid")
	BlockFutureErr   = errors.New("block time is in the future")
	BlockTSTooBigErr = errors.New("block time too big")
	BlockEqualTSErr  = errors.New("block time stamp equal to previous")
)
View Source
var (
	Big0 = big.NewInt(0)
)
View Source
var BlockReward *big.Int = big.NewInt(5e+18)

Functions

func AccumulateRewards

func AccumulateRewards(statedb *state.StateDB, header *types.Header, uncles []*types.Header)

AccumulateRewards credits the coinbase of the given block with the mining reward. The total reward consists of the static block reward and rewards for included uncles. The coinbase of each uncle block is also rewarded.

func ApplyMessage

func ApplyMessage(env *vm.EVM, msg Message, gp *GasPool) ([]byte, *big.Int, error)

ApplyMessage computes the new state by applying the given message against the old state within the environment.

ApplyMessage returns the bytes returned by any EVM execution (if it took place), the gas used (which includes gas refunds) and an error if it failed. An error always indicates a core error meaning that the message would always fail for that particular state and would never be accepted within a block.

func ApplyTransaction

func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, gp *GasPool, statedb *state.StateDB, header *types.Header,
	tx *types.Transaction, txHash []byte, usedGas *big.Int, cfg vm.Config) (*types.Receipt, *big.Int, error)

ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment. It returns the receipt for the transaction, gas used and an error if the transaction failed, indicating the block was invalid.

func CanTransfer

func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool

CanTransfer checks wether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

func GetHashFn

func GetHashFn(ref *types.Header, chain HeaderFetcher) func(n uint64) common.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func IntrinsicGas

func IntrinsicGas(data []byte, contractCreation, homestead bool) *big.Int

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

func IsBadHashError

func IsBadHashError(err error) bool

func IsBlockNonceErr

func IsBlockNonceErr(err error) bool

IsBlockNonceErr returns true for invalid block nonce errors.

func IsGasLimitErr

func IsGasLimitErr(err error) bool

func IsInvalidTxErr

func IsInvalidTxErr(err error) bool

func IsKnownBlockErr

func IsKnownBlockErr(e error) bool

func IsNonceErr

func IsNonceErr(err error) bool

func IsParentErr

func IsParentErr(err error) bool

func IsTDError

func IsTDError(e error) bool

func IsUncleErr

func IsUncleErr(err error) bool

func IsValidationErr

func IsValidationErr(err error) bool

func IsValueTransferErr

func IsValueTransferErr(e error) bool

func MessageCreatesContract

func MessageCreatesContract(msg Message) bool

func NewEVMContext

func NewEVMContext(msg Message, header *types.Header, chain HeaderFetcher) vm.Context

NewEVMContext creates a new context for use in the EVM.

func ParentError

func ParentError(hash common.Hash) error

func Transfer

func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

func UncleError

func UncleError(format string, v ...interface{}) error

Types

type BadHashError

type BadHashError common.Hash

func (BadHashError) Error

func (h BadHashError) Error() string

type BlockChain

type BlockChain struct{}

func (BlockChain) GetHeader

func (bc BlockChain) GetHeader(common.Hash, uint64) *types.Header

type BlockNonceErr

type BlockNonceErr struct {
	Number *big.Int
	Hash   common.Hash
	Nonce  uint64
}

BlockNonceErr indicates that a block's nonce is invalid.

func (*BlockNonceErr) Error

func (err *BlockNonceErr) Error() string

type GasLimitErr

type GasLimitErr struct {
	Have, Want *big.Int
}

func (*GasLimitErr) Error

func (err *GasLimitErr) Error() string

type GasPool

type GasPool big.Int

GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount *big.Int) *GasPool

AddGas makes gas available for execution.

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount *big.Int) error

SubGas deducts the given amount from the pool if enough gas is available and returns an error otherwise.

type HeaderFetcher

type HeaderFetcher interface {
	// GetHeader returns the hash corresponding to their hash
	GetHeader(common.Hash, uint64) *types.Header
}

BlockFetcher retrieves headers by their hash

type InvalidTxErr

type InvalidTxErr struct {
	Message string
}

func InvalidTxError

func InvalidTxError(err error) *InvalidTxErr

func (*InvalidTxErr) Error

func (err *InvalidTxErr) Error() string

type KnownBlockError

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

func (*KnownBlockError) Error

func (self *KnownBlockError) Error() string

type Message

type Message interface {
	From() common.Address
	//FromFrontier() (common.Address, error)
	To() *common.Address

	GasPrice() *big.Int
	Gas() *big.Int
	Value() *big.Int

	Nonce() uint64
	CheckNonce() bool
	Data() []byte
}

Message represents a message sent to a contract.

type NonceErr

type NonceErr struct {
	Message string
	Is, Exp uint64
}

func NonceError

func NonceError(is, exp uint64) *NonceErr

func (*NonceErr) Error

func (err *NonceErr) Error() string

type ParentErr

type ParentErr struct {
	Message string
}

Parent error. In case a parent is unknown this error will be thrown by the block manager

func (*ParentErr) Error

func (err *ParentErr) Error() string

type StateTransition

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

The State Transitioning Model

A state transition is a change made when a transaction is applied to the current world state The state transitioning model does all all the necessary work to work out a valid new state root.

1) Nonce handling 2) Pre pay gas 3) Create a new state object if the recipient is \0*32 4) Value transfer == If contract creation ==

4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object

== end == 5) Run Script section 6) Derive new state root

func NewStateTransition

func NewStateTransition(env *vm.EVM, msg Message, gp *GasPool) *StateTransition

NewStateTransition initialises and returns a new state transition object.

func (*StateTransition) TransitionDb

func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *big.Int, err error)

TransitionDb will move the state by applying the message against the given environment.

type TDError

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

func (*TDError) Error

func (self *TDError) Error() string

type UncleErr

type UncleErr struct {
	Message string
}

func (*UncleErr) Error

func (err *UncleErr) Error() string

type ValidationErr

type ValidationErr struct {
	Message string
}

Block validation error. If any validation fails, this error will be thrown

func ValidationError

func ValidationError(format string, v ...interface{}) *ValidationErr

func (*ValidationErr) Error

func (err *ValidationErr) Error() string

type ValueTransferError

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

func ValueTransferErr

func ValueTransferErr(str string, v ...interface{}) *ValueTransferError

func (*ValueTransferError) Error

func (self *ValueTransferError) Error() string

Directories

Path Synopsis
Package state provides a caching layer atop the Ethereum state trie.
Package state provides a caching layer atop the Ethereum state trie.
Package types contains data types related to Ethereum consensus.
Package types contains data types related to Ethereum consensus.
vm
Package vm implements the Ethereum Virtual Machine.
Package vm implements the Ethereum Virtual Machine.
runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.

Jump to

Keyboard shortcuts

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