generator

package
v0.0.0-...-8b8382b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package generator implements the Chain Core generator.

A Chain Core configured as a generator produces new blocks on an interval.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockSigner

type BlockSigner interface {
	// SignBlock returns an ed25519 signature over the block's sighash.
	// See also the Chain Protocol spec for the complete required behavior
	// of a block signer.
	SignBlock(ctx context.Context, marshalledBlock []byte) (signature []byte, err error)
}

A BlockSigner signs blocks.

type Generator

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

Generator collects pending transactions and produces new blocks on an interval.

func New

func New(
	c *protocol.Chain,
	s []BlockSigner,
	db pg.DB,
) *Generator

New creates and initializes a new Generator.

func (*Generator) Generate

func (g *Generator) Generate(
	ctx context.Context,
	period time.Duration,
	health func(error),
)

Generate runs in a loop, making one new block every block period. It returns when its context is canceled. After each attempt to make a block, it calls health to report either an error or nil to indicate success.

func (*Generator) PendingTxs

func (g *Generator) PendingTxs() []*legacy.Tx

PendingTxs returns all of the pendings txs that will be included in the generator's next block.

func (*Generator) Submit

func (g *Generator) Submit(ctx context.Context, tx *legacy.Tx) error

Submit adds a new pending tx to the pending tx pool.

Jump to

Keyboard shortcuts

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