common

package
v0.1.8-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: GPL-3.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TagAccount represents an account object
	TagAccount = []byte("a")

	// TagChain represents a chain object
	TagChain = []byte("c")

	// TagBlock represents a block object
	TagBlock = []byte("b")

	// TagBlockNumber represents a block object
	TagBlockNumber = []byte("n")

	// TagChainInfo represents a chain information object
	TagChainInfo = []byte("i")

	// TagTransaction represents a transaction object
	TagTransaction = []byte("t")

	// TagReOrg represents a meta object
	TagReOrg = []byte("r")

	// TagMinedBlock represents a mined block data
	TagMinedBlockHeader = []byte("m")
)

Functions

func ComputeTxsRoot

func ComputeTxsRoot(txs []types.Transaction) util.Hash

ComputeTxsRoot computes the merkle root of a set of transactions.

func ExecAllowed

func ExecAllowed(opts ...types.CallOp) bool

ExecAllowed is a convenience method to get the value of OpAllowExec

func HasTxOp

func HasTxOp(opts ...types.CallOp) bool

HasTxOp checks whether a slice of CallOp includes a TxOp

func MakeKeyAccount

func MakeKeyAccount(blockNum uint64, chainID, address []byte) []byte

MakeKeyAccount constructs a key for storing an account. Prefixes: tag_chain + chain ID + tag_account + address + block number (big endian)

func MakeKeyBlock

func MakeKeyBlock(chainID []byte, blockNumber uint64) []byte

MakeKeyBlock constructs a key for storing a block. Prefixes: tag_chain + chain ID + tag_block + block number (big endian)

func MakeKeyBlockHash

func MakeKeyBlockHash(chainID []byte, hash []byte) []byte

MakeKeyBlockHash constructs a key for storing the number of a block with a matching hash. Prefixes: tag_chain + chain ID + tag_block + block hash

func MakeKeyChain

func MakeKeyChain(chainID []byte) []byte

MakeKeyChain constructs a key for storing chain information. Prefixes: tag_chain_info + chain ID

func MakeKeyMinedBlock

func MakeKeyMinedBlock(chainID []byte, blockNumber uint64) []byte

MakeKeyMinedBlock constructs a key for recording information about blocks mined

func MakeKeyReOrg

func MakeKeyReOrg(timestamp int64) []byte

MakeKeyReOrg constructs a key for storing reorganization info. Prefixes: tag_reOrg + timestamp (big endian)

func MakeKeyTransaction

func MakeKeyTransaction(chainID []byte, blockNumber uint64, txHash []byte) []byte

MakeKeyTransaction constructs a key for storing a transaction. Prefixes: tag_chain + chain ID + tag_transaction + transaction hash + block number (big endian)

func MakeQueryKeyAccount

func MakeQueryKeyAccount(chainID, address []byte) []byte

MakeQueryKeyAccount constructs a key for finding account data in the store and hash tree. Prefixes: tag_chain + chain ID + tag_account + address

func MakeQueryKeyAccounts

func MakeQueryKeyAccounts(chainID []byte) []byte

MakeQueryKeyAccounts constructs a key for querying all accounts in a given chain. Prefixes: tag_chain + chain ID + tag_account

func MakeQueryKeyBlocks

func MakeQueryKeyBlocks(chainID []byte) []byte

MakeQueryKeyBlocks constructs a key for querying all blocks in given chain. Prefixes: tag_chain + chain ID + tag_block

func MakeQueryKeyChains

func MakeQueryKeyChains() []byte

MakeQueryKeyChains constructs a key to find all chain information. Prefixes: tag_chain_info

func MakeQueryKeyMinedBlocks

func MakeQueryKeyMinedBlocks(chainID []byte) []byte

MakeQueryKeyMinedBlocks constructs a key for querying all mined blocks in given chain. Prefixes: tag_chain + chain ID + tag_mined_block

func MakeQueryKeyReOrg

func MakeQueryKeyReOrg() []byte

MakeQueryKeyReOrg constructs a key for querying reorganization core. Prefixes: tag_reOrg

func MakeQueryKeyTransaction

func MakeQueryKeyTransaction(chainID []byte, txHash []byte) []byte

MakeQueryKeyTransaction constructs a key for querying a transaction. Prefixes: tag_chain + chain ID + tag_transaction + transaction hash

func MakeQueryKeyTransactions

func MakeQueryKeyTransactions(chainID []byte) []byte

MakeQueryKeyTransactions constructs a key for querying all transactions in a chain. Prefixes: tag_chain + chain ID + tag_transaction

func MakeTreeKey

func MakeTreeKey(blockNumber uint64, objectType []byte) []byte

MakeTreeKey constructs a key for recording state objects in a tree. Combination: block number (big endian) + object type

Types

type DocType

type DocType int

DocType represents a document type

const (
	// TypeBlock represents a block document type
	TypeBlock DocType = 0x1

	// TypeTx represents a transaction document type
	TypeTx DocType = 0x2
)

type Object

type Object interface {
	JSON() ([]byte, error)
}

Object represents an object that can be converted to JSON encoded byte slice

type OpAllowExec

type OpAllowExec bool

OpAllowExec defines a CallOp that indicates whether to execute something

func (OpAllowExec) GetName

func (t OpAllowExec) GetName() string

GetName implements core.CallOp. Allows transitions

type OpBase

