chaintree

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrUnknownTransactionType = 1
	ErrRetryableError         = 2
	ErrInvalidTree            = 3
	ErrUnknown                = 4
	ErrBadHeight              = 5
	ErrBadTip                 = 6

	TreeLabel     = "tree"
	ChainLabel    = "chain"
	ChainEndLabel = "end"
)

Variables

This section is empty.

Functions

func NewEstablishTokenTransaction

func NewEstablishTokenTransaction(name string, max uint64) (*transactions.Transaction, error)

func NewMintTokenTransaction

func NewMintTokenTransaction(name string, amount uint64) (*transactions.Transaction, error)

func NewReceiveTokenTransaction

func NewReceiveTokenTransaction(sendTid string, tip []byte, proof *gossip.Proof, leaves [][]byte) (*transactions.Transaction, error)

func NewSendTokenTransaction

func NewSendTokenTransaction(id, name string, amount uint64, destination string) (*transactions.Transaction, error)

func NewSetDataBytesTransaction

func NewSetDataBytesTransaction(path string, data []byte) (*transactions.Transaction, error)

func NewSetDataTransaction

func NewSetDataTransaction(path string, value interface{}) (*transactions.Transaction, error)

func NewSetOwnershipTransaction

func NewSetOwnershipTransaction(keyAddrs []string) (*transactions.Transaction, error)

Types

type Block

type Block struct {
	PreviousTip  *cid.Cid                    `refmt:"previousTip,omitempty" json:"previousTip,omitempty" cbor:"previousTip,omitempty"`
	Height       uint64                      `refmt:"height" json:"height" cbor:"height"`
	Transactions []*transactions.Transaction `refmt:"transactions" json:"transactions" cbor:"transactions"`
}

type BlockValidatorFunc

type BlockValidatorFunc func(chainTree *dag.Dag, blockWithHeaders *BlockWithHeaders) (valid bool, err CodedError)

BlockValidatorFuncs are run on the block level rather than the per transaction level

type BlockWithHeaders

type BlockWithHeaders struct {
	Block
	PreviousBlock *cid.Cid               `refmt:"previousBlock,omitempty" json:"previousBlock,omitempty" cbor:"previousBlock,omitempty"`
	Headers       map[string]interface{} `refmt:"headers" json:"headers" cbor:"headers"`
}

type Chain

type Chain struct {
	End *cid.Cid `refmt:"end" json:"end" cbor:"end"`
}

type ChainTree

type ChainTree struct {
	Dag             *dag.Dag
	Transactors     map[transactions.Transaction_Type]TransactorFunc
	BlockValidators []BlockValidatorFunc
	Metadata        interface{}
	// contains filtered or unexported fields
}

A Chain Tree is a DAG that starts with the following root node:

{
  id: string
  chain: *cidLink
  tree: *cidLink
}

The chain is for history and the tree is for data. This produces a content-addressable data structure that has its history of change built into the merkle-DAG.

Validators are given the tip of the whole chain tree (chain and tree). Transactions are only given the tip of the tree.

func NewChainTree

func NewChainTree(ctx context.Context, dag *dag.Dag, blockValidators []BlockValidatorFunc, transactors map[transactions.Transaction_Type]TransactorFunc) (*ChainTree, error)

func (*ChainTree) At

func (ct *ChainTree) At(ctx context.Context, tip *cid.Cid) (*ChainTree, error)

At returns a new ChainTree with the given tip as the tip. It should be a former tip of the method receiver.

func (*ChainTree) Id

func (ct *ChainTree) Id(ctx context.Context) (string, error)

Id returns the ID of a chain tree (the ID node in the root of the chaintree)

func (*ChainTree) ProcessBlock

func (ct *ChainTree) ProcessBlock(ctx context.Context, blockWithHeaders *BlockWithHeaders) (valid bool, err error)

ProcessBlock takes a signed block, runs all the validators and if those succeeds it runs the transactors. If all transactors succeed, then the tree of the Chain Tree is updated and the block is appended to the chain part of the Chain Tree

func (*ChainTree) ProcessBlockImmutable

func (ct *ChainTree) ProcessBlockImmutable(ctx context.Context, blockWithHeaders *BlockWithHeaders) (newChainTree *ChainTree, valid bool, err error)

func (*ChainTree) Tree

func (ct *ChainTree) Tree(ctx context.Context) (*dag.Dag, error)

Tree returns just the tree portion of the ChainTree as a pointer to its DAG

type CodedError

type CodedError interface {
	error
	GetCode() int
}

type ErrorCode

type ErrorCode struct {
	Code int
	Memo string
}

func (*ErrorCode) Error

func (e *ErrorCode) Error() string

func (*ErrorCode) GetCode

func (e *ErrorCode) GetCode() int

type Path

type Path []string

type RootNode

type RootNode struct {
	Chain  *cid.Cid `refmt:"chain"`
	Tree   *cid.Cid `refmt:"tree"`
	Id     string   `refmt:"id"`
	Height uint64   `refmt:"height" json:"height" cbor:"height"`
	// contains filtered or unexported fields
}

func (*RootNode) Copy

func (rn *RootNode) Copy() *RootNode

type TransactorFunc

type TransactorFunc func(chainTreeDID string, tree *dag.Dag, transaction *transactions.Transaction) (newTree *dag.Dag, valid bool, err CodedError)

TransactorFunc mutates a ChainTree and returns whether the transaction is valid or if there was an error processing the transactor. Errors should be retried, valid == false means it isn't a valid transaction.

Jump to

Keyboard shortcuts

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