Documentation ¶
Index ¶
- Constants
- func NewEstablishTokenTransaction(name string, max uint64) (*transactions.Transaction, error)
- func NewMintTokenTransaction(name string, amount uint64) (*transactions.Transaction, error)
- func NewReceiveTokenTransaction(sendTid string, tip []byte, proof *gossip.Proof, leaves [][]byte) (*transactions.Transaction, error)
- func NewSendTokenTransaction(id, name string, amount uint64, destination string) (*transactions.Transaction, error)
- func NewSetDataBytesTransaction(path string, data []byte) (*transactions.Transaction, error)
- func NewSetDataTransaction(path string, value interface{}) (*transactions.Transaction, error)
- func NewSetOwnershipTransaction(keyAddrs []string) (*transactions.Transaction, error)
- type Block
- type BlockValidatorFunc
- type BlockWithHeaders
- type Chain
- type ChainTree
- func (ct *ChainTree) At(ctx context.Context, tip *cid.Cid) (*ChainTree, error)
- func (ct *ChainTree) Id(ctx context.Context) (string, error)
- func (ct *ChainTree) ProcessBlock(ctx context.Context, blockWithHeaders *BlockWithHeaders) (valid bool, err error)
- func (ct *ChainTree) ProcessBlockImmutable(ctx context.Context, blockWithHeaders *BlockWithHeaders) (newChainTree *ChainTree, valid bool, err error)
- func (ct *ChainTree) Tree(ctx context.Context) (*dag.Dag, error)
- type CodedError
- type ErrorCode
- type Path
- type RootNode
- type TransactorFunc
Constants ¶
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 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 ¶
At returns a new ChainTree with the given tip as the tip. It should be a former tip of the method receiver.
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 ¶
type CodedError ¶
type 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.