state

package
v0.0.0-...-7c12c5a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: GPL-2.0, GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NameRegCodec = wire.Codec{
	Encode: NameRegEncoder,
	Decode: NameRegDecoder,
}

Functions

func ExecBlock

func ExecBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeader) error

NOTE: If an error occurs during block execution, state will be left at an invalid state. Copy the state before calling ExecBlock!

func ExecTx

func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireable) (err error)

If the tx is invalid, an error will be returned. Unlike ExecBlock(), state will not be altered.

func HasPermission

func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) bool

Get permission on an account or fall back to global value

func MakeGenesisStateFromFile

func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) (*GenesisDoc, *State)

func NameRegDecoder

func NameRegDecoder(r io.Reader, n *int64, err *error) interface{}

func NameRegEncoder

func NameRegEncoder(o interface{}, w io.Writer, n *int64, err *error)

func NewContractAddress

func NewContractAddress(caller []byte, nonce int) []byte

Convenience function to return address of new contract

Types

type AccountGetter

type AccountGetter interface {
	GetAccount(addr []byte) *acm.Account
}

type BlockCache

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

The blockcache helps prevent unnecessary IAVLTree updates and garbage generation.

func NewBlockCache

func NewBlockCache(backend *State) *BlockCache

func (*BlockCache) GetAccount

func (cache *BlockCache) GetAccount(addr []byte) *acm.Account

func (*BlockCache) GetNameRegEntry

func (cache *BlockCache) GetNameRegEntry(name string) *types.NameRegEntry

func (*BlockCache) GetStorage

func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256)

func (*BlockCache) RemoveAccount

func (cache *BlockCache) RemoveAccount(addr []byte)

func (*BlockCache) RemoveNameRegEntry

func (cache *BlockCache) RemoveNameRegEntry(name string)

func (*BlockCache) SetStorage

func (cache *BlockCache) SetStorage(addr Word256, key Word256, value Word256)

NOTE: Set value to zero to removed from the trie.

func (*BlockCache) State

func (cache *BlockCache) State() *State

func (*BlockCache) Sync

func (cache *BlockCache) Sync()

CONTRACT the updates are in deterministic order.

func (*BlockCache) UpdateAccount

func (cache *BlockCache) UpdateAccount(acc *acm.Account)

func (*BlockCache) UpdateNameRegEntry

func (cache *BlockCache) UpdateNameRegEntry(entry *types.NameRegEntry)

type InvalidTxError

type InvalidTxError struct {
	Tx     types.Tx
	Reason error
}

func (InvalidTxError) Error

func (txErr InvalidTxError) Error() string

type State

type State struct {
	DB                   dbm.DB
	ChainID              string
	LastBlockHeight      int
	LastBlockHash        []byte
	LastBlockParts       types.PartSetHeader
	LastBlockTime        time.Time
	BondedValidators     *types.ValidatorSet
	LastBondedValidators *types.ValidatorSet
	UnbondingValidators  *types.ValidatorSet
	// contains filtered or unexported fields
}

NOTE: not goroutine-safe.

func LoadState

func LoadState(db dbm.DB) *State

func MakeGenesisState

func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State

func RandGenesisState

func RandGenesisState(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*State, []*acm.PrivAccount, []*types.PrivValidator)

func (*State) ComputeBlockStateHash

func (s *State) ComputeBlockStateHash(block *types.Block) error

Mutates the block in place and updates it with new state hash.

func (*State) Copy

func (s *State) Copy() *State

CONTRACT: Copy() is a cheap way to take a snapshot, as if State were copied by value.

func (*State) GetAccount

func (s *State) GetAccount(address []byte) *acm.Account

Returns nil if account does not exist with given address. The returned Account is a copy, so mutating it has no side effects. Implements Statelike

func (*State) GetAccounts

func (s *State) GetAccounts() merkle.Tree

The returned Account is a copy, so mutating it has no side effects.

func (*State) GetGasLimit

func (s *State) GetGasLimit() int64

func (*State) GetNameRegEntry

func (s *State) GetNameRegEntry(name string) *types.NameRegEntry

func (*State) GetNames

func (s *State) GetNames() merkle.Tree

func (*State) GetValidatorInfo

func (s *State) GetValidatorInfo(address []byte) *types.ValidatorInfo

The returned ValidatorInfo is a copy, so mutating it has no side effects.

func (*State) GetValidatorInfos

func (s *State) GetValidatorInfos() merkle.Tree

func (*State) Hash

func (s *State) Hash() []byte

Returns a hash that represents the state data, excluding Last*

func (*State) LoadStorage

func (s *State) LoadStorage(hash []byte) (storage merkle.Tree)

func (*State) RemoveAccount

func (s *State) RemoveAccount(address []byte) bool

Implements Statelike

func (*State) RemoveNameRegEntry

func (s *State) RemoveNameRegEntry(name string) bool

func (*State) Save

func (s *State) Save()

func (*State) SetAccounts

func (s *State) SetAccounts(accounts merkle.Tree)

Set the accounts tree

func (*State) SetDB

func (s *State) SetDB(db dbm.DB)

func (*State) SetFireable

func (s *State) SetFireable(evc events.Fireable)

Implements events.Eventable. Typically uses events.EventCache

func (*State) SetNameReg

func (s *State) SetNameReg(nameReg merkle.Tree)

Set the name reg tree

func (*State) SetValidatorInfo

func (s *State) SetValidatorInfo(valInfo *types.ValidatorInfo) (updated bool)

Returns false if new, true if updated. The valInfo is copied before setting, so mutating it afterwards has no side effects.

func (*State) SetValidatorInfos

func (s *State) SetValidatorInfos(validatorInfos merkle.Tree)

Set the validator infos tree

func (*State) UpdateAccount

func (s *State) UpdateAccount(account *acm.Account) bool

The account is copied before setting, so mutating it afterwards has no side effects. Implements Statelike

func (*State) UpdateNameRegEntry

func (s *State) UpdateNameRegEntry(entry *types.NameRegEntry) bool

type TxCache

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

func NewTxCache

func NewTxCache(backend *BlockCache) *TxCache

func (*TxCache) CreateAccount

func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account

Creates a 20 byte address and bumps the creator's nonce.

func (*TxCache) GetAccount

func (cache *TxCache) GetAccount(addr Word256) *vm.Account

func (*TxCache) GetStorage

func (cache *TxCache) GetStorage(addr Word256, key Word256) Word256

func (*TxCache) RemoveAccount

func (cache *TxCache) RemoveAccount(acc *vm.Account)

func (*TxCache) SetStorage

func (cache *TxCache) SetStorage(addr Word256, key Word256, value Word256)

NOTE: Set value to zero to removed from the trie.

func (*TxCache) Sync

func (cache *TxCache) Sync()

These updates do not have to be in deterministic order, the backend is responsible for ordering updates.

func (*TxCache) UpdateAccount

func (cache *TxCache) UpdateAccount(acc *vm.Account)

type VMAccountState

type VMAccountState interface {
	GetAccount(addr Word256) *vm.Account
	UpdateAccount(acc *vm.Account)
	RemoveAccount(acc *vm.Account)
	CreateAccount(creator *vm.Account) *vm.Account
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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