state

package
v0.23.3 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GlobalAccountPermissions

func GlobalAccountPermissions(getter AccountGetter) permission.AccountPermissions

Get global permissions from the account at GlobalPermissionsAddress

func GlobalPermissionsAccount

func GlobalPermissionsAccount(getter AccountGetter) *acm.Account

Types

type AccountGetter

type AccountGetter interface {
	// Get an account by its address return nil if it does not exist (which should not be an error)
	GetAccount(address crypto.Address) (*acm.Account, error)
}

type AccountIterable

type AccountIterable interface {
	// Iterates through accounts calling passed function once per account, if the consumer
	// returns true the iteration breaks and returns true to indicate it iteration
	// was escaped
	IterateAccounts(consumer func(*acm.Account) (stop bool)) (stopped bool, err error)
}

type AccountUpdater

type AccountUpdater interface {
	// Updates the fields of updatedAccount by address, creating the account
	// if it does not exist
	UpdateAccount(updatedAccount *acm.Account) error
	// Remove the account at address
	RemoveAccount(address crypto.Address) error
}

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCache

func NewCache(backend Reader, options ...CacheOption) *Cache

Returns a Cache that wraps an underlying Reader to use on a cache miss, can write to an output Writer via Sync. Goroutine safe for concurrent access.

func (*Cache) Flush

func (cache *Cache) Flush(output Writer, backend Reader) error

Syncs the Cache to output and Resets it to use backend as Reader

func (*Cache) GetAccount

func (cache *Cache) GetAccount(address crypto.Address) (*acm.Account, error)

func (*Cache) GetStorage

func (cache *Cache) GetStorage(address crypto.Address, key binary.Word256) (binary.Word256, error)

func (*Cache) IterateCachedAccount

func (cache *Cache) IterateCachedAccount(consumer func(*acm.Account) (stop bool)) (stopped bool, err error)

Iterates over all cached accounts first in cache and then in backend until consumer returns true for 'stop'

func (*Cache) IterateCachedStorage

func (cache *Cache) IterateCachedStorage(address crypto.Address,
	consumer func(key, value binary.Word256) (stop bool)) (stopped bool, err error)

Iterates over all cached storage items first in cache and then in backend until consumer returns true for 'stop'

func (*Cache) RemoveAccount

func (cache *Cache) RemoveAccount(address crypto.Address) error

func (*Cache) Reset

func (cache *Cache) Reset(backend Reader)

Resets the cache to empty initialising the backing map to the same size as the previous iteration.

func (*Cache) SetStorage

func (cache *Cache) SetStorage(address crypto.Address, key binary.Word256, value binary.Word256) error

NOTE: Set value to zero to remove.

func (*Cache) String

func (cache *Cache) String() string

func (*Cache) Sync

func (cache *Cache) Sync(st Writer) error

Syncs changes to the backend in deterministic order. Sends storage updates before updating the account they belong so that storage values can be taken account of in the update.

func (*Cache) UpdateAccount

func (cache *Cache) UpdateAccount(account *acm.Account) error

type CacheOption

type CacheOption func(*Cache) *Cache
var ReadOnly CacheOption = func(cache *Cache) *Cache {
	cache.readonly = true
	return cache
}

func Named added in v0.23.0

func Named(name string) CacheOption

type DumpState added in v0.23.3

type DumpState struct {
	bytes.Buffer
}

func (*DumpState) RemoveAccount added in v0.23.3

func (dw *DumpState) RemoveAccount(address crypto.Address) error

func (*DumpState) SetStorage added in v0.23.3

func (dw *DumpState) SetStorage(address crypto.Address, key, value binary.Word256) error

func (*DumpState) UpdateAccount added in v0.23.3

func (dw *DumpState) UpdateAccount(updatedAccount *acm.Account) error

type Iterable

type Iterable interface {
	AccountIterable
	StorageIterable
}

type IterableReader

type IterableReader interface {
	Iterable
	Reader
}

Read and list account and storage state

type IterableReaderWriter

type IterableReaderWriter interface {
	Iterable
	Reader
	Writer
}

type MemoryState

type MemoryState struct {
	Accounts map[crypto.Address]*acm.Account
	Storage  map[crypto.Address]map[binary.Word256]binary.Word256
}

func NewMemoryState

func NewMemoryState() *MemoryState

Get an in-memory state IterableReader

func (*MemoryState) GetAccount

func (ms *MemoryState) GetAccount(address crypto.Address) (*acm.Account, error)

func (*MemoryState) GetStorage

func (ms *MemoryState) GetStorage(address crypto.Address, key binary.Word256) (binary.Word256, error)

func (*MemoryState) IterateAccounts

func (ms *MemoryState) IterateAccounts(consumer func(*acm.Account) (stop bool)) (stopped bool, err error)

func (*MemoryState) IterateStorage

func (ms *MemoryState) IterateStorage(address crypto.Address, consumer func(key, value binary.Word256) (stop bool)) (stopped bool, err error)

func (*MemoryState) RemoveAccount

func (ms *MemoryState) RemoveAccount(address crypto.Address) error

func (*MemoryState) SetStorage

func (ms *MemoryState) SetStorage(address crypto.Address, key, value binary.Word256) error

func (*MemoryState) UpdateAccount

func (ms *MemoryState) UpdateAccount(updatedAccount *acm.Account) error

type Reader

type Reader interface {
	AccountGetter
	StorageGetter
}

Read-only account and storage state

type ReaderWriter

type ReaderWriter interface {
	Reader
	Writer
}

Read and write account and storage state

type StorageGetter

type StorageGetter interface {
	// Retrieve a 32-byte value stored at key for the account at address, return Zero256 if key does not exist but
	// error if address does not
	GetStorage(address crypto.Address, key binary.Word256) (value binary.Word256, err error)
}

type StorageIterable

type StorageIterable interface {
	// Iterates through the storage of account ad address calling the passed function once per account,
	// if the iterator function returns true the iteration breaks and returns true to indicate it iteration
	// was escaped
	IterateStorage(address crypto.Address, consumer func(key, value binary.Word256) (stop bool)) (stopped bool, err error)
}

type StorageSetter

type StorageSetter interface {
	// Store a 32-byte value at key for the account at address, setting to Zero256 removes the key
	SetStorage(address crypto.Address, key, value binary.Word256) error
}

type Writer

type Writer interface {
	AccountUpdater
	StorageSetter
}

Jump to

Keyboard shortcuts

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