types

package
v2.0.0-...-ad76cac Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package types defines the essential types of the Sia blockchain.

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.

View Source
const MaxRevisionNumber = math.MaxUint64

MaxRevisionNumber is used to finalize a FileContract. When a contract's RevisionNumber is set to this value, no further revisions are possible. This allows contracts to be resolved "early" in some cases; see FileContractResolution.

Variables

This section is empty.

Functions

func CurrentTimestamp

func CurrentTimestamp() time.Time

CurrentTimestamp returns the current time, rounded to the nearest second. The time zone is set to UTC.

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 StandardAddress

func StandardAddress(pk PublicKey) Address

StandardAddress computes the address for a single public key policy.

func (*Address) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (Address) EncodeTo

func (a Address) EncodeTo(e *Encoder)

EncodeTo implements types.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 Attestation

type Attestation struct {
	PublicKey PublicKey
	Key       string
	Value     []byte
	Signature Signature
}

An Attestation associates a key-value pair with an identity. For example, hosts attest to their network address by setting Key to "HostAnnouncement" and Value to their address, thereby allowing renters to discover them. Generally, an attestation for a particular key is considered to overwrite any previous attestations with the same key. (This allows hosts to announce a new network address, for example.)

func (*Attestation) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (Attestation) EncodeTo

func (a Attestation) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type Block

type Block struct {
	Header       BlockHeader
	Transactions []Transaction
}

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

func (*Block) FoundationOutputID

func (b *Block) FoundationOutputID() ElementID

FoundationOutputID returns the output ID of the foundation payout. A Foundation subsidy output is only created every 4380 blocks after the hardfork at block 298000.

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 types.DecoderFrom.

func (BlockHeader) EncodeTo

func (h BlockHeader) EncodeTo(e *Encoder)

EncodeTo implements types.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 types.DecoderFrom.

func (BlockID) EncodeTo

func (id BlockID) EncodeTo(e *Encoder)

EncodeTo implements types.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 types.DecoderFrom.

func (ChainIndex) EncodeTo

func (index ChainIndex) EncodeTo(e *Encoder)

EncodeTo implements types.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 represents zero base units.
	ZeroCurrency Currency

	// HastingsPerSiacoin is the number of hastings (base units) in a siacoin.
	HastingsPerSiacoin = NewCurrency(2003764205206896640, 54210) // 10^24
)

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 Siacoins

func Siacoins(n uint32) Currency

Siacoins returns a Currency value representing n siacoins.

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 types.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 types.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 types.DecoderFrom.

func (ElementID) EncodeTo

func (id ElementID) EncodeTo(e *Encoder)

EncodeTo implements types.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 Sia 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 FileContract

type FileContract struct {
	Filesize        uint64
	FileMerkleRoot  Hash256
	WindowStart     uint64
	WindowEnd       uint64
	RenterOutput    SiacoinOutput
	HostOutput      SiacoinOutput
	MissedHostValue Currency
	TotalCollateral Currency
	RenterPublicKey PublicKey
	HostPublicKey   PublicKey
	RevisionNumber  uint64

	// signatures cover above fields
	RenterSignature Signature
	HostSignature   Signature
}

A FileContract is a storage agreement between a renter and a host. It consists of a bidirectional payment channel that resolves as either "valid" or "missed" depending on whether a valid StorageProof is submitted for the contract.

func (*FileContract) DecodeFrom

func (fc *FileContract) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (FileContract) EncodeTo

func (fc FileContract) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

func (FileContract) MissedHostOutput

func (fc FileContract) MissedHostOutput() SiacoinOutput

MissedHostOutput returns the host output that will be created if the contract resolves missed.

type FileContractElement

type FileContractElement struct {
	StateElement
	FileContract
}

A FileContractElement is a storage agreement between a renter and a host.

func (*FileContractElement) DecodeFrom

func (fce *FileContractElement) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (FileContractElement) EncodeTo

func (fce FileContractElement) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type FileContractRenewal

type FileContractRenewal struct {
	FinalRevision   FileContract
	InitialRevision FileContract
	RenterRollover  Currency
	HostRollover    Currency

	// signatures cover above fields
	RenterSignature Signature
	HostSignature   Signature
}

A FileContractRenewal renews a file contract.

func (*FileContractRenewal) DecodeFrom

func (ren *FileContractRenewal) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (FileContractRenewal) EncodeTo

func (ren FileContractRenewal) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type FileContractResolution

type FileContractResolution struct {
	Parent       FileContractElement
	Renewal      FileContractRenewal
	StorageProof StorageProof
	Finalization FileContract
}

A FileContractResolution closes a file contract's payment channel. There are four ways a contract can be resolved:

1) The renter and host can renew the contract. The old contract is finalized, and a portion of its funds are "rolled over" into a new contract.

2) The host can submit a valid storage proof within the contract's proof window. This is considered a "valid" resolution.

3) The renter and host can sign a final contract revision (a "finalization"), setting the contract's revision number to its maximum legal value. A finalization can be submitted at any time prior to the contract's WindowEnd. This is considered a "valid" resolution.

4) After the proof window has expired, anyone can submit an empty resolution with no storage proof or finalization. This is considered a "missed" resolution.

func (*FileContractResolution) DecodeFrom

func (res *FileContractResolution) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (FileContractResolution) EncodeTo

func (res FileContractResolution) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

func (*FileContractResolution) HasFinalization

func (fcr *FileContractResolution) HasFinalization() bool

HasFinalization returns true if the resolution contains a finalization.

func (*FileContractResolution) HasRenewal

func (fcr *FileContractResolution) HasRenewal() bool

HasRenewal returns true if the resolution contains a renewal.

func (*FileContractResolution) HasStorageProof

func (fcr *FileContractResolution) HasStorageProof() bool

HasStorageProof returns true if the resolution contains a storage proof.

type FileContractRevision

type FileContractRevision struct {
	Parent   FileContractElement
	Revision FileContract
}

A FileContractRevision updates the state of an existing file contract.

func (*FileContractRevision) DecodeFrom

func (rev *FileContractRevision) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (FileContractRevision) EncodeTo

func (rev FileContractRevision) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

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 Sia's hash function.

func (*Hash256) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (Hash256) EncodeTo

func (h Hash256) EncodeTo(e *Encoder)

EncodeTo implements types.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 Sia's 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 PolicyTypeAbove

type PolicyTypeAbove uint64

PolicyTypeAbove requires the input to be spent above a given block height.

type PolicyTypePublicKey

type PolicyTypePublicKey PublicKey

PolicyTypePublicKey requires the input to be signed by a given key.

type PolicyTypeThreshold

type PolicyTypeThreshold struct {
	N  uint8
	Of []SpendPolicy
}

PolicyTypeThreshold requires at least N sub-policies to be satisfied.

type PolicyTypeUnlockConditions

type PolicyTypeUnlockConditions struct {
	Timelock           uint64
	PublicKeys         []PublicKey
	SignaturesRequired uint8
}

PolicyTypeUnlockConditions reproduces the requirements imposed by Sia's original "UnlockConditions" type. It exists for compatibility purposes and should not be used to construct new policies.

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) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (PublicKey) EncodeTo

func (pk PublicKey) EncodeTo(e *Encoder)

EncodeTo implements types.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 SiacoinElement

type SiacoinElement struct {
	StateElement
	SiacoinOutput
	MaturityHeight uint64
}

A SiacoinElement is a volume of siacoins that is created and spent as an atomic unit.

func (*SiacoinElement) DecodeFrom

func (sce *SiacoinElement) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (SiacoinElement) EncodeTo

func (sce SiacoinElement) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type SiacoinInput

type SiacoinInput struct {
	Parent      SiacoinElement
	SpendPolicy SpendPolicy
	Signatures  []Signature
}

A SiacoinInput spends an unspent SiacoinElement in the state accumulator by revealing its public key and signing the transaction.

func (*SiacoinInput) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (SiacoinInput) EncodeTo

func (in SiacoinInput) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type SiacoinOutput

type SiacoinOutput struct {
	Value   Currency
	Address Address
}

A SiacoinOutput is the recipient of some of the siacoins spent in a transaction.

func (*SiacoinOutput) DecodeFrom

func (sco *SiacoinOutput) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (SiacoinOutput) EncodeTo

func (sco SiacoinOutput) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type SiafundElement

type SiafundElement struct {
	StateElement
	SiafundOutput
	ClaimStart Currency // value of SiafundPool when element was created
}

A SiafundElement is a volume of siafunds that is created and spent as an atomic unit.

func (*SiafundElement) DecodeFrom

func (sfe *SiafundElement) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (SiafundElement) EncodeTo

func (sfe SiafundElement) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type SiafundInput

type SiafundInput struct {
	Parent       SiafundElement
	ClaimAddress Address
	SpendPolicy  SpendPolicy
	Signatures   []Signature
}

A SiafundInput spends an unspent SiafundElement in the state accumulator by revealing its public key and signing the transaction. Inputs also include a ClaimAddress, specifying the recipient of the siacoins that were earned by the SiafundElement.

func (*SiafundInput) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (SiafundInput) EncodeTo

func (in SiafundInput) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type SiafundOutput

type SiafundOutput struct {
	Value   uint64
	Address Address
}

A SiafundOutput is the recipient of some of the siafunds spent in a transaction.

func (*SiafundOutput) DecodeFrom