type OpBase struct {
	Addr util.String
}

OpBase includes common methods and fields for a transition object

func (*OpBase) Address

func (o *OpBase) Address() util.String

Address returns the address to be acted on

func (*OpBase) Equal

func (o *OpBase) Equal(t Transition) bool

Equal checks whether a Transition t is equal to o

type OpBlockQueryRange

type OpBlockQueryRange struct {
	Min uint64
	Max uint64
}

OpBlockQueryRange defines the minimum and maximum block number of objects to access.

func GetBlockQueryRangeOp

func GetBlockQueryRangeOp(opts ...types.CallOp) *OpBlockQueryRange

GetBlockQueryRangeOp is a convenience method to get QueryBlockRange option from a slice of CallOps

func (*OpBlockQueryRange) GetName

func (o *OpBlockQueryRange) GetName() string

GetName returns the name of the op

type OpChainer

type OpChainer struct {
	Chain types.Chainer
	// contains filtered or unexported fields
}

OpChainer defines a CallOp for passing a chain

func GetChainerOp

func GetChainerOp(opts ...types.CallOp) *OpChainer

GetChainerOp is a convenience method to get ChainerOp option from a slice of CallOps

func (*OpChainer) GetName

func (t *OpChainer) GetName() string

GetName implements core.CallOp. Allows transitions

type OpCreateAccount

type OpCreateAccount struct {
	*OpBase
	Account types.Account
}

OpCreateAccount describes a transition to create an account

func (*OpCreateAccount) Equal

func (o *OpCreateAccount) Equal(t Transition) bool

Equal checks whether a Transition t is equal to o

type OpNewAccountBalance

type OpNewAccountBalance struct {
	*OpBase
	Account types.Account
}

OpNewAccountBalance represents a transition to a new account balance

func (*OpNewAccountBalance) Equal

func (o *OpNewAccountBalance) Equal(t Transition) bool

Equal checks whether a Transition t is equal to o

type OpTransitions

type OpTransitions []Transition

OpTransitions defines a CallOp for passing transition objects

func (*OpTransitions) GetName

func (t *OpTransitions) GetName() string

GetName implements core.CallOp. Allows transitions

type OpTx

type OpTx struct {
	Tx        elldb.Tx
	CanFinish bool
	// contains filtered or unexported fields
}

OpTx is used to pass transactions to methods

func GetTxOp

func GetTxOp(db elldb.TxCreator, opts ...types.CallOp) *OpTx

GetTxOp checks and return a transaction added in the supplied call option slice. If none is found, a new transaction is created and returned as a TxOp.

func (*OpTx) Closed

func (t *OpTx) Closed() bool

Closed gets the status of the transaction

func (*OpTx) Commit

func (t *OpTx) Commit() error

Commit commits the transaction if it has not been done before. It ignores the call if CanFinish is false.

func (*OpTx) Discard

func (t *OpTx) Discard() error

Discard the transaction. Do not call functions in the transaction after this.

func (*OpTx) Finishable

func (t *OpTx) Finishable() *OpTx

Finishable makes the transaction finishable

func (*OpTx) GetName

func (t *OpTx) GetName() string

GetName returns the name of the op

func (*OpTx) Rollback

func (t *OpTx) Rollback() error

Rollback rolls back the transaction if it has not been done before. It ignores the call if CanFinish is false.

func (*OpTx) SetFinishable

func (t *OpTx) SetFinishable(finish bool) *OpTx

SetFinishable sets whether the transaction can be finished

type OrphanBlock

type OrphanBlock struct {
	Block      core.Block
	Expiration time.Time
}

OrphanBlock represents an orphan block

type StateObject

type StateObject struct {

	// Key represents the key to use
	// to persist the object to database
	Key []byte

	// Value is the content of this state
	// object. It is written to the database
	// and the tree
	Value []byte
}

StateObject describes an object to be stored in a elldb.StateObject. Usually created after processing a Transition object.

type Transition

type Transition interface {

	// Address returns the address this transition is to affect
	Address() util.String

	// Equal is used to check whether a transition operation t is similar
	Equal(t Transition) bool
}

Transition represents a mutation to the state of a chain

func GetTransitions

func GetTransitions(opts ...types.CallOp) (transitions []Transition)

GetTransitions finds a Transitions option from a given slice of call options and returns a slice of transition objects

type Tree

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

Tree provides merkle tree functionality with the ability to persist the tree content to a storage.

func NewTree

func NewTree() *Tree

NewTree creates an instance of Tree and accepts storage module that implements common.Storer.

func (*Tree) Add

func (t *Tree) Add(item merkletree.Content)

Add adds an item to collection of items to be used to build the tree

func (*Tree) Build

func (t *Tree) Build() error

Build the tree from a slice of item

func (*Tree) GetItems

func (t *Tree) GetItems() []merkletree.Content

GetItems returns the tree items Needs tests

func (*Tree) Root

func (t *Tree) Root() util.Hash

Root returns the root of the tree

type TreeItem

type TreeItem []byte

TreeItem represents an item to be added to the tree

func (TreeItem) CalculateHash

func (i TreeItem) CalculateHash() ([]byte, error)

CalculateHash returns the blake2b-256 hash of the item

func (TreeItem) Equals

func (i TreeItem) Equals(other merkletree.Content) (bool, error)

Equals checks whether the item equal another item

Jump to

Keyboard shortcuts

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