sunyata

package module
v0.0.0-...-e0c2429 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 17 Imported by: 0

README

banner

sunyata

GoDoc Go Report Card

sunyata is a blockchain skeleton. It implements a minimally-functional proof-of-work blockchain, including consensus algorithms, p2p networking, a transaction pool, a wallet, and a simple miner. "Minimally-functional" means that sunyata only supports one transaction type: sending X coins to address Y. There is no scripting system or multisig support; all addresses are pubkey hashes.

But sunyata does implement one feature that no other blockchain does: a UTXO accumulator, namely Tadge Dryja's Utreexo. This accumulator replaces the traditional UTXO database with a Merkle forest; instead of checking for a UTXO's existence within a database, nodes verify a proof of the UTXO's existence (provided in the transaction) against the accumulator. The accumulator itself is tiny -- about 1 KB -- and grows logarithmically with the number of unspent outputs, whereas a database grows linearly.

This design has a number of benefits for performance, scalability, and functionality, making it vastly easier to run a fully-validating node. A new user can start validating new blocks almost instantly: all they need is a copy of the latest accumulator state. Initial block download can be performed in parallel by using multiple accumulator states at checkpoints throughout the chain. And since no costly database operations are required to process incoming blocks, you can sync almost as fast as your disk's write speed.

sunyata is not a cryptocurrency; it's just the skeleton of one. The goal is provide a simple, performant, and robust foundation on which future cryptocurrencies can be built. Accordingly, its design is fairly "conservative" aside from the accumulator; in other words, it cribs heavily from Bitcoin. ;)

Documentation

Overview

Package sunyata defines the basic types and functions of the sunyata system.

Index

Constants

View Source
const EphemeralLeafIndex = math.MaxUint64

EphemeralLeafIndex is used as the LeafIndex of StateElements that are created and spent within the same block. Such elements do not require a proof of existence. They are, however, assigned a proper index and are incorporated into the state accumulator when the block is processed.

Variables

View Source
var BaseUnitsPerCoin = NewCurrency64(1e9)

BaseUnitsPerCoin is the number of base units in a single coin.

Functions

func CurrentTimestamp

func CurrentTimestamp() time.Time

CurrentTimestamp returns the current time, rounded to the nearest second.

func EncodedLen

func EncodedLen(v interface{}) int

EncodedLen returns the length of v when encoded.

Types

type Address

type Address Hash256

An Address is the hash of a public key.

var VoidAddress Address

VoidAddress is an address whose signing key does not exist. Sending coins to this address ensures that they will never be recoverable by anyone.

func ParseAddress

func ParseAddress(s string) (a Address, err error)

ParseAddress parses an address from a prefixed hex encoded string.

func (*Address) DecodeFrom

func (a *Address) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Address) EncodeTo

