state

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(chain Chain, dbKeyMR *factom.Bytes32, eb factom.EBlock) (err error)

func SyncEBlocks

func SyncEBlocks(ctx context.Context, c *factom.Client, chain Chain,
	eblocks []factom.EBlock) error

Types

type Chain

type Chain interface {
	// UpdateSidechainData updates any data from external Chains that the
	// state depends on. This should be called before ApplyEBlock.
	UpdateSidechainData(context.Context, *factom.Client) error

	// Apply applies the next EBlock to the chain state.
	ApplyEBlock(*factom.Bytes32, factom.EBlock) error

	// ApplyEntry applies the next Entry. This is used by the engine for
	// applying pending entries.
	ApplyEntry(factom.Entry) (id int64, err error)

	SetSync(uint32, *factom.Bytes32) error

	// Copy returns a copy of the current state. This allows the engine to
	// save and rollback the in-memory state data.
	Copy() Chain

	Save() func(*error)

	// ToFactomChain returns a pointer to the underlying db.FactomChain
	// that all chains embed.
	ToFactomChain() *db.FactomChain

	Close() error
}

Chain is the interface for advancing a Chain's state. This is used by the engine to apply EBlocks and Entries.

type FATChain

type FATChain db.FATChain

func NewFATChain

func NewFATChain(ctx context.Context, c *factom.Client,
	dbPath, tokenID string,
	identityChainID, chainID *factom.Bytes32,
	networkID factom.NetworkID) (_ FATChain, err error)

func NewFATChainByEBlock

func NewFATChainByEBlock(ctx context.Context, c *factom.Client,
	dbPath string, head factom.EBlock) (chain FATChain, err error)

func ToFATChain

func ToFATChain(chain Chain) (fatChain *FATChain, ok bool)

func (*FATChain) ApplyEBlock

func (chain *FATChain) ApplyEBlock(dbKeyMR *factom.Bytes32, eb factom.EBlock) error

func (*FATChain) ApplyEntry

func (chain *FATChain) ApplyEntry(e factom.Entry) (eID int64, err error)

func (*FATChain) ApplyFAT0Tx

func (chain *FATChain) ApplyFAT0Tx(eID int64, e factom.Entry) (tx fat0.Transaction,
	txErr, err error)

func (*FATChain) ApplyFAT1Tx

func (chain *FATChain) ApplyFAT1Tx(eID int64, e factom.Entry) (tx fat1.Transaction,
	txErr, err error)

func (*FATChain) ApplyIssuance

func (chain *FATChain) ApplyIssuance(ei int64, e factom.Entry) (txErr, err error)

func (*FATChain) ApplyTx

func (chain *FATChain) ApplyTx(eID int64, e factom.Entry) (tx interface{},
	txErr, err error)

func (*FATChain) Copy

func (chain *FATChain) Copy() Chain

func (*FATChain) IsIssued

func (chain *FATChain) IsIssued() bool

func (*FATChain) Save

func (chain *FATChain) Save() func(err *error)

Save the current state of the chain and the database that can be rolled back to if the returned closure is called with a non-nil error.

func (*FATChain) SetSync

func (chain *FATChain) SetSync(height uint32, dbKeyMR *factom.Bytes32) error

func (*FATChain) ToDBFATChain added in v1.1.3

func (chain *FATChain) ToDBFATChain() *db.FATChain

func (*FATChain) ToFactomChain

func (chain *FATChain) ToFactomChain() *db.FactomChain

func (*FATChain) UpdateSidechainData

func (chain *FATChain) UpdateSidechainData(ctx context.Context, c *factom.Client) error

func (*FATChain) Validate

func (chain *FATChain) Validate(ctx context.Context, repair bool) (err error)

Validate all Entry Hashes and EBlock KeyMRs, as well as the continuity of all stored EBlocks and Entries.

This does not validate the validity of the saved DBlock KeyMRs.

type FactomChain

type FactomChain db.FactomChain

func ToFactomChain

func ToFactomChain(chain Chain) (factomChain *FactomChain, ok bool)

func (*FactomChain) ApplyEBlock

func (chain *FactomChain) ApplyEBlock(dbKeyMR *factom.Bytes32, eb factom.EBlock) error

func (*FactomChain) ApplyEntry

func (chain *FactomChain) ApplyEntry(e factom.Entry) (eID int64, err error)

func (*FactomChain) Close

func (chain *FactomChain) Close() error

func (*FactomChain) Copy

func (chain *FactomChain) Copy() Chain

func (*FactomChain) Save

func (chain *FactomChain) Save() func(err *error)

Save the current state of the chain and the database that can be rolled back to if the returned closure is called with a non-nil error.

func (*FactomChain) SetSync

func (chain *FactomChain) SetSync(height uint32, dbKeyMR *factom.Bytes32) error

func (*FactomChain) ToFactomChain

