Documentation ¶
Overview ¶
Package types defines the essential types of the Sia blockchain.
Index ¶
- Constants
- Variables
- func CurrentTimestamp() time.Time
- func DecodePtr[T any, TP interface{ ... }](d *Decoder, v **T)
- func DecodePtrCast[T interface{ ... }, TP interface{ ... }, V any](d *Decoder, p **V)
- func DecodeSlice[T any, DF interface{ ... }](d *Decoder, s *[]T)
- func DecodeSliceCast[V any, T any, VF interface{ ... }](d *Decoder, s *[]T)
- func DecodeSliceFn[T any](d *Decoder, s *[]T, fn func(*Decoder) T)
- func EncodePtr[T any, P interface{ ... }](e *Encoder, p P)
- func EncodePtrCast[V interface{ ... }, T any](e *Encoder, p *T)
- func EncodeSlice[T EncoderTo](e *Encoder, s []T)
- func EncodeSliceCast[V interface{ ... }, T any](e *Encoder, s []T)
- func EncodeSliceFn[T any](e *Encoder, s []T, fn func(*Encoder, T))
- type Address
- type Attestation
- type AttestationElement
- type AttestationID
- type Block
- type BlockHeader
- type BlockID
- func (bid BlockID) CmpWork(t BlockID) int
- func (id *BlockID) DecodeFrom(d *Decoder)
- func (id BlockID) EncodeTo(e *Encoder)
- func (bid BlockID) FoundationOutputID() SiacoinOutputID
- func (bid BlockID) MarshalText() ([]byte, error)
- func (bid BlockID) MinerOutputID(i int) SiacoinOutputID
- func (bid BlockID) String() string
- func (bid *BlockID) UnmarshalText(b []byte) error
- type ChainIndex
- func (index *ChainIndex) DecodeFrom(d *Decoder)
- func (index ChainIndex) EncodeTo(e *Encoder)
- func (ci ChainIndex) MarshalJSON() ([]byte, error)
- func (ci ChainIndex) MarshalText() ([]byte, error)
- func (ci ChainIndex) String() string
- func (ci *ChainIndex) UnmarshalJSON(b []byte) error
- func (ci *ChainIndex) UnmarshalText(b []byte) (err error)
- type ChainIndexElement
- type CoveredFields
- type Currency
- func (c Currency) Add(v Currency) Currency
- func (c Currency) AddWithOverflow(v Currency) (Currency, bool)
- func (c Currency) Big() *big.Int
- func (c Currency) Cmp(v Currency) int
- func (c Currency) Div(v Currency) Currency
- func (c Currency) Div64(v uint64) Currency
- func (c Currency) Equals(v Currency) bool
- func (c Currency) ExactString() string
- func (c Currency) Format(f fmt.State, v rune)
- func (c Currency) IsZero() bool
- func (c Currency) MarshalText() ([]byte, error)
- func (c Currency) Mul(v Currency) Currency
- func (c Currency) Mul64(v uint64) Currency
- func (c Currency) Mul64WithOverflow(v uint64) (Currency, bool)
- func (c Currency) MulWithOverflow(v Currency) (Currency, bool)
- func (c Currency) Siacoins() float64
- func (c Currency) String() string
- func (c Currency) Sub(v Currency) Currency
- func (c Currency) SubWithUnderflow(v Currency) (Currency, bool)
- func (c *Currency) UnmarshalText(b []byte) (err error)
- type Decoder
- func (d *Decoder) Err() error
- func (d *Decoder) Read(p []byte) (int, error)
- func (d *Decoder) ReadBool() bool
- func (d *Decoder) ReadBytes() []byte
- func (d *Decoder) ReadString() string
- func (d *Decoder) ReadTime() time.Time
- func (d *Decoder) ReadUint64() uint64
- func (d *Decoder) ReadUint8() uint8
- func (d *Decoder) SetErr(err error)
- type DecoderFrom
- type DecoderFunc
- type ElementID
- type Encoder
- func (e *Encoder) Flush() error
- func (e *Encoder) Reset(w io.Writer)
- func (e *Encoder) Write(p []byte) (int, error)
- func (e *Encoder) WriteBool(b bool)
- func (e *Encoder) WriteBytes(b []byte)
- func (e *Encoder) WriteString(s string)
- func (e *Encoder) WriteTime(t time.Time)
- func (e *Encoder) WriteUint64(u uint64)
- func (e *Encoder) WriteUint8(u uint8)
- type EncoderFunc
- type EncoderTo
- type FileContract
- func (fc *FileContract) DecodeFrom(d *Decoder)
- func (fc FileContract) EncodeTo(e *Encoder)
- func (fc *FileContract) EndHeight() uint64
- func (fc *FileContract) MissedHostOutput() SiacoinOutput
- func (fc *FileContract) MissedHostPayout() Currency
- func (fc *FileContract) MissedRenterOutput() SiacoinOutput
- func (fc *FileContract) MissedRenterPayout() Currency
- func (fc *FileContract) ValidHostOutput() SiacoinOutput
- func (fc *FileContract) ValidHostPayout() Currency
- func (fc *FileContract) ValidRenterOutput() SiacoinOutput
- func (fc *FileContract) ValidRenterPayout() Currency
- type FileContractElement
- type FileContractID
- func (id *FileContractID) DecodeFrom(d *Decoder)
- func (id FileContractID) EncodeTo(e *Encoder)
- func (fcid FileContractID) MarshalText() ([]byte, error)
- func (fcid FileContractID) MissedOutputID(i int) SiacoinOutputID
- func (fcid FileContractID) String() string
- func (fcid *FileContractID) UnmarshalText(b []byte) error
- func (fcid FileContractID) V2HostOutputID() SiacoinOutputID
- func (fcid FileContractID) V2RenewalID() FileContractID
- func (fcid FileContractID) V2RenterOutputID() SiacoinOutputID
- func (fcid FileContractID) ValidOutputID(i int) SiacoinOutputID
- type FileContractRevision
- type FoundationAddressUpdate
- type Hash256
- type Hasher
- type PolicyTypeAbove
- type PolicyTypeAfter
- type PolicyTypeHash
- type PolicyTypeOpaque
- type PolicyTypePublicKey
- type PolicyTypeThreshold
- type PolicyTypeUnlockConditions
- type PrivateKey
- type PublicKey
- func (pk *PublicKey) DecodeFrom(d *Decoder)
- func (pk PublicKey) EncodeTo(e *Encoder)
- func (pk PublicKey) MarshalText() ([]byte, error)
- func (pk PublicKey) String() string
- func (pk PublicKey) UnlockKey() UnlockKey
- func (pk *PublicKey) UnmarshalText(b []byte) error
- func (pk PublicKey) VerifyHash(h Hash256, s Signature) bool
- type SatisfiedPolicy
- type SiacoinElement
- type SiacoinInput
- type SiacoinOutput
- type SiacoinOutputID
- type SiafundElement
- type SiafundInput
- type SiafundOutput
- type SiafundOutputID
- func (sfoid SiafundOutputID) ClaimOutputID() SiacoinOutputID
- func (id *SiafundOutputID) DecodeFrom(d *Decoder)
- func (id SiafundOutputID) EncodeTo(e *Encoder)
- func (sfoid SiafundOutputID) MarshalText() ([]byte, error)
- func (sfoid SiafundOutputID) String() string
- func (sfoid *SiafundOutputID) UnmarshalText(b []byte) error
- func (sfoid SiafundOutputID) V2ClaimOutputID() SiacoinOutputID
- type Signature
- type Specifier
- type SpendPolicy
- func AnyoneCanSpend() SpendPolicy
- func ParseSpendPolicy(s string) (SpendPolicy, error)
- func PolicyAbove(height uint64) SpendPolicy
- func PolicyAfter(t time.Time) SpendPolicy
- func PolicyHash(h Hash256) SpendPolicy
- func PolicyOpaque(p SpendPolicy) SpendPolicy
- func PolicyPublicKey(pk PublicKey) SpendPolicy
- func PolicyThreshold(n uint8, of []SpendPolicy) SpendPolicy
- func (p SpendPolicy) Address() Address
- func (p *SpendPolicy) DecodeFrom(d *Decoder)
- func (p SpendPolicy) EncodeTo(e *Encoder)
- func (p SpendPolicy) MarshalJSON() ([]byte, error)
- func (p SpendPolicy) String() string
- func (p *SpendPolicy) UnmarshalJSON(b []byte) (err error)
- func (p SpendPolicy) Verify(height uint64, medianTimestamp time.Time, sigHash Hash256, sigs []Signature, ...) error
- type StateElement
- type StorageProof
- type Transaction
- func (txn *Transaction) DecodeFrom(d *Decoder)
- func (txn Transaction) EncodeTo(e *Encoder)
- func (txn *Transaction) FileContractID(i int) FileContractID
- func (txn *Transaction) FullHash() Hash256
- func (txn *Transaction) ID() TransactionID
- func (txn Transaction) MarshalJSON() ([]byte, error)
- func (txn *Transaction) SiacoinOutputID(i int) SiacoinOutputID
- func (txn *Transaction) SiafundClaimOutputID(i int) SiacoinOutputID
- func (txn *Transaction) SiafundOutputID(i int) SiafundOutputID
- func (txn *Transaction) TotalFees() Currency
- type TransactionID
- type TransactionSignature
- type UnlockConditions
- type UnlockKey
- type V1Block
- type V1Currency
- type V1SiacoinOutput
- type V1SiafundOutput
- type V2Block
- type V2BlockData
- type V2Currency
- type V2FileContract
- type V2FileContractElement
- type V2FileContractExpiration
- type V2FileContractRenewal
- type V2FileContractResolution
- type V2FileContractResolutionType
- type V2FileContractRevision
- type V2SiacoinInput
- type V2SiacoinOutput
- type V2SiafundInput
- type V2SiafundOutput
- type V2StorageProof
- type V2Transaction
- func (*V2Transaction) AttestationID(txid TransactionID, i int) AttestationID
- func (txn *V2Transaction) DecodeFrom(d *Decoder)
- func (txn *V2Transaction) DeepCopy() V2Transaction
- func (txn V2Transaction) EncodeTo(e *Encoder)
- func (txn *V2Transaction) EphemeralSiacoinOutput(i int) SiacoinElement
- func (txn *V2Transaction) EphemeralSiafundOutput(i int) SiafundElement
- func (txn *V2Transaction) FullHash() Hash256
- func (txn *V2Transaction) ID() TransactionID
- func (txn V2Transaction) MarshalJSON() ([]byte, error)
- func (*V2Transaction) SiacoinOutputID(txid TransactionID, i int) SiacoinOutputID
- func (*V2Transaction) SiafundOutputID(txid TransactionID, i int) SiafundOutputID
- func (*V2Transaction) V2FileContractID(txid TransactionID, i int) FileContractID
- type V2TransactionSemantics
- type V2TransactionsMultiproof
Constants ¶
const ( // MaxRevisionNumber is used to finalize a FileContract. When a contract's // RevisionNumber is set to this value, no further revisions are possible. MaxRevisionNumber = math.MaxUint64 // RenterContractIndex defines the index of the renter's output and public // key in a FileContract. RenterContractIndex = 0 // HostContractIndex defines the index of the host's output and public key in // a FileContract. HostContractIndex = 1 // UnassignedLeafIndex is a sentinel value used as the LeafIndex of // StateElements that have not been added to the accumulator yet. This is // necessary for constructing blocks sets where later transactions reference // elements created in earlier transactions. // // Most clients do not need to reference this value directly, and should // instead use the EphemeralSiacoinElement and EphemeralSiafundElement // functions to construct dependent transaction sets. UnassignedLeafIndex = 10101010101010101010 )
Variables ¶
var ( // ZeroCurrency represents zero base units. ZeroCurrency Currency // MaxCurrency represents the largest possible value for the Currency type. MaxCurrency = NewCurrency(math.MaxUint64, math.MaxUint64) // HastingsPerSiacoin is the number of hastings (base units) in a siacoin. HastingsPerSiacoin = NewCurrency(2003764205206896640, 54210) // 10^24 )
var ( SpecifierEd25519 = NewSpecifier("ed25519") SpecifierSiacoinOutput = NewSpecifier("siacoin output") SpecifierSiafundOutput = NewSpecifier("siafund output") SpecifierFileContract = NewSpecifier("file contract") SpecifierStorageProof = NewSpecifier("storage proof") SpecifierFoundation = NewSpecifier("foundation") SpecifierEntropy = NewSpecifier("entropy") )
Various specifiers.
Functions ¶
func CurrentTimestamp ¶
CurrentTimestamp returns the current time, rounded to the nearest second. The time zone is set to UTC.
func DecodePtr ¶
func DecodePtr[T any, TP interface { *T DecoderFrom }](d *Decoder, v **T)
DecodePtr decodes a pointer to an object that implements DecoderFrom.
func DecodePtrCast ¶
func DecodePtrCast[T interface { Cast() V }, TP interface { *T DecoderFrom }, V any](d *Decoder, p **V)
DecodePtrCast decodes a pointer to an object by casting it to V.
func DecodeSlice ¶
func DecodeSlice[T any, DF interface { *T DecoderFrom }](d *Decoder, s *[]T)
DecodeSlice decodes a length-prefixed slice of type T, containing values read from the decoder.
func DecodeSliceCast ¶
func DecodeSliceCast[V any, T any, VF interface { *V Cast() T DecoderFrom }](d *Decoder, s *[]T)
DecodeSliceCast decodes a length-prefixed slice of type T, casting through type V.
func DecodeSliceFn ¶
DecodeSliceFn decodes a length-prefixed slice of type T, calling an explicit function to decode each element.
func EncodePtrCast ¶
EncodePtrCast encodes a pointer to an object by casting it to V.
func EncodeSlice ¶
EncodeSlice encodes a slice of objects that implement EncoderTo.
func EncodeSliceCast ¶
EncodeSliceCast encodes a slice of objects by casting them to V.
func EncodeSliceFn ¶
EncodeSliceFn encodes a slice of objects by calling an explicit function to encode each element.
Types ¶
type Address ¶
type Address Hash256
An Address is the hash of a set of UnlockConditions.
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 ¶
ParseAddress parses an address from a prefixed hex encoded string.
func StandardAddress ¶
StandardAddress returns the standard v2 Address derived from pk. It is equivalent to PolicyPublicKey(pk).Address().
func StandardUnlockHash ¶
StandardUnlockHash returns the standard UnlockHash derived from pk. It is equivalent to SpendPolicy{PolicyUnlockConditions(StandardUnlockConditions(pk))}.Address().
func (*Address) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Address) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Address) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Attestation ¶
type Attestation struct { PublicKey PublicKey `json:"publicKey"` Key string `json:"key"` Value []byte `json:"value"` Signature Signature `json:"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 AttestationElement ¶
type AttestationElement struct { ID AttestationID `json:"id"` StateElement StateElement `json:"stateElement"` Attestation Attestation `json:"attestation"` }
An AttestationElement is a record of an Attestation within the state accumulator.
type AttestationID ¶
type AttestationID Hash256
An AttestationID uniquely identifies an attestation.
func (*AttestationID) DecodeFrom ¶
func (id *AttestationID) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (AttestationID) EncodeTo ¶
func (id AttestationID) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (AttestationID) MarshalText ¶
func (aid AttestationID) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (AttestationID) String ¶
func (aid AttestationID) String() string
String implements fmt.Stringer.
func (*AttestationID) UnmarshalText ¶
func (aid *AttestationID) UnmarshalText(b []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type Block ¶
type Block struct { ParentID BlockID `json:"parentID"` Nonce uint64 `json:"nonce"` Timestamp time.Time `json:"timestamp"` MinerPayouts []SiacoinOutput `json:"minerPayouts"` Transactions []Transaction `json:"transactions"` V2 *V2BlockData `json:"v2,omitempty"` }
A Block is a timestamped set of transactions, immutably linked to a previous block, secured by proof-of-work.
func (*Block) V2Transactions ¶
func (b *Block) V2Transactions() []V2Transaction
V2Transactions returns the block's v2 transactions, if present.
type BlockHeader ¶
type BlockHeader struct { ParentID BlockID `json:"parentID"` Nonce uint64 `json:"nonce"` Timestamp time.Time `json:"timestamp"` Commitment Hash256 `json:"commitment"` }
A BlockHeader is the preimage of a Block's ID.
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.
type BlockID ¶
type BlockID Hash256
A BlockID uniquely identifies a block.
func (*BlockID) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (BlockID) FoundationOutputID ¶
func (bid BlockID) FoundationOutputID() SiacoinOutputID
FoundationOutputID returns the ID of the block's Foundation subsidy.
func (BlockID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (BlockID) MinerOutputID ¶
func (bid BlockID) MinerOutputID(i int) SiacoinOutputID
MinerOutputID returns the ID of the block's i'th miner payout.
func (*BlockID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type ChainIndex ¶
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) MarshalJSON ¶
func (ci ChainIndex) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (ChainIndex) MarshalText ¶
func (ci ChainIndex) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*ChainIndex) UnmarshalJSON ¶
func (ci *ChainIndex) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*ChainIndex) UnmarshalText ¶
func (ci *ChainIndex) UnmarshalText(b []byte) (err error)
UnmarshalText implements encoding.TextUnmarshaler.
type ChainIndexElement ¶
type ChainIndexElement struct { ID BlockID `json:"id"` StateElement StateElement `json:"stateElement"` ChainIndex ChainIndex `json:"chainIndex"` }
A ChainIndexElement is a record of a ChainIndex within the state accumulator.
func (*ChainIndexElement) DecodeFrom ¶
func (cie *ChainIndexElement) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (ChainIndexElement) EncodeTo ¶
func (cie ChainIndexElement) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type CoveredFields ¶
type CoveredFields struct { WholeTransaction bool `json:"wholeTransaction,omitempty"` SiacoinInputs []uint64 `json:"siacoinInputs,omitempty"` SiacoinOutputs []uint64 `json:"siacoinOutputs,omitempty"` FileContracts []uint64 `json:"fileContracts,omitempty"` FileContractRevisions []uint64 `json:"fileContractRevisions,omitempty"` StorageProofs []uint64 `json:"storageProofs,omitempty"` SiafundInputs []uint64 `json:"siafundInputs,omitempty"` SiafundOutputs []uint64 `json:"siafundOutputs,omitempty"` MinerFees []uint64 `json:"minerFees,omitempty"` ArbitraryData []uint64 `json:"arbitraryData,omitempty"` Signatures []uint64 `json:"signatures,omitempty"` }
CoveredFields indicates which fields of a transaction are covered by a signature.
func (*CoveredFields) DecodeFrom ¶
func (cf *CoveredFields) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (CoveredFields) EncodeTo ¶
func (cf CoveredFields) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type Currency ¶
type Currency struct {
Lo, Hi uint64
}
Currency represents a quantity of hastings as an unsigned 128-bit number.
func NewCurrency ¶
NewCurrency returns the Currency value (lo,hi).
func NewCurrency64 ¶
NewCurrency64 converts c to a Currency value.
func ParseCurrency ¶
ParseCurrency parses s as a Currency value. The format of s should match one of the representations provided by (Currency).Format.
func (Currency) Add ¶
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 ¶
AddWithOverflow returns c+v, along with a boolean indicating whether the result overflowed.
func (Currency) Equals ¶
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 ¶
ExactString returns the base-10 representation of c as a string.
func (Currency) Format ¶
Format implements fmt.Formatter. It accepts the following formats:
s, v: decimal with unit suffix (equivalent to String()) b, d, o, O, x, X: raw integer, formatted via c.Big().Format
func (Currency) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Currency) Mul ¶
Mul returns c*v. If the result would overflow, Mul panics.
Note that it is safe to multiply any two Currency values that are below 2^64.
func (Currency) Mul64 ¶
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) Mul64WithOverflow ¶
Mul64WithOverflow returns c*v along with a boolean indicating whether the result overflowed.
Note that it is safe to multiply any two Currency values that are below 2^64.
func (Currency) MulWithOverflow ¶
MulWithOverflow returns c*v, along with a boolean indicating whether the result overflowed.
Note that it is safe to multiply any two Currency values that are below 2^64.
func (Currency) Siacoins ¶
Siacoins converts c to a floating-point number of siacoins. This may result in a loss of precision.
func (Currency) SubWithUnderflow ¶
SubWithUnderflow returns c-v, along with a boolean indicating whether the result underflowed.
func (*Currency) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
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 ¶
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) Read ¶
Read implements the io.Reader interface. It always returns an error if fewer than len(p) bytes were read.
func (*Decoder) ReadString ¶
ReadString reads a length-prefixed string from the underlying stream.
func (*Decoder) ReadUint64 ¶
ReadUint64 reads a uint64 value from the underlying stream.
type DecoderFrom ¶
type DecoderFrom interface {
DecodeFrom(d *Decoder)
}
A DecoderFrom can decode itself from a stream via a Decoder.
type DecoderFunc ¶
type DecoderFunc func(*Decoder)
DecoderFunc implements types.DecoderTo with a function.
func (DecoderFunc) DecodeFrom ¶
func (fn DecoderFunc) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderTo.
type ElementID ¶
type ElementID = [32]byte
An ElementID identifies a generic element within the state accumulator. In practice, it may be a BlockID, SiacoinOutputID, SiafundOutputID, FileContractID, or AttestationID.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes Sia objects to an underlying stream.
func NewEncoder ¶
NewEncoder returns an Encoder that wraps the provided stream.
func (*Encoder) Flush ¶
Flush writes any pending data to the underlying stream. It returns the first error encountered by the Encoder.
func (*Encoder) Reset ¶
Reset resets the Encoder to write to w. Any unflushed data, along with any error previously encountered, is discarded.
func (*Encoder) WriteBytes ¶
WriteBytes writes a length-prefixed []byte to the underlying stream.
func (*Encoder) WriteString ¶
WriteString writes a length-prefixed string to the underlying stream.
func (*Encoder) WriteUint64 ¶
WriteUint64 writes a uint64 value to the underlying stream.
func (*Encoder) WriteUint8 ¶
WriteUint8 writes a uint8 value to the underlying stream.
type EncoderFunc ¶
type EncoderFunc func(*Encoder)
EncoderFunc implements types.EncoderTo with a function.
func (EncoderFunc) EncodeTo ¶
func (fn EncoderFunc) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
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 `json:"filesize"` FileMerkleRoot Hash256 `json:"fileMerkleRoot"` WindowStart uint64 `json:"windowStart"` WindowEnd uint64 `json:"windowEnd"` Payout Currency `json:"payout"` ValidProofOutputs []SiacoinOutput `json:"validProofOutputs"` MissedProofOutputs []SiacoinOutput `json:"missedProofOutputs"` UnlockHash Address `json:"unlockHash"` RevisionNumber uint64 `json:"revisionNumber"` }
A FileContract is a storage agreement between a renter and a host. It contains 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) EndHeight ¶
func (fc *FileContract) EndHeight() uint64
EndHeight returns the height at which the contract's host is no longer obligated to store the contract data.
func (*FileContract) MissedHostOutput ¶
func (fc *FileContract) MissedHostOutput() SiacoinOutput
MissedHostOutput returns the output that will be created for the host if the contract resolves missed.
func (*FileContract) MissedHostPayout ¶
func (fc *FileContract) MissedHostPayout() Currency
MissedHostPayout returns the amount of siacoins that the host will receive if the contract resolves missed.
func (*FileContract) MissedRenterOutput ¶
func (fc *FileContract) MissedRenterOutput() SiacoinOutput
MissedRenterOutput returns the output that will be created for the renter if the contract resolves missed.
func (*FileContract) MissedRenterPayout ¶
func (fc *FileContract) MissedRenterPayout() Currency
MissedRenterPayout returns the amount of siacoins that the renter will receive if the contract resolves missed.
func (*FileContract) ValidHostOutput ¶
func (fc *FileContract) ValidHostOutput() SiacoinOutput
ValidHostOutput returns the output that will be created for the host if the contract resolves valid.
func (*FileContract) ValidHostPayout ¶
func (fc *FileContract) ValidHostPayout() Currency
ValidHostPayout returns the amount of siacoins that the host will receive if the contract resolves valid.
func (*FileContract) ValidRenterOutput ¶
func (fc *FileContract) ValidRenterOutput() SiacoinOutput
ValidRenterOutput returns the output that will be created for the renter if the contract resolves valid.
func (*FileContract) ValidRenterPayout ¶
func (fc *FileContract) ValidRenterPayout() Currency
ValidRenterPayout returns the amount of siacoins that the renter will receive if the contract resolves valid.
type FileContractElement ¶
type FileContractElement struct { ID FileContractID `json:"id"` StateElement StateElement `json:"stateElement"` FileContract FileContract `json:"fileContract"` }
A FileContractElement is a record of a FileContract within the state accumulator.
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 FileContractID ¶
type FileContractID Hash256
A FileContractID uniquely identifies a file contract.
func (*FileContractID) DecodeFrom ¶
func (id *FileContractID) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (FileContractID) EncodeTo ¶
func (id FileContractID) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (FileContractID) MarshalText ¶
func (fcid FileContractID) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (FileContractID) MissedOutputID ¶
func (fcid FileContractID) MissedOutputID(i int) SiacoinOutputID
MissedOutputID returns the ID of the missed proof output at index i.
func (FileContractID) String ¶
func (fcid FileContractID) String() string
String implements fmt.Stringer.
func (*FileContractID) UnmarshalText ¶
func (fcid *FileContractID) UnmarshalText(b []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
func (FileContractID) V2HostOutputID ¶
func (fcid FileContractID) V2HostOutputID() SiacoinOutputID
V2HostOutputID returns the ID of the host output for a v2 contract.
func (FileContractID) V2RenewalID ¶
func (fcid FileContractID) V2RenewalID() FileContractID
V2RenewalID returns the ID of the renewal of a v2 contract.
func (FileContractID) V2RenterOutputID ¶
func (fcid FileContractID) V2RenterOutputID() SiacoinOutputID
V2RenterOutputID returns the ID of the renter output for a v2 contract.
func (FileContractID) ValidOutputID ¶
func (fcid FileContractID) ValidOutputID(i int) SiacoinOutputID
ValidOutputID returns the ID of the valid proof output at index i.
type FileContractRevision ¶
type FileContractRevision struct { ParentID FileContractID `json:"parentID"` UnlockConditions UnlockConditions `json:"unlockConditions"` // NOTE: the Payout field of the contract is not "really" part of a // revision. A revision cannot change the total payout, so the original siad // code defines FileContractRevision as an entirely separate struct without // a Payout field. Here, we instead reuse the FileContract type, which means // we must treat its Payout field as invalid. To guard against developer // error, we set it to a sentinel value when decoding it. 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.
func (FileContractRevision) MarshalJSON ¶
func (fcr FileContractRevision) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*FileContractRevision) UnmarshalJSON ¶
func (fcr *FileContractRevision) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type FoundationAddressUpdate ¶
type FoundationAddressUpdate struct { NewPrimary Address `json:"newPrimary"` NewFailsafe Address `json:"newFailsafe"` }
A FoundationAddressUpdate updates the primary and failsafe Foundation subsidy addresses.
func (*FoundationAddressUpdate) DecodeFrom ¶
func (fau *FoundationAddressUpdate) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (FoundationAddressUpdate) EncodeTo ¶
func (fau FoundationAddressUpdate) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type Hash256 ¶
type Hash256 [32]byte
A Hash256 is a generic 256-bit cryptographic hash.
func (*Hash256) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Hash256) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Hash256) UnmarshalText ¶
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 (*Hasher) WriteDistinguisher ¶
WriteDistinguisher writes a distinguisher prefix to the encoder.
type PolicyTypeAbove ¶
type PolicyTypeAbove uint64
PolicyTypeAbove requires the input to be spent above a given block height.
type PolicyTypeAfter ¶
PolicyTypeAfter requires the input to be spent after a given timestamp.
type PolicyTypeHash ¶
type PolicyTypeHash Hash256
PolicyTypeHash requires the input to reveal a SHA256 hash preimage.
type PolicyTypeOpaque ¶
type PolicyTypeOpaque Address
PolicyTypeOpaque is the opaque hash of a policy. It is not satisfiable.
type PolicyTypePublicKey ¶
type PolicyTypePublicKey PublicKey
PolicyTypePublicKey requires the input to be signed by a given key.
type PolicyTypeThreshold ¶
type PolicyTypeThreshold struct { N uint8 `json:"n"` Of []SpendPolicy `json:"of"` }
PolicyTypeThreshold requires at least N sub-policies to be satisfied.
type PolicyTypeUnlockConditions ¶
type PolicyTypeUnlockConditions UnlockConditions
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 ¶
DecodeFrom implements types.DecoderFrom.
func (PublicKey) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*PublicKey) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type SatisfiedPolicy ¶
type SatisfiedPolicy struct { Policy SpendPolicy Signatures []Signature Preimages [][32]byte }
A SatisfiedPolicy pairs a policy with the signatures and preimages that satisfy it.
func (*SatisfiedPolicy) DecodeFrom ¶
func (sp *SatisfiedPolicy) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (SatisfiedPolicy) EncodeTo ¶
func (sp SatisfiedPolicy) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (SatisfiedPolicy) MarshalJSON ¶
func (sp SatisfiedPolicy) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*SatisfiedPolicy) UnmarshalJSON ¶
func (sp *SatisfiedPolicy) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type SiacoinElement ¶
type SiacoinElement struct { ID SiacoinOutputID `json:"id"` StateElement StateElement `json:"stateElement"` SiacoinOutput SiacoinOutput `json:"siacoinOutput"` MaturityHeight uint64 `json:"maturityHeight"` }
A SiacoinElement is a record of a SiacoinOutput within the state accumulator.
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 { ParentID SiacoinOutputID `json:"parentID"` UnlockConditions UnlockConditions `json:"unlockConditions"` }
A SiacoinInput spends an unspent SiacoinOutput in the UTXO set by revealing and satisfying its unlock conditions.
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 ¶
A SiacoinOutput is the recipient of some of the siacoins spent in a transaction.
type SiacoinOutputID ¶
type SiacoinOutputID Hash256
A SiacoinOutputID uniquely identifies a siacoin output.
func (*SiacoinOutputID) DecodeFrom ¶
func (id *SiacoinOutputID) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (SiacoinOutputID) EncodeTo ¶
func (id SiacoinOutputID) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (SiacoinOutputID) MarshalText ¶
func (scoid SiacoinOutputID) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (SiacoinOutputID) String ¶
func (scoid SiacoinOutputID) String() string
String implements fmt.Stringer.
func (*SiacoinOutputID) UnmarshalText ¶
func (scoid *SiacoinOutputID) UnmarshalText(b []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type SiafundElement ¶
type SiafundElement struct { ID SiafundOutputID `json:"id"` StateElement StateElement `json:"stateElement"` SiafundOutput SiafundOutput `json:"siafundOutput"` ClaimStart Currency `json:"claimStart"` // value of SiafundTaxRevenue when element was created }
A SiafundElement is a record of a SiafundOutput within the state accumulator.
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 { ParentID SiafundOutputID `json:"parentID"` UnlockConditions UnlockConditions `json:"unlockConditions"` ClaimAddress Address `json:"claimAddress"` }
A SiafundInput spends an unspent SiafundOutput in the UTXO set by revealing and satisfying its unlock conditions. SiafundInputs also include a ClaimAddress, specifying the recipient of the siacoins that were earned by the output.
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 ¶
A SiafundOutput is the recipient of some of the siafunds spent in a transaction.
type SiafundOutputID ¶
type SiafundOutputID Hash256
A SiafundOutputID uniquely identifies a siafund output.
func (SiafundOutputID) ClaimOutputID ¶
func (sfoid SiafundOutputID) ClaimOutputID() SiacoinOutputID
ClaimOutputID returns the ID of the SiacoinOutput that is created when the siafund output is spent.
func (*SiafundOutputID) DecodeFrom ¶
func (id *SiafundOutputID) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (SiafundOutputID) EncodeTo ¶
func (id SiafundOutputID) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (SiafundOutputID) MarshalText ¶
func (sfoid SiafundOutputID) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (SiafundOutputID) String ¶
func (sfoid SiafundOutputID) String() string
String implements fmt.Stringer.
func (*SiafundOutputID) UnmarshalText ¶
func (sfoid *SiafundOutputID) UnmarshalText(b []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
func (SiafundOutputID) V2ClaimOutputID ¶
func (sfoid SiafundOutputID) V2ClaimOutputID() SiacoinOutputID
V2ClaimOutputID returns the ID of the SiacoinOutput that is created when the siafund output is spent.
type Signature ¶
type Signature [64]byte
A Signature is an Ed25519 signature.
func (*Signature) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Signature) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Signature) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Specifier ¶
type Specifier [16]byte
A Specifier is a fixed-size, 0-padded identifier.
func NewSpecifier ¶
NewSpecifier returns a specifier containing the provided name.
func (*Specifier) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Specifier) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Specifier) UnmarshalText ¶
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 PolicyAfter ¶
func PolicyAfter(t time.Time) SpendPolicy
PolicyAfter returns a policy that requires the input to be spent after a given timestamp.
func PolicyHash ¶
func PolicyHash(h Hash256) SpendPolicy
PolicyHash returns a policy that requires the input to reveal a SHA256 hash preimage.
func PolicyOpaque ¶
func PolicyOpaque(p SpendPolicy) SpendPolicy
PolicyOpaque returns a policy with the same address as p, but without its semantics.
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. When satisfying a threshold policy, all unsatisfied sub-policies must be replaced with PolicyOpaque.
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) UnmarshalJSON ¶
func (p *SpendPolicy) UnmarshalJSON(b []byte) (err error)
UnmarshalJSON implements json.Unmarshaler.
type StateElement ¶
type StateElement struct { LeafIndex uint64 `json:"leafIndex"` MerkleProof []Hash256 `json:"merkleProof,omitempty"` }
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 { ParentID FileContractID 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.
func (StorageProof) MarshalJSON ¶
func (sp StorageProof) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*StorageProof) UnmarshalJSON ¶
func (sp *StorageProof) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Transaction ¶
type Transaction struct { SiacoinInputs []SiacoinInput `json:"siacoinInputs,omitempty"` SiacoinOutputs []SiacoinOutput `json:"siacoinOutputs,omitempty"` FileContracts []FileContract `json:"fileContracts,omitempty"` FileContractRevisions []FileContractRevision `json:"fileContractRevisions,omitempty"` StorageProofs []StorageProof `json:"storageProofs,omitempty"` SiafundInputs []SiafundInput `json:"siafundInputs,omitempty"` SiafundOutputs []SiafundOutput `json:"siafundOutputs,omitempty"` MinerFees []Currency `json:"minerFees,omitempty"` ArbitraryData [][]byte `json:"arbitraryData,omitempty"` Signatures []TransactionSignature `json:"signatures,omitempty"` }
A Transaction effects a change of blockchain state.
func (*Transaction) DecodeFrom ¶
func (txn *Transaction) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (Transaction) EncodeTo ¶
func (txn Transaction) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (*Transaction) FileContractID ¶
func (txn *Transaction) FileContractID(i int) FileContractID
FileContractID returns the ID of the file contract at index i.
func (*Transaction) FullHash ¶
func (txn *Transaction) FullHash() Hash256
FullHash returns the hash of the transaction's binary encoding. This hash is only used in specific circumstances; generally, ID should be used instead.
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. This ensures that the ID will remain stable (i.e. non-malleable).
To hash all of the data in a transaction, use the FullHash method.
func (Transaction) MarshalJSON ¶
func (txn Transaction) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaller.
For convenience, the transaction's ID is also calculated and included. This field is ignored during unmarshalling.
func (*Transaction) SiacoinOutputID ¶
func (txn *Transaction) SiacoinOutputID(i int) SiacoinOutputID
SiacoinOutputID returns the ID of the siacoin output at index i.
func (*Transaction) SiafundClaimOutputID ¶
func (txn *Transaction) SiafundClaimOutputID(i int) SiacoinOutputID
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) SiafundOutputID
SiafundOutputID returns the ID of the siafund output at index i.
func (*Transaction) TotalFees ¶
func (txn *Transaction) TotalFees() Currency
TotalFees returns the sum of the transaction's miner fees. If the sum would overflow, TotalFees returns ZeroCurrency.
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) 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) UnmarshalText ¶
func (tid *TransactionID) UnmarshalText(b []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type TransactionSignature ¶
type TransactionSignature struct { ParentID Hash256 `json:"parentID"` PublicKeyIndex uint64 `json:"publicKeyIndex"` Timelock uint64 `json:"timelock,omitempty"` CoveredFields CoveredFields `json:"coveredFields"` Signature []byte `json:"signature"` }
A TransactionSignature signs transaction data.
func (*TransactionSignature) DecodeFrom ¶
func (ts *TransactionSignature) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (TransactionSignature) EncodeTo ¶
func (ts TransactionSignature) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type UnlockConditions ¶
type UnlockConditions struct { Timelock uint64 `json:"timelock"` PublicKeys []UnlockKey `json:"publicKeys"` SignaturesRequired uint64 `json:"signaturesRequired"` }
UnlockConditions specify the conditions for spending an output or revising a file contract.
func StandardUnlockConditions ¶
func StandardUnlockConditions(pk PublicKey) UnlockConditions
StandardUnlockConditions returns the standard unlock conditions for pk.
func (*UnlockConditions) DecodeFrom ¶
func (uc *UnlockConditions) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (UnlockConditions) EncodeTo ¶
func (uc UnlockConditions) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (UnlockConditions) UnlockHash ¶
func (uc UnlockConditions) UnlockHash() Address
UnlockHash computes the hash of a set of UnlockConditions. Such hashes are most commonly used as addresses, but are also used in file contracts.
type UnlockKey ¶
An UnlockKey can provide one of the signatures required by a set of UnlockConditions.
func (*UnlockKey) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (UnlockKey) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*UnlockKey) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type V1Block ¶
type V1Block Block
V1Block provides v1 encoding for Block.
func (*V1Block) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
type V1Currency ¶
type V1Currency Currency
V1Currency provides v1 encoding for Currency.
func (V1Currency) Cast ¶
func (c V1Currency) Cast() Currency
Cast provides type safety for DecodeSliceCast.
func (*V1Currency) DecodeFrom ¶
func (c *V1Currency) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V1Currency) EncodeTo ¶
func (c V1Currency) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V1SiacoinOutput ¶
type V1SiacoinOutput SiacoinOutput
V1SiacoinOutput provides v1 encoding for SiacoinOutput.
func (V1SiacoinOutput) Cast ¶
func (sco V1SiacoinOutput) Cast() SiacoinOutput
Cast provides type safety for DecodeSliceCast.
func (*V1SiacoinOutput) DecodeFrom ¶
func (sco *V1SiacoinOutput) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V1SiacoinOutput) EncodeTo ¶
func (sco V1SiacoinOutput) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V1SiafundOutput ¶
type V1SiafundOutput SiafundOutput
V1SiafundOutput provides v1 encoding for SiafundOutput.
func (V1SiafundOutput) Cast ¶
func (sfo V1SiafundOutput) Cast() SiafundOutput
Cast provides type safety for DecodeSliceCast.
func (*V1SiafundOutput) DecodeFrom ¶
func (sfo *V1SiafundOutput) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V1SiafundOutput) EncodeTo ¶
func (sfo V1SiafundOutput) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2Block ¶
type V2Block Block
V2Block provides v2 encoding for Block.
func (*V2Block) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
type V2BlockData ¶
type V2BlockData struct { Height uint64 `json:"height"` Commitment Hash256 `json:"commitment"` Transactions []V2Transaction `json:"transactions"` }
V2BlockData contains additional fields not present in v1 blocks.
func (*V2BlockData) DecodeFrom ¶
func (b *V2BlockData) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2BlockData) EncodeTo ¶
func (b V2BlockData) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2Currency ¶
type V2Currency Currency
V2Currency provides v2 encoding for Currency.
func (V2Currency) Cast ¶
func (c V2Currency) Cast() Currency
Cast provides type safety for DecodeSliceCast.
func (*V2Currency) DecodeFrom ¶
func (c *V2Currency) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2Currency) EncodeTo ¶
func (c V2Currency) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2FileContract ¶
type V2FileContract struct { Capacity uint64 `json:"capacity"` Filesize uint64 `json:"filesize"` FileMerkleRoot Hash256 `json:"fileMerkleRoot"` ProofHeight uint64 `json:"proofHeight"` ExpirationHeight uint64 `json:"expirationHeight"` RenterOutput SiacoinOutput `json:"renterOutput"` HostOutput SiacoinOutput `json:"hostOutput"` MissedHostValue Currency `json:"missedHostValue"` TotalCollateral Currency `json:"totalCollateral"` RenterPublicKey PublicKey `json:"renterPublicKey"` HostPublicKey PublicKey `json:"hostPublicKey"` RevisionNumber uint64 `json:"revisionNumber"` // signatures cover above fields RenterSignature Signature `json:"renterSignature"` HostSignature Signature `json:"hostSignature"` }
A V2FileContract 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 (*V2FileContract) DecodeFrom ¶
func (fc *V2FileContract) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2FileContract) EncodeTo ¶
func (fc V2FileContract) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (V2FileContract) MissedHostOutput ¶
func (fc V2FileContract) MissedHostOutput() SiacoinOutput
MissedHostOutput returns the host output that will be created if the contract resolves missed.
type V2FileContractElement ¶
type V2FileContractElement struct { ID FileContractID `json:"id"` StateElement StateElement `json:"stateElement"` V2FileContract V2FileContract `json:"v2FileContract"` }
A V2FileContractElement is a record of a V2FileContract within the state accumulator.
func (*V2FileContractElement) DecodeFrom ¶
func (fce *V2FileContractElement) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2FileContractElement) EncodeTo ¶
func (fce V2FileContractElement) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2FileContractExpiration ¶
type V2FileContractExpiration struct{}
A V2FileContractExpiration resolves an expired contract. A contract is considered expired when its proof window has elapsed. If the contract is not storing any data, it will resolve as valid; otherwise, it resolves as missed.
func (*V2FileContractExpiration) DecodeFrom ¶
func (*V2FileContractExpiration) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2FileContractExpiration) EncodeTo ¶
func (V2FileContractExpiration) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2FileContractRenewal ¶
type V2FileContractRenewal struct { FinalRenterOutput SiacoinOutput `json:"finalRenterOutput"` FinalHostOutput SiacoinOutput `json:"finalHostOutput"` RenterRollover Currency `json:"renterRollover"` HostRollover Currency `json:"hostRollover"` NewContract V2FileContract `json:"newContract"` // signatures cover above fields RenterSignature Signature `json:"renterSignature"` HostSignature Signature `json:"hostSignature"` }
A V2FileContractRenewal renews a file contract.
func (*V2FileContractRenewal) DecodeFrom ¶
func (ren *V2FileContractRenewal) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2FileContractRenewal) EncodeTo ¶
func (ren V2FileContractRenewal) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2FileContractResolution ¶
type V2FileContractResolution struct { Parent V2FileContractElement `json:"parent"` Resolution V2FileContractResolutionType `json:"resolution"` }
A V2FileContractResolution closes a v2 file contract's payment channel. There are three ways a contract can be resolved:
1) The renter and host can jointly renew the contract. The old contract is finalized, and a portion of its funds are "rolled over" into a new contract. Renewals must be submitted prior to the contract's ProofHeight.
2) If the renter is unwilling or unable to sign a renewal, the host can submit a storage proof, asserting that it has faithfully stored the contract data for the agreed-upon duration. Storage proofs must be submitted after the contract's ProofHeight and prior to its ExpirationHeight.
3) Lastly, anyone can submit a contract expiration. An expiration can only be submitted after the contract's ExpirationHeight.
Once a contract has been resolved, it cannot be altered or resolved again. When a contract is resolved, its RenterOutput and HostOutput are created immediately (though they will not be spendable until their timelock expires). However, if the contract is resolved via an expiration, the HostOutput will have value equal to MissedHostValue; in other words, the host forfeits its collateral. This is considered a "missed" resolution; all other resolution types are "valid." As a special case, the expiration of an empty contract is considered valid, reflecting the fact that the host has not failed to perform any duty.
func (*V2FileContractResolution) DecodeFrom ¶
func (res *V2FileContractResolution) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2FileContractResolution) EncodeTo ¶
func (res V2FileContractResolution) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (V2FileContractResolution) MarshalJSON ¶
func (res V2FileContractResolution) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*V2FileContractResolution) UnmarshalJSON ¶
func (res *V2FileContractResolution) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Marshaler.
type V2FileContractResolutionType ¶
type V2FileContractResolutionType interface {
// contains filtered or unexported methods
}
V2FileContractResolutionType enumerates the types of file contract resolution.
type V2FileContractRevision ¶
type V2FileContractRevision struct { Parent V2FileContractElement `json:"parent"` Revision V2FileContract `json:"revision"` }
A V2FileContractRevision updates the state of an existing file contract.
func (*V2FileContractRevision) DecodeFrom ¶
func (rev *V2FileContractRevision) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2FileContractRevision) EncodeTo ¶
func (rev V2FileContractRevision) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2SiacoinInput ¶
type V2SiacoinInput struct { Parent SiacoinElement `json:"parent"` SatisfiedPolicy SatisfiedPolicy `json:"satisfiedPolicy"` }
A V2SiacoinInput spends an unspent SiacoinElement in the state accumulator by revealing its public key and signing the transaction.
func (*V2SiacoinInput) DecodeFrom ¶
func (in *V2SiacoinInput) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2SiacoinInput) EncodeTo ¶
func (in V2SiacoinInput) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2SiacoinOutput ¶
type V2SiacoinOutput SiacoinOutput
V2SiacoinOutput provides v2 encoding for SiacoinOutput.
func (V2SiacoinOutput) Cast ¶
func (sco V2SiacoinOutput) Cast() SiacoinOutput
Cast provides type safety for DecodeSliceCast.
func (*V2SiacoinOutput) DecodeFrom ¶
func (sco *V2SiacoinOutput) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2SiacoinOutput) EncodeTo ¶
func (sco V2SiacoinOutput) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2SiafundInput ¶
type V2SiafundInput struct { Parent SiafundElement `json:"parent"` ClaimAddress Address `json:"claimAddress"` SatisfiedPolicy SatisfiedPolicy `json:"satisfiedPolicy"` }
A V2SiafundInput 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 (*V2SiafundInput) DecodeFrom ¶
func (in *V2SiafundInput) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2SiafundInput) EncodeTo ¶
func (in V2SiafundInput) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2SiafundOutput ¶
type V2SiafundOutput SiafundOutput
V2SiafundOutput provides v2 encoding for SiafundOutput.
func (V2SiafundOutput) Cast ¶
func (sfo V2SiafundOutput) Cast() SiafundOutput
Cast provides type safety for DecodeSliceCast.
func (*V2SiafundOutput) DecodeFrom ¶
func (sfo *V2SiafundOutput) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2SiafundOutput) EncodeTo ¶
func (sfo V2SiafundOutput) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2StorageProof ¶
type V2StorageProof struct { // Selecting the leaf requires a source of unpredictable entropy; we use the // ID of the block at the contract's ProofHeight. The storage proof thus // includes a proof that this ID is the correct ancestor. // // During validation, it is imperative to check that ProofIndex.Height // matches the ProofHeight field of the contract's final revision; // otherwise, the prover could use any ProofIndex, giving them control over // the leaf index. ProofIndex ChainIndexElement // The leaf is always 64 bytes, extended with zeros if necessary. Leaf [64]byte Proof []Hash256 }
A V2StorageProof asserts the presence of a randomly-selected leaf within the Merkle tree of a V2FileContract's data.
func (*V2StorageProof) DecodeFrom ¶
func (sp *V2StorageProof) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2StorageProof) EncodeTo ¶
func (sp V2StorageProof) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (V2StorageProof) MarshalJSON ¶
func (sp V2StorageProof) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*V2StorageProof) UnmarshalJSON ¶
func (sp *V2StorageProof) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type V2Transaction ¶
type V2Transaction struct { SiacoinInputs []V2SiacoinInput `json:"siacoinInputs,omitempty"` SiacoinOutputs []SiacoinOutput `json:"siacoinOutputs,omitempty"` SiafundInputs []V2SiafundInput `json:"siafundInputs,omitempty"` SiafundOutputs []SiafundOutput `json:"siafundOutputs,omitempty"` FileContracts []V2FileContract `json:"fileContracts,omitempty"` FileContractRevisions []V2FileContractRevision `json:"fileContractRevisions,omitempty"` FileContractResolutions []V2FileContractResolution `json:"fileContractResolutions,omitempty"` Attestations []Attestation `json:"attestations,omitempty"` ArbitraryData []byte `json:"arbitraryData,omitempty"` NewFoundationAddress *Address `json:"newFoundationAddress,omitempty"` MinerFee Currency `json:"minerFee"` }
A V2Transaction effects a change of blockchain state.
func (*V2Transaction) AttestationID ¶
func (*V2Transaction) AttestationID(txid TransactionID, i int) AttestationID
AttestationID returns the ID for the attestation at index i.
func (*V2Transaction) DecodeFrom ¶
func (txn *V2Transaction) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (*V2Transaction) DeepCopy ¶
func (txn *V2Transaction) DeepCopy() V2Transaction
DeepCopy returns a copy of txn that does not alias any of its memory.
func (V2Transaction) EncodeTo ¶
func (txn V2Transaction) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
func (*V2Transaction) EphemeralSiacoinOutput ¶
func (txn *V2Transaction) EphemeralSiacoinOutput(i int) SiacoinElement
EphemeralSiacoinOutput returns a SiacoinElement for the siacoin output at index i.
func (*V2Transaction) EphemeralSiafundOutput ¶
func (txn *V2Transaction) EphemeralSiafundOutput(i int) SiafundElement
EphemeralSiafundOutput returns a SiafundElement for the siafund output at index i.
func (*V2Transaction) FullHash ¶
func (txn *V2Transaction) FullHash() Hash256
FullHash returns the hash of the transaction's binary encoding. This hash is only used in specific circumstances; generally, ID should be used instead.
func (*V2Transaction) ID ¶
func (txn *V2Transaction) 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 FullHash method.
func (V2Transaction) MarshalJSON ¶
func (txn V2Transaction) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaller.
For convenience, the transaction's ID is also calculated and included. This field is ignored during unmarshalling.
func (*V2Transaction) SiacoinOutputID ¶
func (*V2Transaction) SiacoinOutputID(txid TransactionID, i int) SiacoinOutputID
SiacoinOutputID returns the ID for the siacoin output at index i.
func (*V2Transaction) SiafundOutputID ¶
func (*V2Transaction) SiafundOutputID(txid TransactionID, i int) SiafundOutputID
SiafundOutputID returns the ID for the siafund output at index i.
func (*V2Transaction) V2FileContractID ¶
func (*V2Transaction) V2FileContractID(txid TransactionID, i int) FileContractID
V2FileContractID returns the ID for the v2 file contract at index i.
type V2TransactionSemantics ¶
type V2TransactionSemantics V2Transaction
V2TransactionSemantics is a helper type that provides a "semantic encoding" of a v2 transaction, for use in computing IDs and signature hashes.
func (V2TransactionSemantics) EncodeTo ¶
func (txn V2TransactionSemantics) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.
type V2TransactionsMultiproof ¶
type V2TransactionsMultiproof []V2Transaction
V2TransactionsMultiproof is a slice of V2Transactions whose Merkle proofs are encoded as a single multiproof. This can significantly reduce the size of the encoded transactions. However, multiproofs may only be used for transaction sets whose Merkle proofs are all valid for the same consensus state.
func (*V2TransactionsMultiproof) DecodeFrom ¶
func (txns *V2TransactionsMultiproof) DecodeFrom(d *Decoder)
DecodeFrom implements types.DecoderFrom.
func (V2TransactionsMultiproof) EncodeTo ¶
func (txns V2TransactionsMultiproof) EncodeTo(e *Encoder)
EncodeTo implements types.EncoderTo.