func (a Address) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(b []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

type Block

type Block struct {
	Header       BlockHeader
	Transactions []Transaction
}

A Block is a set of transactions grouped under a header.

func (*Block) ID

func (b *Block) ID() BlockID

ID returns a hash that uniquely identifies a block. It is equivalent to b.Header.ID().

func (*Block) Index

func (b *Block) Index() ChainIndex

Index returns the block's chain index. It is equivalent to b.Header.Index().

func (*Block) MinerOutputID

func (b *Block) MinerOutputID() ElementID

MinerOutputID returns the output ID of the miner payout.

type BlockHeader

type BlockHeader struct {
	Height       uint64
	ParentID     BlockID
	Nonce        uint64
	Timestamp    time.Time
	MinerAddress Address
	Commitment   Hash256
}

A BlockHeader contains a Block's non-transaction data.

func (*BlockHeader) DecodeFrom

func (h *BlockHeader) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (BlockHeader) EncodeTo

func (h BlockHeader) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (BlockHeader) ID

func (h BlockHeader) ID() BlockID

ID returns a hash that uniquely identifies a block.

func (BlockHeader) Index

func (h BlockHeader) Index() ChainIndex

Index returns the header's chain index.

func (BlockHeader) ParentIndex

func (h BlockHeader) ParentIndex() ChainIndex

ParentIndex returns the index of the header's parent.

type BlockID

type BlockID Hash256

A BlockID uniquely identifies a block.

func HashRequiringWork

func HashRequiringWork(w Work) BlockID

HashRequiringWork returns the best BlockID that the given amount of Work would be expected to produce. Note that many different BlockIDs may require the same amount of Work; this function returns the lowest of them.

func (*BlockID) DecodeFrom

func (id *BlockID) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (BlockID) EncodeTo

func (id BlockID) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (BlockID) MarshalJSON

func (bid BlockID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (BlockID) MarshalText

func (bid BlockID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (BlockID) MeetsTarget

func (bid BlockID) MeetsTarget(t BlockID) bool

MeetsTarget returns true if bid is not greater than t.

func (BlockID) String

func (bid BlockID) String() string

String implements fmt.Stringer.

func (*BlockID) UnmarshalJSON

func (bid *BlockID) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*BlockID) UnmarshalText

func (bid *BlockID) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type ChainIndex

type ChainIndex struct {
	Height uint64
	ID     BlockID
}

A ChainIndex pairs a block's height with its ID.

func ParseChainIndex

func ParseChainIndex(s string) (ci ChainIndex, err error)

ParseChainIndex parses a chain index from a string.

func (*ChainIndex) DecodeFrom

func (index *ChainIndex) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (ChainIndex) EncodeTo

func (index ChainIndex) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (ChainIndex) MarshalText

func (ci ChainIndex) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (ChainIndex) String

func (ci ChainIndex) String() string

String implements fmt.Stringer.

func (*ChainIndex) UnmarshalText

func (ci *ChainIndex) UnmarshalText(b []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

type Currency

type Currency struct {
	Lo, Hi uint64
}

Currency represents a quantity of hastings as an unsigned 128-bit number.

var ZeroCurrency Currency

ZeroCurrency represents zero base units.

func NewCurrency

func NewCurrency(lo, hi uint64) Currency

NewCurrency returns the Currency value (lo,hi).

func NewCurrency64

func NewCurrency64(c uint64) Currency

NewCurrency64 converts c to a Currency value.

func ParseCurrency

func ParseCurrency(s string) (Currency, error)

ParseCurrency parses s as a Currency value. The format of s should match one of the representations provided by (Currency).Format.

func (Currency) Add

func (c Currency) Add(v Currency) Currency

Add returns c+v. If the result would overflow, Add panics.

It is safe to use Add in any context where the sum cannot exceed the total supply of Currency (such as when calculating the balance of a wallet). In less-trusted contexts (such as when validating a transaction), AddWithOverflow should be used instead.

func (Currency) AddWithOverflow

func (c Currency) AddWithOverflow(v Currency) (Currency, bool)

AddWithOverflow returns c+v, along with a boolean indicating whether the result overflowed.

func (Currency) Big

func (c Currency) Big() *big.Int

Big returns c as a *big.Int.

func (Currency) Cmp

func (c Currency) Cmp(v Currency) int

Cmp compares c and v and returns:

-1 if c <  v
 0 if c == v
+1 if c >  v

func (*Currency) DecodeFrom

func (c *Currency) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Currency) Div

func (c Currency) Div(v Currency) Currency

Div returns c/v. If v == 0, Div panics.

func (Currency) Div64

func (c Currency) Div64(v uint64) Currency

Div64 returns c/v. If v == 0, Div panics.

func (Currency) EncodeTo

func (c Currency) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (Currency) Equals

func (c Currency) Equals(v Currency) bool

Equals returns true if c == v.

Currency values can be compared directly with ==, but use of the Equals method is preferred for consistency.

func (Currency) ExactString

func (c Currency) ExactString() string

ExactString returns the base-10 representation of c as a string.

func (Currency) Format

func (c Currency) Format(f fmt.State, v rune)

Format implements fmt.Formatter. It accepts the following formats:

d: raw integer (equivalent to ExactString())
s: rounded integer with unit suffix (equivalent to String())
v: same as s

func (Currency) IsZero

func (c Currency) IsZero() bool

IsZero returns true if c == 0.

func (Currency) MarshalJSON

func (c Currency) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Currency) Mul64

func (c Currency) Mul64(v uint64) Currency

Mul64 returns c*v. If the result would overflow, Mul64 panics.

Note that it is safe to multiply any two Currency values that are below 2^64.

func (Currency) String

func (c Currency) String() string

String returns base-10 representation of c with a unit suffix. The value may be rounded. To avoid loss of precision, use ExactString.

func (Currency) Sub

func (c Currency) Sub(v Currency) Currency

Sub returns c-v. If the result would underflow, Sub panics.

func (Currency) SubWithUnderflow

func (c Currency) SubWithUnderflow(v Currency) (Currency, bool)

SubWithUnderflow returns c-v, along with a boolean indicating whether the result underflowed.

func (*Currency) UnmarshalJSON

func (c *Currency) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

type Decoder

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

A Decoder reads values from an underlying stream. Callers MUST check (*Decoder).Err before using any decoded values.

func NewBufDecoder

func NewBufDecoder(buf []byte) *Decoder

NewBufDecoder returns a Decoder for the provided byte slice.

func NewDecoder

func NewDecoder(lr io.LimitedReader) *Decoder

NewDecoder returns a Decoder that wraps the provided stream.

func (*Decoder) Err

func (d *Decoder) Err() error

Err returns the first error encountered during decoding.

func (*Decoder) Read

func (d *Decoder) Read(p []byte) (int, error)

Read implements the io.Reader interface. It always returns an error if fewer than len(p) bytes were read.

func (*Decoder) ReadBool

func (d *Decoder) ReadBool() bool

ReadBool reads a bool value from the underlying stream.

func (*Decoder) ReadBytes

func (d *Decoder) ReadBytes() []byte

ReadBytes reads a length-prefixed []byte from the underlying stream.

func (*Decoder) ReadPrefix

func (d *Decoder) ReadPrefix() int

ReadPrefix reads a length prefix from the underlying stream. If the length exceeds the number of bytes remaining in the stream, ReadPrefix sets d.Err and returns 0.

func (*Decoder) ReadString

func (d *Decoder) ReadString() string

ReadString reads a length-prefixed string from the underlying stream.

func (*Decoder) ReadTime

func (d *Decoder) ReadTime() time.Time

ReadTime reads a time.Time from the underlying stream.

func (*Decoder) ReadUint64

func (d *Decoder) ReadUint64() uint64

ReadUint64 reads a uint64 value from the underlying stream.

func (*Decoder) ReadUint8

func (d *Decoder) ReadUint8() uint8

ReadUint8 reads a uint8 value from the underlying stream.

func (*Decoder) SetErr

func (d *Decoder) SetErr(err error)

SetErr sets the Decoder's error if it has not already been set. SetErr should only be called from DecodeFrom methods.

type DecoderFrom

type DecoderFrom interface {
	DecodeFrom(d *Decoder)
}

A DecoderFrom can decode itself from a stream via a Decoder.

type ElementID

type ElementID struct {
	Source Hash256 // BlockID or TransactionID
	Index  uint64
}

An ElementID uniquely identifies a StateElement.

func (*ElementID) DecodeFrom

func (id *ElementID) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (ElementID) EncodeTo

func (id ElementID) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (ElementID) MarshalText

func (eid ElementID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (ElementID) String

func (eid ElementID) String() string

String implements fmt.Stringer.

func (*ElementID) UnmarshalText

func (eid *ElementID) UnmarshalText(b []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

type Encoder

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

An Encoder writes objects to an underlying stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns an Encoder that wraps the provided stream.

func (*Encoder) Flush

func (e *Encoder) Flush() error

Flush writes any pending data to the underlying stream. It returns the first error encountered by the Encoder.

func (*Encoder) Write

func (e *Encoder) Write(p []byte) (int, error)

Write implements io.Writer.

func (*Encoder) WriteBool

func (e *Encoder) WriteBool(b bool)

WriteBool writes a bool value to the underlying stream.

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(b []byte)

WriteBytes writes a length-prefixed []byte to the underlying stream.

func (*Encoder) WritePrefix

func (e *Encoder) WritePrefix(i int)

WritePrefix writes a length prefix to the underlying stream.

func (*Encoder) WriteString

func (e *Encoder) WriteString(s string)

WriteString writes a length-prefixed string to the underlying stream.

func (*Encoder) WriteTime

func (e *Encoder) WriteTime(t time.Time)

WriteTime writes a time.Time value to the underlying stream.

func (*Encoder) WriteUint64

func (e *Encoder) WriteUint64(u uint64)

WriteUint64 writes a uint64 value to the underlying stream.

func (*Encoder) WriteUint8

func (e *Encoder) WriteUint8(u uint8)

WriteUint8 writes a uint8 value to the underlying stream.

type EncoderTo

type EncoderTo interface {
	EncodeTo(e *Encoder)
}

An EncoderTo can encode itself to a stream via an Encoder.

type Hash256

type Hash256 [32]byte

A Hash256 is a generic 256-bit cryptographic hash.

func HashBytes

func HashBytes(b []byte) Hash256

HashBytes computes the hash of b using sunyata's hash function.

func (*Hash256) DecodeFrom

func (h *Hash256) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Hash256) EncodeTo

func (h Hash256) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (Hash256) MarshalJSON

func (h Hash256) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Hash256) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Hash256) String