func (chain *FactomChain) ToFactomChain() *db.FactomChain

func (*FactomChain) UpdateSidechainData

func (chain *FactomChain) UpdateSidechainData(context.Context, *factom.Client) error

type ParallelChain

type ParallelChain struct {
	Chain

	trylock.TryLocker
	// contains filtered or unexported fields
}

func ToParallelChain

func ToParallelChain(chain Chain) *ParallelChain

func (*ParallelChain) ApplyEBlockCtx

func (chain *ParallelChain) ApplyEBlockCtx(ctx context.Context,
	dbKeyMR *factom.Bytes32, eb factom.EBlock) error

func (*ParallelChain) ApplyPendingEntries

func (chain *ParallelChain) ApplyPendingEntries(
	ctx context.Context, es []factom.Entry) error

func (*ParallelChain) Close

func (chain *ParallelChain) Close() error

func (*ParallelChain) SetSync

func (chain *ParallelChain) SetSync(height uint32, dbKeyMR *factom.Bytes32) error

type PendingChain

type PendingChain struct {
	Chain

	OfficialState    Chain
	OfficialSnapshot *sqlite.Snapshot

	Session *sqlite.Session

	Entries map[factom.Bytes32]factom.Entry
	// contains filtered or unexported fields
}

func NewPendingChain

func NewPendingChain(ctx context.Context, c *factom.Client, chain Chain) (
	_ *PendingChain, err error)

func ToPendingChain

func ToPendingChain(chain Chain) (pending *PendingChain, ok bool)

func (*PendingChain) ApplyPendingEntries

func (pending *PendingChain) ApplyPendingEntries(es []factom.Entry) error

func (*PendingChain) Close

func (pending *PendingChain) Close() error

func (*PendingChain) LoadFromCache

func (pending *PendingChain) LoadFromCache(eb *factom.EBlock)

func (*PendingChain) Revert

func (pending *PendingChain) Revert() (Chain, error)

type State

type State struct {
	Chains map[factom.Bytes32]Chain

	sync.RWMutex

	DBPath    string
	NetworkID factom.NetworkID

	IgnoreNewChains bool

	SyncHeight  uint32
	SyncDBKeyMR *factom.Bytes32

	Log log.Log

	Lockfile lockfile.Lockfile
	// contains filtered or unexported fields
}

func Open

func Open(ctx context.Context, c *factom.Client,
	dbPath string,
	networkID factom.NetworkID,
	whitelist, blacklist []factom.Bytes32,
	skipDBValidation, repair bool,
) (_ *State, _ context.Context, err error)

func (*State) ApplyEBlock

func (state *State) ApplyEBlock(ctx context.Context,
	dbKeyMR *factom.Bytes32, eb factom.EBlock) (err error)

func (*State) ApplyPendingEntries

func (state *State) ApplyPendingEntries(ctx context.Context,
	es []factom.Entry) error

func (*State) Close

func (state *State) Close()

func (*State) Get

func (state *State) Get(ctx context.Context,
	id *factom.Bytes32, includePending bool) (_ Chain, _ func(), err error)

Get returns a threadsafe connection to the database, and a function to release the connection back to the pool. If pending is true, the chain will reflect the state with pending entries applied. Otherwise the chain will reflect the official state after the most recent EBlock.

func (*State) GetSync

func (state *State) GetSync() uint32

func (*State) IssuedIDs

func (state *State) IssuedIDs() []*factom.Bytes32

func (*State) NewParallelChain

func (state *State) NewParallelChain(ctx context.Context,
	chainID *factom.Bytes32,
	init func(context.Context, *factom.Client,
		factom.EBlock) (Chain, error)) error

func (*State) SetSync

func (state *State) SetSync(ctx context.Context,
	height uint32, dbKeyMR *factom.Bytes32) error

func (*State) TrackedIDs

func (state *State) TrackedIDs() []*factom.Bytes32

type UnknownChain

type UnknownChain struct{}

func (UnknownChain) ApplyEBlock

func (chain UnknownChain) ApplyEBlock(*factom.Bytes32, factom.EBlock) error

func (UnknownChain) ApplyEntry

func (chain UnknownChain) ApplyEntry(factom.Entry) (int64, error)

func (UnknownChain) Close

func (chain UnknownChain) Close() error

func (UnknownChain) Copy

func (chain UnknownChain) Copy() Chain

func (UnknownChain) Save

func (chain UnknownChain) Save() func(*error)

func (UnknownChain) SetSync

func (chain UnknownChain) SetSync(uint32, *factom.Bytes32) error

func (UnknownChain) ToFactomChain

func (chain UnknownChain) ToFactomChain() *db.FactomChain

func (UnknownChain) UpdateSidechainData

func (chain UnknownChain) UpdateSidechainData(context.Context, *factom.Client) error

Jump to

Keyboard shortcuts

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