db

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package db defines the standard go-summercash transaction database.

Package db defines the standard go-summercash transaction database.

Package db defines the standard go-summercash transaction database.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCommonLeaf defines an error describing a lack of common leaves.
	ErrNoCommonLeaf = errors.New("no common leaf exists")

	// ErrNoParents defines an error describing a lack of parent leaves.
	ErrNoParents = errors.New("leaf has no parents")

	// ErrDuplicateLeaf defines an error describing a duplicate dag leaf.
	ErrDuplicateLeaf = errors.New("leaf already exists in dag")
)
View Source
var (
	// ErrNoOnlyChild represents an error describing a request for an only child where the leaf has multiple or no children.
	ErrNoOnlyChild = errors.New("leaf has no only child")

	// ErrNoMatchingLeaf represents an error describing a request for a child with a particular hash--that of which
	// is nonexistent.
	ErrNoMatchingLeaf = errors.New("no matching leaf")

	// ErrNilLeafContents represents an error describing a leaf value of nil.
	ErrNilLeafContents = errors.New("nil leaf contents")
)
View Source
var ErrNilDag = errors.New("dag has no root")

ErrNilDag is an error definition representing a root dag leaf of nil value.

Functions

This section is empty.

Types

type Dag

type Dag struct {
	Root *Leaf `json:"root"` // Root leaf
}

Dag implements the standard directed acyclic graph global chain.

func ImportBlockmesh

func ImportBlockmesh(dbPath string, inflationRate float64, networkID uint) (*Dag, error)

ImportBlockmesh attempts to reconstruct the dag from a given blockmesh.

func NewDag

func NewDag() *Dag

NewDag initializes a new dag.

func NewDagWithRoot

func NewDagWithRoot(root *Leaf) *Dag

NewDagWithRoot initializes a new dag from a given root.

func ReadDagFromMemory

func ReadDagFromMemory(network string) (*Dag, error)

ReadDagFromMemory attempts to reconstruct a dag from the local persisted dag db.

func UnflattenDag

func UnflattenDag(flattened *Flattened) (*Dag, error)

UnflattenDag attempts to unflatten the given flattened dag.

func (*Dag) AddLeaf

func (dag *Dag) AddLeaf(leaf *Leaf) error

AddLeaf adds a given leaf to the working dag

func (*Dag) AddTransaction

func (dag *Dag) AddTransaction(transaction *types.Transaction) error

AddTransaction adds the given transaction to the working dag.

func (*Dag) Flatten

func (dag *Dag) Flatten() (*Flattened, error)

Flatten flattens the working dag. If the working dag is nil, an error is returned.

func (*Dag) MakeGenesis

func (dag *Dag) MakeGenesis(config *config.ChainConfig) error

MakeGenesis constructs a set of genesis transactions from the given config and adds them to the working dag.

func (*Dag) QueryLeafWithHash

func (dag *Dag) QueryLeafWithHash(hash common.Hash) (*Leaf, error)

QueryLeafWithHash queries the dag for a leaf with the corresponding hash.

func (*Dag) QueryNextCommonLeaf

func (dag *Dag) QueryNextCommonLeaf(lastCommonLeaf *Leaf) (*Leaf, error)

QueryNextCommonLeaf attempts to find the next common leaf in the dag. A common leaf is defined as a leaf that has no siblings. If no common leaf exists, an error is returned.

func (*Dag) QueryTransactionWithHash

func (dag *Dag) QueryTransactionWithHash(hash common.Hash) (*types.Transaction, error)

QueryTransactionWithHash queries the dag for a transaction with the corresponding hash.

func (*Dag) QueryTransactionsWithRecipient

func (dag *Dag) QueryTransactionsWithRecipient(recipient common.Address) ([]*types.Transaction, error)

QueryTransactionsWithRecipient queries the dag for a list of transactions with the corresponding recipient.

func (*Dag) QueryTransactionsWithSender

func (dag *Dag) QueryTransactionsWithSender(sender common.Address) ([]*types.Transaction, error)

QueryTransactionsWithSender queries the dag for a list of transactions with the corresponding sender.

func (*Dag) WriteToMemory

func (dag *Dag) WriteToMemory(network string) error

WriteToMemory writes the working dag to persistent memory.

type Flattened

type Flattened struct {
	Transactions []*types.Transaction `json:"transactions"` // Flattened dag transactions
}

Flattened implements a flattened representation of the standard dag.

type Leaf

type Leaf struct {
	Transaction *types.Transaction `json:"transaction"` // Transaction at leaf

	Parents  []*Leaf `json:"parents"`  // Transaction parents
	Children []*Leaf `json:"children"` // Leaf children

	Hash common.Hash `json:"hash"` // Transaction hash at leaf
}

Leaf defines a leaf in the go-summercash DAG.

func NewLeaf

func NewLeaf(transaction *types.Transaction, parent *Leaf) (*Leaf, error)

NewLeaf initializes a new leaf with the given transaction.

func (*Leaf) GetChildByHash

func (leaf *Leaf) GetChildByHash(hash common.Hash) (*Leaf, error)

GetChildByHash queries the leaf's children for a particular hash. If the hash does not exist, an error is returned.

func (*Leaf) GetChildren

func (leaf *Leaf) GetChildren() ([]*Leaf, error)

GetChildren gets all children of the given leaf.

func (*Leaf) GetChildrenByRecipient

func (leaf *Leaf) GetChildrenByRecipient(recipient common.Address) ([]*Leaf, error)

GetChildrenByRecipient queries the leaf's children for a particular recipient. If a transaction with the corresponding recipient does not exist, an error is returned.

func (*Leaf) GetChildrenBySender

func (leaf *Leaf) GetChildrenBySender(sender common.Address) ([]*Leaf, error)

GetChildrenBySender queries the leaf's children for a particular sender. If a transaction with the corresponding sender does not exist, an error is returned.

func (*Leaf) GetDirectChildByHash

func (leaf *Leaf) GetDirectChildByHash(hash common.Hash) (*Leaf, error)

GetDirectChildByHash searches the set of immediate children for the given hash. If no child exists with the corresponding hash, an error is returned.

func (*Leaf) GetDirectChildrenByRecipient

func (leaf *Leaf) GetDirectChildrenByRecipient(recipient common.Address) ([]*Leaf, error)

GetDirectChildrenByRecipient searches the set of immediate children for the given recipient. If no child exists with the corresponding recipient, an error is returned.

func (*Leaf) GetDirectChildrenBySender

func (leaf *Leaf) GetDirectChildrenBySender(sender common.Address) ([]*Leaf, error)

GetDirectChildrenBySender searches the set of immediate children for the given sender. If no child exists with the corresponding sender, an error is returned.

func (*Leaf) GetNextCommonLeaf

func (leaf *Leaf) GetNextCommonLeaf() (*Leaf, error)

GetNextCommonLeaf implements the functionality of the DAG QueryNextCommonLeaf method.

func (*Leaf) GetOnlyChild

func (leaf *Leaf) GetOnlyChild() (*Leaf, error)

GetOnlyChild returns the only child of the current leaf (if applicable).

func (*Leaf) IsOnlyChild

func (leaf *Leaf) IsOnlyChild() bool

IsOnlyChild determines whether or not the current leaf has any siblings.

Jump to

Keyboard shortcuts

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