messagefactory

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0, BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ZeroWorker is a PoW worker that always returns 0 as the nonce.
	ZeroWorker = WorkerFunc(func([]byte) (uint64, error) { return 0, nil })
)

Functions

This section is empty.

Types

type Events

type Events struct {
	// Fired when a message is built including tips, sequence number and other metadata.
	MessageConstructed *events.Event
	// Fired when an error occurred.
	Error *events.Event
}

Events represents events happening on a message factory.

type MessageFactory

type MessageFactory struct {
	Events *Events
	// contains filtered or unexported fields
}

MessageFactory acts as a factory to create new messages.

func New

func New(store kvstore.KVStore, sequenceKey []byte, localIdentity *identity.LocalIdentity, selector TipSelector) *MessageFactory

New creates a new message factory.

func (*MessageFactory) IssuePayload

func (m *MessageFactory) IssuePayload(p payload.Payload) (*message.Message, error)

IssuePayload creates a new message including sequence number and tip selection and returns it. It also triggers the MessageConstructed event once it's done, which is for example used by the plugins to listen for messages that shall be attached to the tangle.

func (*MessageFactory) SetWorker

func (m *MessageFactory) SetWorker(worker Worker)

SetWorker sets the PoW worker to be used for the messages.

func (*MessageFactory) Shutdown

func (m *MessageFactory) Shutdown()

Shutdown closes the messageFactory and persists the sequence number.

type TipSelector

type TipSelector interface {
	Tips() (trunk message.ID, branch message.ID)
}

A TipSelector selects two tips, branch and trunk, for a new message to attach to.

type TipSelectorFunc

type TipSelectorFunc func() (message.ID, message.ID)

The TipSelectorFunc type is an adapter to allow the use of ordinary functions as tip selectors.

func (TipSelectorFunc) Tips

func (f TipSelectorFunc) Tips() (message.ID, message.ID)

Tips calls f().

type Worker

type Worker interface {
	DoPOW([]byte) (nonce uint64, err error)
}

A Worker performs the PoW for the provided message in serialized byte form.

type WorkerFunc

type WorkerFunc func([]byte) (uint64, error)

The WorkerFunc type is an adapter to allow the use of ordinary functions as a PoW performer.

func (WorkerFunc) DoPOW

func (f WorkerFunc) DoPOW(msg []byte) (uint64, error)

DoPOW calls f(msg).

Jump to

Keyboard shortcuts

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