block

package
v0.0.0-...-745f595 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package block provides implementations for Nano's block types.

Index

Constants

View Source
const (
	FrontierSize = nano.AddressSize + HashSize
)
View Source
const (
	HashSize = blake2b.Size256
)
View Source
const (
	SignatureSize = ed25519.SignatureSize
)
View Source
const (
	WorkSize = 8
)

Variables

View Source
var (
	ErrBadBlockType = errors.New("bad block type")
	ErrNotABlock    = errors.New("block type is not_a_block")
)

Functions

func Name

func Name(id byte) string

Types

type Block

type Block interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	Hash() Hash
	Root() Hash
	Size() int
	ID() byte
	Valid(threshold uint64) bool
}

func New

func New(blockType byte) (Block, error)

type ChangeBlock

type ChangeBlock struct {
	PreviousHash   Hash         `json:"previous"`
	Representative nano.Address `json:"representative"`
	Signature      Signature    `json:"signature"`
	Work           Work         `json:"work"`
}

func (*ChangeBlock) Hash

func (b *ChangeBlock) Hash() Hash

func (*ChangeBlock) ID

func (b *ChangeBlock) ID() byte

func (*ChangeBlock) MarshalBinary

func (b *ChangeBlock) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*ChangeBlock) Root

func (b *ChangeBlock) Root() Hash

func (*ChangeBlock) Size

func (b *ChangeBlock) Size() int

func (*ChangeBlock) UnmarshalBinary

func (b *ChangeBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*ChangeBlock) Valid

func (b *ChangeBlock) Valid(threshold uint64) bool

type Frontier

type Frontier struct {
	Address nano.Address
	Hash    Hash
}

func (*Frontier) IsZero

func (f *Frontier) IsZero() bool

func (*Frontier) MarshalBinary

func (f *Frontier) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Frontier) UnmarshalBinary

func (f *Frontier) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Hash

type Hash [HashSize]byte

func (Hash) IsZero

func (h Hash) IsZero() bool

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Hash) String

func (h Hash) String() string

String implements the fmt.Stringer interface.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type OpenBlock

type OpenBlock struct {
	SourceHash     Hash         `json:"source"`
	Representative nano.Address `json:"representative"`
	Address        nano.Address `json:"address"`
	Signature      Signature    `json:"signature"`
	Work           Work         `json:"work"`
}

func (*OpenBlock) Hash

func (b *OpenBlock) Hash() Hash

func (*OpenBlock) ID

func (b *OpenBlock) ID() byte

func (*OpenBlock) MarshalBinary

func (b *OpenBlock) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*OpenBlock) Root

func (b *OpenBlock) Root() Hash

func (*OpenBlock) Size

func (b *OpenBlock) Size() int

func (*OpenBlock) UnmarshalBinary

func (b *OpenBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*OpenBlock) Valid

func (b *OpenBlock) Valid(threshold uint64) bool

type ReceiveBlock

type ReceiveBlock struct {
	PreviousHash Hash      `json:"previous"`
	SourceHash   Hash      `json:"source"`
	Signature    Signature `json:"signature"`
	Work         Work      `json:"work"`
}

func (*ReceiveBlock) Hash

func (b *ReceiveBlock) Hash() Hash

func (*ReceiveBlock) ID

func (b *ReceiveBlock) ID() byte

func (*ReceiveBlock) MarshalBinary

func (b *ReceiveBlock) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*ReceiveBlock) Root

func (b *ReceiveBlock) Root() Hash

func (*ReceiveBlock) Size

func (b *ReceiveBlock) Size() int

func (*ReceiveBlock) UnmarshalBinary

func (b *ReceiveBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*ReceiveBlock) Valid

func (b *ReceiveBlock) Valid(threshold uint64) bool

type SendBlock

type SendBlock struct {
	PreviousHash Hash         `json:"previous"`
	Destination  nano.Address `json:"destination"`
	Balance      nano.Balance `json:"balance"`
	Signature    Signature    `json:"signature"`
	Work         Work         `json:"work"`
}

func (*SendBlock) Hash

func (b *SendBlock) Hash() Hash

func (*SendBlock) ID

func (b *SendBlock) ID() byte

func (*SendBlock) MarshalBinary

func (b *SendBlock) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*SendBlock) Root

func (b *SendBlock) Root() Hash

func (*SendBlock) Size

func (b *SendBlock) Size() int

func (*SendBlock) UnmarshalBinary

func (b *SendBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*SendBlock) Valid

func (b *SendBlock) Valid(threshold uint64) bool

type Signature

type Signature [SignatureSize]byte

func (Signature) MarshalText

func (s Signature) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Signature) String

func (s Signature) String() string

String implements the fmt.Stringer interface.

func (*Signature) UnmarshalText

func (s *Signature) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type StateBlock

type StateBlock struct {
	Address        nano.Address `json:"address"`
	PreviousHash   Hash         `json:"previous"`
	Representative nano.Address `json:"representative"`
	Balance        nano.Balance `json:"balance"`
	Link           Hash         `json:"link"`
	Signature      Signature    `json:"signature"`
	Work           Work         `json:"work"`
}

func (*StateBlock) Hash

func (b *StateBlock) Hash() Hash

func (*StateBlock) ID

func (b *StateBlock) ID() byte

func (*StateBlock) IsOpen

func (b *StateBlock) IsOpen() bool

func (*StateBlock) MarshalBinary

func (b *StateBlock) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*StateBlock) Root

func (b *StateBlock) Root() Hash

func (*StateBlock) Size

func (b *StateBlock) Size() int

func (*StateBlock) UnmarshalBinary

func (b *StateBlock) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*StateBlock) Valid

func (b *StateBlock) Valid(threshold uint64) bool

type Vote

type Vote struct {
	Address   nano.Address
	Signature Signature
	Sequence  uint64
	Block     Block
}

func (*Vote) MarshalBinary

func (v *Vote) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Vote) UnmarshalBinary

func (v *Vote) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Work

type Work uint64

func (Work) MarshalText

func (w Work) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Work) String

func (w Work) String() string

String implements the fmt.Stringer interface.

func (*Work) UnmarshalText

func (w *Work) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Work) Valid

func (w Work) Valid(root Hash, threshold uint64) bool

type Worker

type Worker struct {
	Threshold uint64
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(work Work, root Hash, threshold uint64) *Worker

func (*Worker) Generate

func (w *Worker) Generate() Work

func (*Worker) Reset

func (w *Worker) Reset()

func (*Worker) Valid

func (w *Worker) Valid() bool

Jump to

Keyboard shortcuts

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