func (h Hash256) String() string

String implements fmt.Stringer.

func (*Hash256) UnmarshalJSON

func (h *Hash256) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Hash256) UnmarshalText

func (h *Hash256) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Hasher

type Hasher struct {
	E *Encoder
	// contains filtered or unexported fields
}

A Hasher streams objects into an instance of the sunyata hash function.

func NewHasher

func NewHasher() *Hasher

NewHasher returns a new Hasher instance.

func (*Hasher) Reset

func (h *Hasher) Reset()

Reset resets the underlying hash digest state.

func (*Hasher) Sum

func (h *Hasher) Sum() (sum Hash256)

Sum returns the digest of the objects written to the Hasher.

type Input

type Input struct {
	Parent    OutputElement
	PublicKey PublicKey
	Signature Signature
}

An Input spends its parent Output by revealing its public key and signing the transaction.

func (*Input) DecodeFrom

func (in *Input) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Input) EncodeTo

func (in Input) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

type Output

type Output struct {
	Value   Currency
	Address Address
}

An Output is a volume of currency that is created and spent as an atomic unit.

func (*Output) DecodeFrom

func (out *Output) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Output) EncodeTo

func (out Output) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

type OutputElement

type OutputElement struct {
	StateElement
	Output
	MaturityHeight uint64
}

