pow

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package pow implements a Proof-of-Work ordering service. This implementation very naive and only support one single node. It demonstrates a permissionless blockchain.

TODO: later improve or remove

Index

Constants

View Source
const Difficulty = 1

Difficulty is the default difficulty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

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

Block is a representation of a batch of transactions for a Proof-of-Work consensus. Each block has a fingerprint as a proof of correctness.

func NewBlock

func NewBlock(ctx context.Context, data validation.Result, opts ...BlockOption) (Block, error)

NewBlock creates a new block.

type BlockOption

type BlockOption func(*blockTemplate)

BlockOption is the type of options to create a block.

func WithDifficulty

func WithDifficulty(diff uint) BlockOption

WithDifficulty is an option to set the difficulty of the proof of work. If the difficulty is set to 0, the hash will be calculated according to the current nonce.

func WithIndex

func WithIndex(index uint64) BlockOption

WithIndex is an option to set the block index.

func WithNonce

func WithNonce(nonce uint64) BlockOption

WithNonce is an option to set the nonce of a block.

func WithRoot

func WithRoot(root []byte) BlockOption

WithRoot is an option to set the root of a block.

type Proof

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

Proof is a proof that the chain of blocks has or has not the key in the store. If the key exists, the proof also contains the value.

- implements ordering.Proof

func NewProof

func NewProof(blocks []Block, path hashtree.Path) (Proof, error)

NewProof creates a new valid proof.

func (Proof) GetKey

func (p Proof) GetKey() []byte

GetKey implements ordering.Proof.

func (Proof) GetValue

func (p Proof) GetValue() []byte

GetValue implements ordering.Proof.

type Service

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

Service is an ordering service powered by a Proof-of-Work consensus algorithm.

- implements ordering.Service

func NewService

func NewService(pool pool.Pool, val validation.Service, trie hashtree.Tree) *Service

NewService creates a new service.

func (*Service) GetProof

func (s *Service) GetProof(key []byte) (ordering.Proof, error)

GetProof implements ordering.Service.

func (*Service) Listen

func (s *Service) Listen() error

Listen implements ordering.Service.

func (*Service) Stop

func (s *Service) Stop() error

Stop implements ordering.Service.

func (*Service) Watch

func (s *Service) Watch(ctx context.Context) <-chan ordering.Event

Watch implements ordering.Service.

Jump to

Keyboard shortcuts

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