func (sfo *SiafundOutput) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (SiafundOutput) EncodeTo

func (sfo SiafundOutput) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type Signature

type Signature [64]byte

A Signature is an Ed25519 signature.

func (*Signature) DecodeFrom

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

DecodeFrom implements types.DecoderFrom.

func (Signature) EncodeTo

func (s Signature) EncodeTo(e *Encoder)

EncodeTo implements types.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 SpendPolicy

type SpendPolicy struct {
	Type interface {
		// contains filtered or unexported methods
	}
}

A SpendPolicy describes the conditions under which an input may be spent.

func AnyoneCanSpend

func AnyoneCanSpend() SpendPolicy

AnyoneCanSpend returns a policy that has no requirements.

func ParseSpendPolicy

func ParseSpendPolicy(s string) (SpendPolicy, error)

ParseSpendPolicy parses a spend policy from a string.

func PolicyAbove

func PolicyAbove(height uint64) SpendPolicy

PolicyAbove returns a policy that requires the input to be spent above a given block height.

func PolicyPublicKey

func PolicyPublicKey(pk PublicKey) SpendPolicy

PolicyPublicKey returns a policy that requires the input to be signed by a given key.

func PolicyThreshold

func PolicyThreshold(n uint8, of []SpendPolicy) SpendPolicy

PolicyThreshold returns a policy that requires at least N sub-policies to be satisfied.

func (SpendPolicy) Address

func (p SpendPolicy) Address() Address

Address computes the opaque address for a given policy.

func (*SpendPolicy) DecodeFrom

func (p *SpendPolicy) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (SpendPolicy) EncodeTo

func (p SpendPolicy) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

func (SpendPolicy) MarshalJSON

func (p SpendPolicy) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (SpendPolicy) MarshalText

func (p SpendPolicy) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (SpendPolicy) String

func (p SpendPolicy) String() string

String implements fmt.Stringer.

func (*SpendPolicy) UnmarshalJSON

func (p *SpendPolicy) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*SpendPolicy) UnmarshalText

func (p *SpendPolicy) UnmarshalText(b []byte) (err 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 types.DecoderFrom.

func (StateElement) EncodeTo

func (se StateElement) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type StorageProof

type StorageProof struct {
	// Selecting the leaf requires a source of unpredictable entropy; we use the
	// ID of the block at the start of the proof window. The StorageProof
	// includes this ID, and asserts its presence in the chain via a separate
	// Merkle proof.
	//
	// For convenience, WindowStart is a ChainIndex rather than a BlockID.
	// Consequently, WindowStart.Height MUST match the WindowStart field of the
	// contract's final revision; otherwise, the prover could use any
	// WindowStart, giving them control over the leaf index.
	WindowStart ChainIndex
	WindowProof []Hash256

	// The leaf is always 64 bytes, extended with zeros if necessary.
	Leaf  [64]byte
	Proof []Hash256
}

A StorageProof asserts the presence of a randomly-selected leaf within the Merkle tree of a FileContract's data.

func (*StorageProof) DecodeFrom

func (sp *StorageProof) DecodeFrom(d *Decoder)

DecodeFrom implements types.DecoderFrom.

func (StorageProof) EncodeTo

func (sp StorageProof) EncodeTo(e *Encoder)

EncodeTo implements types.EncoderTo.

type Transaction

type Transaction struct {
	SiacoinInputs           []SiacoinInput
	SiacoinOutputs          []SiacoinOutput
	SiafundInputs           []SiafundInput
	SiafundOutputs          []SiafundOutput
	FileContracts           []FileContract
	FileContractRevisions   []FileContractRevision
	FileContractResolutions []FileContractResolution
	Attestations            []Attestation
	ArbitraryData           []byte
	NewFoundationAddress    Address
	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 types.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 types.EncoderTo.

func (*Transaction) EphemeralSiacoinElement

func (txn *Transaction) EphemeralSiacoinElement(i int) SiacoinElement

EphemeralSiacoinElement returns txn.SiacoinOutputs[i] as an ephemeral SiacoinElement.

func (*Transaction) FileContractID

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

FileContractID returns the ID of the file contract at index i.

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) SiacoinOutputID

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

SiacoinOutputID returns the ID of the siacoin output at index i.

func (*Transaction) SiafundClaimOutputID

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

SiafundClaimOutputID returns the ID of the siacoin claim output for the siafund input at index i.

func (*Transaction) SiafundOutputID

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

SiafundOutputID returns the ID of the siafund 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 types.DecoderFrom.

func (TransactionID) EncodeTo

func (id TransactionID) EncodeTo(e *Encoder)

EncodeTo implements types.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 types.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 types.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.

Jump to

Keyboard shortcuts

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