chain

package
v0.0.0-...-4502c18 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: GPL-3.0 Imports: 16 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGenesisLoaded returned if genesis chain already been loaded.
	ErrGenesisLoaded = errors.New("The genesis chain has already been loaded")

	// ErrTxInvalidPrevTx is returned if the transaction specified an invalid
	// previous transaction hash.
	ErrTxInvalidPrevTx = errors.New("Invalid previous tx")

	// ErrTxInvalidSignature is returned if signature incorrect.
	ErrTxInvalidSignature = errors.New("Invalid tx signature")

	// ErrTxInsufficientBalance is returned is sender does not have enough coins.
	ErrTxInsufficientBalance = errors.New("Insufficient balance")

	// ErrTxNotFoundInChain is returned if the transaction is not found
	// or is not in a particular chain.
	ErrTxNotFoundInChain = errors.New("Tx not found in chain")

	// ErrTxAlreadyExist is returned if tx already exist in tx list.
	ErrTxAlreadyExist = errors.New("Tx already exist")

	// ErrTxNil if a null pointer was passed when creating a chain
	ErrChainTxNil = errors.New("Genesis tx is nil")

	// ErrChainNotFound is returned is chain not found when writing a new transaction.
	ErrChainNotFound = errors.New("Chain not found")

	// ErrChainEmpty is returned is chain empty.
	ErrChainEmpty = errors.New("Chain empty")

	// ErrInsufficientData is returned if not found previous tx and sync needed.
	ErrInsufficientData = errors.New("Insufficient data")
)

Functions

func CreateTx

func CreateTx(kp *types.KeyPair, amount types.Coin,
	fee types.Coin, recipient types.Hash) (*types.Tx, error)

func LoadGenesis

func LoadGenesis(filename string, h *ChainHelper) error

LoadGenesis loads the genesis chain from the file.

func SubscribeNewBlock

func SubscribeNewBlock() chan events.Eventer

Types

type Chain

type Chain struct {
	Id      types.Hash   `json:"id"`
	Height  uint32       `json:"height"`
	Payload types.Hash   `json:"payload"`
	Txs     []types.Hash `json:"txs"`
	// contains filtered or unexported fields
}

Chain is a branch in a network.

func NewChain

func NewChain(db *leveldb.Db, proc TxProcessor, id types.Hash,
	genesisTx *types.Tx) (*Chain, error)

NewChain creates a new chain with hash name.

func (*Chain) AddTx

func (c *Chain) AddTx(tx *types.Tx) error

AddTx adds a new transaction to the chain.

func (c *Chain) AddTxLink(id types.Hash)

func (*Chain) GetTx

func (c *Chain) GetTx(hash types.Hash) (*types.Tx, error)

GetTx gets a transaction from the chain.

func (*Chain) LastTx

func (c *Chain) LastTx() types.Hash

LastTx returns last tx hash in this chain.

func (*Chain) Save

func (c *Chain) Save() error

Save writes chain to the database.

func (*Chain) UpdatePayload

func (c *Chain) UpdatePayload() types.Hash

UpdatePayload updates payload field responsible for the security of transactions inside.

type ChainHelper

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

ChainHelper is an assistant for management of chains and transactions.

func NewChainHelper

func NewChainHelper(db *leveldb.Db) *ChainHelper

NewChainHelper creates chain helper instance with database tables, TxProcessor and AccountManager instances.

func (*ChainHelper) AccountManager

func (h *ChainHelper) AccountManager() *account.AccountManager

AccountManager gets AccountManager instance.

func (*ChainHelper) GetChainByAddress

func (h *ChainHelper) GetChainByAddress(address []byte) (*Chain, error)

GetChainByAddress gets chain by address wallet.

func (*ChainHelper) GetChainById

func (h *ChainHelper) GetChainById(id []byte) (*Chain, error)

GetChainById gets chain by chainid.

func (*ChainHelper) GetTx

func (h *ChainHelper) GetTx(hash types.Hash) (*types.Tx, error)

GetTx find tx by delegate types.GetTx

func (*ChainHelper) NewTx

func (h *ChainHelper) NewTx(kp *types.KeyPair, amount types.Coin, fee types.Coin,
	recipient types.Hash) (*types.Tx, error)

NewTx prepares new transaction for wallet chain.

func (*ChainHelper) ProcessTx

func (h *ChainHelper) ProcessTx(tx *types.Tx) error

ProcessTx write tx to the database and process its.

type DefaultProcessor

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

DefaultProcessor is the base processor for blocks.

func NewProcessor

func NewProcessor(db *leveldb.Db) *DefaultProcessor

NewProcessor creates a new DefaultProcessor.

func (*DefaultProcessor) Process

func (p *DefaultProcessor) Process(tx *types.Tx, ch *Chain) error

Process called directly for transaction processing. Do not use this method to write to the chain, here only the results are processed.

func (*DefaultProcessor) Validate

func (p *DefaultProcessor) Validate(tx *types.Tx, ch *Chain) error

Validate called before the transaction is written, if nil is returned, it is considered that the transaction is valid.

type TxProcessor

type TxProcessor interface {
	// Process processes the transaction, but does not write to the chain.
	Process(tx *types.Tx, ch *Chain) error

	// Validate checks the transaction for validity.
	Validate(tx *types.Tx, ch *Chain) error
}

TxProcessor responsible for the validation of the transaction and its processing.

Jump to

Keyboard shortcuts

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