An OutputElement is a volume of currency that is created and spent as an atomic unit.

func (*OutputElement) DecodeFrom

func (oe *OutputElement) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (OutputElement) EncodeTo

func (oe OutputElement) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

type PrivateKey

type PrivateKey []byte

A PrivateKey is an Ed25519 private key.

func GeneratePrivateKey

func GeneratePrivateKey() PrivateKey

GeneratePrivateKey creates a new private key from a secure entropy source.

func NewPrivateKeyFromSeed

func NewPrivateKeyFromSeed(seed []byte) PrivateKey

NewPrivateKeyFromSeed calculates a private key from a seed.

func (PrivateKey) PublicKey

func (priv PrivateKey) PublicKey() (pk PublicKey)

PublicKey returns the PublicKey corresponding to priv.

func (PrivateKey) SignHash

func (priv PrivateKey) SignHash(h Hash256) (s Signature)

SignHash signs h with priv, producing a Signature.

type PublicKey

type PublicKey [32]byte

A PublicKey is an Ed25519 public key.

func (PublicKey) Address

func (pk PublicKey) Address() Address

Address returns the address corresponding to a public key.

func (*PublicKey) DecodeFrom

func (pk *PublicKey) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (PublicKey) EncodeTo

func (pk PublicKey) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (PublicKey) MarshalJSON

func (pk PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (PublicKey) MarshalText

func (pk PublicKey) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (PublicKey) String

func (pk PublicKey) String() string

String implements fmt.Stringer.

func (*PublicKey) UnmarshalJSON

func (pk *PublicKey) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*PublicKey) UnmarshalText

func (pk *PublicKey) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (PublicKey) VerifyHash

func (pk PublicKey) VerifyHash(h Hash256, s Signature) bool

VerifyHash verifies that s is a valid signature of h by pk.

type Signature

type Signature [64]byte

A Signature is an Ed25519 signature.

