Documentation ¶
Overview ¶
Package powork provides an easy-to-use proof of work library for golang
Index ¶
- func GetChannel(buffer int) ...
- type PoWork
- type Worker
- func (p *Worker) DoProofFor(msg []byte) (*PoWork, error)
- func (p *Worker) DoProofForString(msg string) (*PoWork, error)
- func (p *Worker) DoProofForStringWithContext(ctx context.Context, msg string) (*PoWork, error)
- func (p *Worker) DoProofForWithContext(ctx context.Context, msg []byte) (*PoWork, error)
- func (p *Worker) PrepareProof(msg []byte) ...
- func (p *Worker) PrepareProofWithContext(ctx context.Context, msg []byte) ...
- func (p *Worker) SendProofToChannel(msg []byte, c ...)
- func (p *Worker) SendProofToChannelWithContext(ctx context.Context, msg []byte, c ...)
- func (p *Worker) SetDifficulty(difficulty int) error
- func (p *Worker) SetHasher(h hash.Hash)
- func (p *Worker) SetTimeout(milliseconds int) error
- func (p *Worker) ValidatePoWork(pow *PoWork) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChannel ¶
GetChannel returns a channel, with the given buffer, that can be used with SendProofToChannel
Types ¶
type PoWork ¶
type PoWork struct {
// contains filtered or unexported fields
}
A PoWork represents a (potentially valid) proof of work for a given message
func (*PoWork) GetMessage ¶
GetMessage gets the message that the proof of work relates to
func (*PoWork) GetMessageString ¶
GetMessageString simply casts the result of GetMessage to a string
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker represents an object that calculates proofs of work and verifies them.
func NewWorker ¶
func NewWorker() *Worker
NewWorker creates a new Worker with sensible defaults: SHA3-512, 10 bit difficulty, and a 5 second timeout.
func NewWorkerWithHash ¶
NewWorkerWithHash creates a new worker with given hash
func (*Worker) DoProofFor ¶
DoProofFor calculates a proof of work for a byte slice
func (*Worker) DoProofForString ¶
DoProofForString calculates a proof of work for a given string
func (*Worker) DoProofForStringWithContext ¶
DoProofForStringWithContext does the same thing as DoProofForString except carrying a context
func (*Worker) DoProofForWithContext ¶
DoProofForWithContext does the same thing as DoProofFor except carrying a context
func (*Worker) PrepareProof ¶
PrepareProof starts working on creating a proof of work for the passed message and returns immediately.
func (*Worker) PrepareProofWithContext ¶
func (p *Worker) PrepareProofWithContext(ctx context.Context, msg []byte) chan struct { *PoWork error }
PrepareProofWithContext does the same thing as PrepareProof except carrying a context
func (*Worker) SendProofToChannel ¶
SendProofToChannel begins computing a proof of work for the given message, and sends it to the passed channel upon completion.
func (*Worker) SendProofToChannelWithContext ¶
func (p *Worker) SendProofToChannelWithContext(ctx context.Context, msg []byte, c chan struct { *PoWork error })
SendProofToChannelWithContext does the same thing as SendProofToChannel except carrying a context
func (*Worker) SetDifficulty ¶
SetDifficulty sets the difficulty of the proof calculated. A higher value represents a more difficult proof. Increases exponentially.
func (*Worker) SetTimeout ¶
SetTimeout sets the amount of time a Worker will spend computing a proof of work before giving up.