miner

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateFileName ...
	StateFileName string = "state.txt"
)

Variables

View Source
var (
	// ErrNilBlock ...
	ErrNilBlock = errors.New("block is nil")
	// ErrNoHash ...
	ErrNoHash = errors.New("no hash present")
	// ErrNilTx ...
	ErrNilTx = errors.New("transaction is nil")
	// ErrNoSig ...
	ErrNoSig = errors.New("no signature present")
	// ErrInvalidFromAddress ...
	ErrInvalidFromAddress = errors.New("from address is not valid")
	// ErrInvalidTx ...
	ErrInvalidTx = errors.New("transaction is not valid")
	// ErrNilDiff ...
	ErrNilDiff = errors.New("diff is nil")
)

Functions

func BuildCoderFromBlock

func BuildCoderFromBlock(m *MinedBlock) (*coder.MinedBlock, error)

BuildCoderFromBlock ...

func BuildCoderFromBytes

func BuildCoderFromBytes(data []byte) (*coder.MinedBlock, error)

BuildCoderFromBytes ...

func BuildTxsMap

BuildTxsMap ...

func CheckBlockHashAgainstDifficulty

func CheckBlockHashAgainstDifficulty(block *mainchain.Block) (bool, error)

CheckBlockHashAgainstDifficulty ...

func CheckHashAgainstDifficulty

func CheckHashAgainstDifficulty(hashHex string, difficulty uint64) (bool, error)

CheckHashAgainstDifficulty ...

func VerifyMerkleTreeFromMinedBlock

func VerifyMerkleTreeFromMinedBlock(ctx context.Context, minedBlock *MinedBlock) (bool, error)

VerifyMerkleTreeFromMinedBlock ...

func VerifyMinedBlock

func VerifyMinedBlock(ctx context.Context, p2pSvc p2p.Interface, sbSvc sandbox.Interface, minedBlock *MinedBlock) (bool, error)

VerifyMinedBlock ...

func VerifyStateBlocksFromMinedBlock

func VerifyStateBlocksFromMinedBlock(ctx context.Context, p2pSvc p2p.Interface, sbSvc sandbox.Interface, minedBlock *MinedBlock) (bool, error)

VerifyStateBlocksFromMinedBlock ... note: this function also checks the merkle tree. That check is not required to be performed, separately.

func VerifyTransaction

func VerifyTransaction(tx *statechain.Transaction) (bool, error)

VerifyTransaction ...

Types

type Interface

type Interface interface {
	Props() Props
	SpawnMiner() error
}

Interface ... TODO: finish

type MinedBlock

type MinedBlock struct {
	NextBlock     *mainchain.Block `json:"nextBlock"`
	PreviousBlock *mainchain.Block `json:"previousBlock"`

	StatechainBlocksMap map[string]*statechain.Block       `json:"statechainBlocksMap"`
	TransactionsMap     map[string]*statechain.Transaction `json:"transactionsMap"`
	DiffsMap            map[string]*statechain.Diff        `json:"diffsMap"`
	MerkleTreesMap      map[string]*merkle.Tree            `json:"merkleTreesMap"`
	// contains filtered or unexported fields
}

MinedBlock ...

func BuildBlockFromBytes

func BuildBlockFromBytes(data []byte) (*MinedBlock, error)

BuildBlockFromBytes ...

func BuildBlockFromCoder

func BuildBlockFromCoder(tmp *coder.MinedBlock) (*MinedBlock, error)

BuildBlockFromCoder ...

func (*MinedBlock) Deserialize

func (m *MinedBlock) Deserialize(data []byte) error

Deserialize ...

func (*MinedBlock) DeserializeString

func (m *MinedBlock) DeserializeString(hexStr string) error

DeserializeString ...

func (*MinedBlock) Serialize

func (m *MinedBlock) Serialize() ([]byte, error)

Serialize ...

func (*MinedBlock) SerializeString

func (m *MinedBlock) SerializeString() (string, error)

SerializeString ...

type Props

type Props struct {
	Context             context.Context
	PreviousBlock       *mainchain.Block
	Difficulty          uint64
	Channel             chan interface{}
	Async               bool // note: build state blocks asynchronously?
	EncodedMinerAddress string
	P2P                 p2p.Interface
	Sandbox             sandbox.Interface
	PendingTransactions []*statechain.Transaction
	RemoveTx            func(hash string) error
}

Props is passed to the new function

type Service

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

Service ...

func New

func New(props *Props) (*Service, error)

New returns a new service

func (Service) Props

func (s Service) Props() Props

Props returns the props

func (Service) SpawnMiner

func (s Service) SpawnMiner() error

SpawnMiner ...

Jump to

Keyboard shortcuts

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