func (*Signature) DecodeFrom

func (s *Signature) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Signature) EncodeTo

func (s Signature) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (Signature) MarshalJSON

func (sig Signature) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Signature) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Signature) String

func (sig Signature) String() string

String implements fmt.Stringer.

func (*Signature) UnmarshalJSON

func (sig *Signature) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Signature) UnmarshalText

func (sig *Signature) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type StateElement

type StateElement struct {
	ID          ElementID
	LeafIndex   uint64
	MerkleProof []Hash256
}

A StateElement is a generic element within the state accumulator.

func (*StateElement) DecodeFrom

func (se *StateElement) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (StateElement) EncodeTo

func (se StateElement) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

type Transaction

type Transaction struct {
	Inputs   []Input
	Outputs  []Output
	MinerFee Currency
}

A Transaction transfers value by consuming existing Outputs and creating new Outputs.

func (*Transaction) DecodeFrom

func (txn *Transaction) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (*Transaction) DeepCopy

func (txn *Transaction) DeepCopy() Transaction

DeepCopy returns a copy of txn that does not alias any of its memory.

func (Transaction) EncodeTo

func (txn Transaction) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (*Transaction) EphemeralOutputElement

func (txn *Transaction) EphemeralOutputElement(i int) OutputElement

EphemeralOutputElement returns txn.Outputs[i] as an ephemeral OutputElement.

func (*Transaction) ID

func (txn *Transaction) ID() TransactionID

ID returns the "semantic hash" of the transaction, covering all of the transaction's effects, but not incidental data such as signatures or Merkle proofs. This ensures that the ID will remain stable (i.e. non-malleable).

To hash all of the data in a transaction, use the EncodeTo method.

func (*Transaction) OutputID

func (txn *Transaction) OutputID(i int) ElementID

OutputID returns the ID of the output at index i.

type TransactionID

type TransactionID Hash256

A TransactionID uniquely identifies a transaction.

func (*TransactionID) DecodeFrom

func (id *TransactionID) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (TransactionID) EncodeTo

func (id TransactionID) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (TransactionID) MarshalJSON

func (tid TransactionID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (TransactionID) MarshalText

func (tid TransactionID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (TransactionID) String

func (tid TransactionID) String() string

String implements fmt.Stringer.

func (*TransactionID) UnmarshalJSON

func (tid *TransactionID) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*TransactionID) UnmarshalText

func (tid *TransactionID) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Work

type Work struct {
	// The representation is the expected number of hashes required to produce a
	// given hash, in big-endian order.
	NumHashes [32]byte
}

Work represents a quantity of work.

func WorkRequiredForHash

func WorkRequiredForHash(id BlockID) Work

WorkRequiredForHash estimates how much work was required to produce the given id. Note that the mapping is not injective; many different ids may require the same expected amount of Work.

func (Work) Add

func (w Work) Add(v Work) Work

Add returns w+v, wrapping on overflow.

func (Work) Cmp

func (w Work) Cmp(v Work) int

Cmp compares two work values.

func (*Work) DecodeFrom

func (w *Work) DecodeFrom(d *Decoder)

DecodeFrom implements sunyata.DecoderFrom.

func (Work) Div64

func (w Work) Div64(v uint64) Work

Div64 returns w/v.

func (Work) EncodeTo

func (w Work) EncodeTo(e *Encoder)

EncodeTo implements sunyata.EncoderTo.

func (Work) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Work) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Work) Mul64

func (w Work) Mul64(v uint64) Work

Mul64 returns w*v, wrapping on overflow.

func (Work) String

func (w Work) String() string

String implements fmt.Stringer.

func (Work) Sub

func (w Work) Sub(v Work) Work

Sub returns w-v, wrapping on underflow.

func (*Work) UnmarshalJSON

func (w *Work) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Work) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

Directories

Path Synopsis
Package consensus implements the sunyata consensus algorithms.
Package consensus implements the sunyata consensus algorithms.
internal
Package miner provides a basic miner for sunyata, suitable for testing and as a basis for more sophisticated implementations.
Package miner provides a basic miner for sunyata, suitable for testing and as a basis for more sophisticated implementations.

Jump to

Keyboard shortcuts

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