Documentation ¶
Overview ¶
Package types defines the essential types of the Sia blockchain.
Index ¶
- Constants
- func CurrentTimestamp() time.Time
- func EncodedLen(v interface{}) int
- type Address
- func (a *Address) DecodeFrom(d *Decoder)
- func (a Address) EncodeTo(e *Encoder)
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalText() ([]byte, error)
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(b []byte) (err error)
- func (a *Address) UnmarshalText(b []byte) (err error)
- type Attestation
- type Block
- type BlockHeader
- type BlockID
- func (id *BlockID) DecodeFrom(d *Decoder)
- func (id BlockID) EncodeTo(e *Encoder)
- func (bid BlockID) MarshalJSON() ([]byte, error)
- func (bid BlockID) MarshalText() ([]byte, error)
- func (bid BlockID) MeetsTarget(t BlockID) bool
- func (bid BlockID) String() string
- func (bid *BlockID) UnmarshalJSON(b []byte) error
- func (bid *BlockID) UnmarshalText(b []byte) error
- type ChainIndex
- 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) DecodeFrom(d *Decoder)
- func (c Currency) Div(v Currency) Currency
- func (c Currency) Div64(v uint64) Currency
- func (c Currency) EncodeTo(e *Encoder)
- 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) MarshalJSON() ([]byte, error)
- func (c Currency) Mul64(v uint64) Currency
- func (c Currency) String() string
- func (c Currency) Sub(v Currency) Currency
- func (c Currency) SubWithUnderflow(v Currency) (Currency, bool)
- func (c *Currency) UnmarshalJSON(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) ReadPrefix() int
- 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 ElementID
- type Encoder
- func (e *Encoder) Flush() error
- func (e *Encoder) Write(p []byte) (int, error)
- func (e *Encoder) WriteBool(b bool)
- func (e *Encoder) WriteBytes(b []byte)
- func (e *Encoder) WritePrefix(i int)
- 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 EncoderTo
- type FileContract
- type FileContractElement
- type FileContractRenewal
- type FileContractResolution
- type FileContractRevision
- type Hash256
- func (h *Hash256) DecodeFrom(d *Decoder)
- func (h Hash256) EncodeTo(e *Encoder)
- func (h Hash256) MarshalJSON() ([]byte, error)
- func (h Hash256) MarshalText() ([]byte, error)
- func (h Hash256) String() string
- func (h *Hash256) UnmarshalJSON(b []byte) error
- func (h *Hash256) UnmarshalText(b []byte) error
- type Hasher
- type PolicyTypeAbove
- 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) MarshalJSON() ([]byte, error)
- func (pk PublicKey) MarshalText() ([]byte, error)
- func (pk PublicKey) String() string
- func (pk *PublicKey) UnmarshalJSON(b []byte) error
- func (pk *PublicKey) UnmarshalText(b []byte) error
- func (pk PublicKey) VerifyHash(h Hash256, s Signature) bool
- type SiacoinElement
- type SiacoinInput
- type SiacoinOutput
- type SiafundElement
- type SiafundInput
- type SiafundOutput
- type Signature
- func (s *Signature) DecodeFrom(d *Decoder)
- func (s Signature) EncodeTo(e *Encoder)
- func (sig Signature) MarshalJSON() ([]byte, error)
- func (sig Signature) MarshalText() ([]byte, error)
- func (sig Signature) String() string
- func (sig *Signature) UnmarshalJSON(b []byte) error
- func (sig *Signature) UnmarshalText(b []byte) error
- type 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) MarshalText() ([]byte, error)
- func (p SpendPolicy) String() string
- func (p *SpendPolicy) UnmarshalJSON(b []byte) (err error)
- func (p *SpendPolicy) UnmarshalText(b []byte) (err error)
- type StateElement
- type StorageProof
- type Transaction
- func (txn *Transaction) DecodeFrom(d *Decoder)
- func (txn *Transaction) DeepCopy() Transaction
- func (txn Transaction) EncodeTo(e *Encoder)
- func (txn *Transaction) EphemeralSiacoinElement(i int) SiacoinElement
- func (txn *Transaction) FileContractID(i int) ElementID
- func (txn *Transaction) ID() TransactionID
- func (txn *Transaction) SiacoinOutputID(i int) ElementID
- func (txn *Transaction) SiafundClaimOutputID(i int) ElementID
- func (txn *Transaction) SiafundOutputID(i int) ElementID
- type TransactionID
- func (id *TransactionID) DecodeFrom(d *Decoder)
- func (id TransactionID) EncodeTo(e *Encoder)
- func (tid TransactionID) MarshalJSON() ([]byte, error)
- func (tid TransactionID) MarshalText() ([]byte, error)
- func (tid TransactionID) String() string
- func (tid *TransactionID) UnmarshalJSON(b []byte) error
- func (tid *TransactionID) UnmarshalText(b []byte) error
- type Work
- func (w Work) Add(v Work) Work
- func (w Work) Cmp(v Work) int
- func (w *Work) DecodeFrom(d *Decoder)
- func (w Work) Div64(v uint64) Work
- func (w Work) EncodeTo(e *Encoder)
- func (w Work) MarshalJSON() ([]byte, error)
- func (w Work) MarshalText() ([]byte, error)
- func (w Work) Mul64(v uint64) Work
- func (w Work) String() string
- func (w Work) Sub(v Work) Work
- func (w *Work) UnmarshalJSON(b []byte) error
- func (w *Work) UnmarshalText(b []byte) error
Constants ¶
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.
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 ¶
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 ¶
ParseAddress parses an address from a prefixed hex encoded string.
func StandardAddress ¶
StandardAddress computes the address for a single public key policy.
func (*Address) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Address) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Address) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Address) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Attestation ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
DecodeFrom implements types.DecoderFrom.
func (BlockID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (BlockID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (BlockID) MeetsTarget ¶
MeetsTarget returns true if bid is not greater than t.
func (*BlockID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
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) MarshalText ¶
func (ci ChainIndex) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
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 ¶
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) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
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:
d: raw integer (equivalent to ExactString()) s: rounded integer with unit suffix (equivalent to String()) v: same as s
func (Currency) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
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) 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) SubWithUnderflow ¶
SubWithUnderflow returns c-v, along with a boolean indicating whether the result underflowed.
func (*Currency) UnmarshalJSON ¶
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 ¶
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) ReadPrefix ¶
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 ¶
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 ElementID ¶
An ElementID uniquely identifies a StateElement.
func (*ElementID) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (ElementID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ElementID) UnmarshalText ¶
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 ¶
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) WriteBytes ¶
WriteBytes writes a length-prefixed []byte to the underlying stream.
func (*Encoder) WritePrefix ¶
WritePrefix writes a length prefix 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 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 (*Hash256) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Hash256) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Hash256) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Hash256) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
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.
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 ¶
DecodeFrom implements types.DecoderFrom.
func (PublicKey) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (PublicKey) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*PublicKey) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*PublicKey) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
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 ¶
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 ¶
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 ¶
DecodeFrom implements types.DecoderFrom.
func (Signature) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Signature) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Signature) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Signature) 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 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) 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 ¶
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 ¶
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) DecodeFrom ¶
DecodeFrom implements types.DecoderFrom.
func (Work) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Work) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Work) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Work) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.