types

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// BlockHeaderSize is the size, in bytes, of a block header.
	// 32 (ParentID) + 8 (Timestamp) + 24 (8 BlockHeight + 8 TransactionIndex + 8 OutputIndex) +  32 (MerkleRoot)
	BlockHeaderSize = 96
)
View Source
const (
	SpecifierLen = 16
)
View Source
const (
	// UnlockHashChecksumSize is the size of the checksum used to verify
	// human-readable addresses. It is not a crypytographically secure
	// checksum, it's merely intended to prevent typos. 6 is chosen because it
	// brings the total size of the address to 38 bytes, leaving 2 bytes for
	// potential version additions in the future.
	UnlockHashChecksumSize = 6
)

Variables

View Source
var (
	BlockSizeLimit   = uint64(2e6)
	RootDepth        = Target{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
	BlockFrequency   BlockHeight
	MaturityDelay    BlockHeight
	GenesisTimestamp Timestamp
	RootTarget       Target

	MedianTimestampWindow  = uint64(11)
	TargetWindow           BlockHeight
	MaxAdjustmentUp        *big.Rat
	MaxAdjustmentDown      *big.Rat
	FutureThreshold        Timestamp
	ExtremeFutureThreshold Timestamp

	StakeModifierDelay BlockHeight

	BlockStakeAging uint64

	BlockCreatorFee Currency

	OneCoin = NewCurrency(new(big.Int).Exp(big.NewInt(10), big.NewInt(24), nil))

	GenesisBlockStakeAllocation = []BlockStakeOutput{}
	GenesisBlockStakeCount      Currency
	GenesisCoinDistribution     = []CoinOutput{}
	GenesisCoinCount            Currency

	GenesisBlock Block

	// GenesisID is used in many places. Calculating it once saves lots of
	// redundant computation.
	GenesisID BlockID

	// StartDifficulty is used in many places. Calculate it once.
	StartDifficulty Difficulty
)
View Source
var (
	// ZeroCurrency defines a currency of value zero.
	ZeroCurrency = NewCurrency64(0)

	// ErrNegativeCurrency is the error that is returned if performing an
	// operation results in a negative currency.
	ErrNegativeCurrency = errors.New("negative currency not allowed")

	// ErrUint64Overflow is the error that is returned if converting to a
	// unit64 would cause an overflow.
	ErrUint64Overflow = errors.New("cannot return the uint64 of this currency - result is an overflow")
)
View Source
var (
	// These Specifiers enumerate the types of signatures that are recognized
	// by this implementation. If a signature's type is unrecognized, the
	// signature is treated as valid. Signatures using the special "entropy"
	// type are always treated as invalid; see Consensus.md for more details.
	SignatureEntropy = Specifier{'e', 'n', 't', 'r', 'o', 'p', 'y'}
	SignatureEd25519 = Specifier{'e', 'd', '2', '5', '5', '1', '9'}

	ErrEntropyKey                = errors.New("transaction tries to sign an entproy public key")
	ErrFrivilousSignature        = errors.New("transaction contains a frivilous siganture")
	ErrInvalidPubKeyIndex        = errors.New("transaction contains a signature that points to a nonexistent public key")
	ErrInvalidUnlockHashChecksum = errors.New("provided unlock hash has an invalid checksum")
	ErrMissingSignatures         = errors.New("transaction has inputs with missing signatures")
	ErrPrematureSignature        = errors.New("timelock on signature has not expired")
	ErrPublicKeyOveruse          = errors.New("public key was used multiple times while signing transaction")
	ErrSortedUniqueViolation     = errors.New("sorted unique violation")
	ErrUnlockHashWrongLen        = errors.New("marshalled unlock hash is the wrong length")
	ErrWholeTransactionViolation = errors.New("covered fields violation")

	// FullCoveredFields is a covered fileds object where the
	// 'WholeTransaction' field has been set to true. The primary purpose of
	// this variable is syntactic sugar.
	FullCoveredFields = CoveredFields{WholeTransaction: true}
)
View Source
var (
	SpecifierMinerPayout      = Specifier{'m', 'i', 'n', 'e', 'r', ' ', 'p', 'a', 'y', 'o', 'u', 't'}
	SpecifierCoinInput        = Specifier{'c', 'o', 'i', 'n', ' ', 'i', 'n', 'p', 'u', 't'}
	SpecifierCoinOutput       = Specifier{'c', 'o', 'i', 'n', ' ', 'o', 'u', 't', 'p', 'u', 't'}
	SpecifierBlockStakeInput  = Specifier{'b', 'l', 's', 't', 'a', 'k', 'e', ' ', 'i', 'n', 'p', 'u', 't'}
	SpecifierBlockStakeOutput = Specifier{'b', 'l', 's', 't', 'a', 'k', 'e', ' ', 'o', 'u', 't', 'p', 'u', 't'}
	SpecifierMinerFee         = Specifier{'m', 'i', 'n', 'e', 'r', ' ', 'f', 'e', 'e'}

	ErrTransactionIDWrongLen = errors.New("input has wrong length to be an encoded transaction id")
)

These Specifiers are used internally when calculating a type's ID. See Specifier for more details.

View Source
var (
	ErrDoubleSpend          = errors.New("transaction uses a parent object twice")
	ErrNonZeroRevision      = errors.New("new file contract has a nonzero revision number")
	ErrTimelockNotSatisfied = errors.New("timelock has not been met")
	ErrTransactionTooLarge  = errors.New("transaction is too large to fit in a block")
	ErrZeroMinerFee         = errors.New("transaction has a zero value miner fee")
	ErrZeroOutput           = errors.New("transaction cannot have an output or payout that has zero value")
)
View Source
var (
	// ErrNegativeDifficulty is the error that is returned if performing an
	// operation results in a negative difficulty.
	ErrNegativeDifficulty = errors.New("negative difficulty not allowed")
)
View Source
var (
	ErrNegativeTarget = errors.New("negative value used when converting to target")
)

Functions

func CalculateGenesis added in v0.1.2

func CalculateGenesis()

CalculateGenesis fills in the genesis block variables which are computed based on variables that have been set earlier

Types

type Block

type Block struct {
	ParentID     BlockID                 `json:"parentid"`
	Timestamp    Timestamp               `json:"timestamp"`
	POBSOutput   BlockStakeOutputIndexes `json:"pobsindexes"`
	MinerPayouts []CoinOutput            `json:"minerpayouts"`
	Transactions []Transaction           `json:"transactions"`
}

A Block is a summary of changes to the state that have occurred since the previous block. Blocks reference the ID of the previous block (their "parent"), creating the linked-list commonly known as the blockchain. Their primary function is to bundle together transactions on the network. Blocks are created by "blockcreators," who collect transactions from other nodes, and then use there BlockStake and some other parameters to come below a given target.

func (Block) CalculateSubsidy

func (b Block) CalculateSubsidy() Currency

CalculateSubsidy determines the block subsidy as the sum of the minerfees and the block creator fee.

func (Block) Header

func (b Block) Header() BlockHeader

Header returns the header of a block.

func (Block) ID

func (b Block) ID() BlockID

ID returns the ID of a Block, which is calculated by hashing the concatenation of the block's parent's ID, nonce, and the result of the b.MerkleRoot(). It is equivalent to calling block.Header().ID()

func (Block) MarshalSia

func (b Block) MarshalSia(w io.Writer) error

MarshalSia implements the encoding.SiaMarshaler interface.

func (Block) MerkleRoot

func (b Block) MerkleRoot() crypto.Hash

MerkleRoot calculates the Merkle root of a Block. The leaves of the Merkle tree are composed of the miner outputs (one leaf per payout), and the transactions (one leaf per transaction).

func (Block) MinerPayoutID

func (b Block) MinerPayoutID(i uint64) CoinOutputID

MinerPayoutID returns the ID of the miner payout at the given index, which is calculated by hashing the concatenation of the BlockID and the payout index.

func (*Block) UnmarshalBlockHeadersParentIDAndTS added in v0.1.0

func (b *Block) UnmarshalBlockHeadersParentIDAndTS(raw []byte) (BlockID, Timestamp)

UnmarshalBlockHeadersParentIDAndTS The MerkleRoot is not unmarshalled from the header because

func (*Block) UnmarshalSia

func (b *Block) UnmarshalSia(r io.Reader) error

UnmarshalSia implements the encoding.SiaUnmarshaler interface.

type BlockHeader

type BlockHeader struct {
	ParentID   BlockID                 `json:"parentid"`
	POBSOutput BlockStakeOutputIndexes `json:"pobsindexes"`
	Timestamp  Timestamp               `json:"timestamp"`
	MerkleRoot crypto.Hash             `json:"merkleroot"`
}

A BlockHeader, when encoded, is an 96-byte constant size field containing enough information to do headers-first block downloading. Hashing the header results in the block ID.

func (BlockHeader) ID

func (h BlockHeader) ID() BlockID

ID returns the ID of a Block, which is calculated by hashing the header.

type BlockHeight

type BlockHeight uint64

type BlockID

type BlockID crypto.Hash

func (BlockID) MarshalJSON

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

MarshalJSON marshales a block id as a hex string.

func (BlockID) String

func (bid BlockID) String() string

String prints the block id in hex.

func (*BlockID) UnmarshalJSON

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

UnmarshalJSON decodes the json hex string of the block id.

type BlockStakeInput

type BlockStakeInput struct {
	ParentID         BlockStakeOutputID `json:"parentid"`
	UnlockConditions UnlockConditions   `json:"unlockconditions"`
}

A BlockStakeInput consumes a BlockStakeOutput and adds the blockstakes to the set of blockstakes that can be spent in the transaction. The ParentID points to the output that is getting consumed, and the UnlockConditions contain the rules for spending the output. The UnlockConditions must match the UnlockHash of the output.

type BlockStakeOutput

type BlockStakeOutput struct {
	Value      Currency   `json:"value"`
	UnlockHash UnlockHash `json:"unlockhash"`
}

A BlockStakeOutput holds a volume of blockstakes. Outputs must be spent atomically; that is, they must all be spent in the same transaction. The UnlockHash is the hash of a set of UnlockConditions that must be fulfilled in order to spend the output.

type BlockStakeOutputID

type BlockStakeOutputID crypto.Hash

func (BlockStakeOutputID) MarshalJSON

func (bsoid BlockStakeOutputID) MarshalJSON() ([]byte, error)

MarshalJSON marshales an id as a hex string.

func (BlockStakeOutputID) String

func (bsoid BlockStakeOutputID) String() string

String prints the id in hex.

func (*BlockStakeOutputID) UnmarshalJSON

func (bsoid *BlockStakeOutputID) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json hex string of the id.

type BlockStakeOutputIndexes added in v0.1.0

type BlockStakeOutputIndexes struct {
	BlockHeight      BlockHeight
	TransactionIndex uint64
	OutputIndex      uint64
}

BlockStakeOutputIndexes groups the block height, the transaction index and the output index to uniquely identify a blockstake output. These indexes and the value are required for the POBS protocol.

type Clock

type Clock interface {
	Now() Timestamp
}

Clock allows clients to retrieve the current time.

type CoinInput added in v0.1.0

type CoinInput struct {
	ParentID         CoinOutputID     `json:"parentid"`
	UnlockConditions UnlockConditions `json:"unlockconditions"`
}

A SiacoinInput consumes a SiacoinOutput and adds the siacoins to the set of siacoins that can be spent in the transaction. The ParentID points to the output that is getting consumed, and the UnlockConditions contain the rules for spending the output. The UnlockConditions must match the UnlockHash of the output.

type CoinOutput added in v0.1.0

type CoinOutput struct {
	Value      Currency   `json:"value"`
	UnlockHash UnlockHash `json:"unlockhash"`
}

A CoinOutput holds a volume of siacoins. Outputs must be spent atomically; that is, they must all be spent in the same transaction. The UnlockHash is the hash of the UnlockConditions that must be fulfilled in order to spend the output.

type CoinOutputID added in v0.1.0

type CoinOutputID crypto.Hash

func (CoinOutputID) MarshalJSON added in v0.1.0

func (scoid CoinOutputID) MarshalJSON() ([]byte, error)

MarshalJSON marshales an id as a hex string.

func (CoinOutputID) String added in v0.1.0

func (scoid CoinOutputID) String() string

String prints the id in hex.

func (*CoinOutputID) UnmarshalJSON added in v0.1.0

func (scoid *CoinOutputID) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json hex string of the id.

type CoveredFields

type CoveredFields struct {
	WholeTransaction      bool     `json:"wholetransaction"`
	CoinInputs            []uint64 `json:"coininputs"`
	CoinOutputs           []uint64 `json:"coinoutputs"`
	BlockStakeInputs      []uint64 `json:"blockstakeinputs"`
	BlockStakeOutputs     []uint64 `json:"blockstakeoutputs"`
	MinerFees             []uint64 `json:"minerfees"`
	ArbitraryData         []uint64 `json:"arbitrarydata"`
	TransactionSignatures []uint64 `json:"transactionsignatures"`
}

CoveredFields indicates which fields in a transaction have been covered by the signature. (Note that the signature does not sign the fields themselves, but rather their combined hash; see SigHash.) Each slice corresponds to a slice in the Transaction type, indicating which indices of the slice have been signed. The indices must be valid, i.e. within the bounds of the slice. In addition, they must be sorted and unique.

As a convenience, a signature of the entire transaction can be indicated by the 'WholeTransaction' field. If 'WholeTransaction' == true, all other fields must be empty (except for the Signatures field, since a signature cannot sign itself).

type Currency

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

A Currency represents a number of siacoins or siafunds. Internally, a Currency value is unbounded; however, Currency values sent over the wire protocol are subject to a maximum size of 255 bytes (approximately 10^614). Unlike the math/big library, whose methods modify their receiver, all arithmetic Currency methods return a new value. Currency cannot be negative.

func NewCurrency

func NewCurrency(b *big.Int) (c Currency)

NewCurrency creates a Currency value from a big.Int. Undefined behavior occurs if a negative input is used.

func NewCurrency64

func NewCurrency64(x uint64) (c Currency)

NewCurrency64 creates a Currency value from a uint64.

func (Currency) Add

func (x Currency) Add(y Currency) (c Currency)

Add returns a new Currency value c = x + y

func (Currency) Big

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

Big returns the value of c as a *big.Int. Importantly, it does not provide access to the c's internal big.Int object, only a copy.

func (Currency) Cmp

func (x Currency) Cmp(y Currency) int

Cmp compares two Currency values. The return value follows the convention of math/big.

func (Currency) Div

func (x Currency) Div(y Currency) (c Currency)

Div returns a new Currency value c = x / y.

func (Currency) Div64

func (x Currency) Div64(y uint64) (c Currency)

Div64 returns a new Currency value c = x / y.

func (Currency) IsZero

func (c Currency) IsZero() bool

IsZero returns true if the value is 0, false otherwise.

func (Currency) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Currency) MarshalSia

func (c Currency) MarshalSia(w io.Writer) error

MarshalSia implements the encoding.SiaMarshaler interface. It writes the byte-slice representation of the Currency's internal big.Int to w. Note that as the bytes of the big.Int correspond to the absolute value of the integer, there is no way to marshal a negative Currency.

func (Currency) Mul

func (x Currency) Mul(y Currency) (c Currency)

Mul returns a new Currency value c = x * y.

func (Currency) Mul64

func (x Currency) Mul64(y uint64) (c Currency)

Mul64 returns a new Currency value c = x * y.

func (Currency) MulFloat

func (x Currency) MulFloat(y float64) (c Currency)

COMPATv0.4.0 - until the first 10e3 blocks have been archived, MulFloat is needed while verifying the first set of blocks.

MulFloat returns a new Currency value y = c * x, where x is a float64. Behavior is undefined when x is negative.

func (Currency) MulRat

func (x Currency) MulRat(y *big.Rat) (c Currency)

MulRat returns a new Currency value c = x * y, where y is a big.Rat.

func (Currency) RoundDown

func (x Currency) RoundDown(y Currency) (c Currency)

RoundDown returns the largest multiple of y <= x.

func (*Currency) Scan

func (c *Currency) Scan(s fmt.ScanState, ch rune) error

Scan implements the fmt.Scanner interface, allowing Currency values to be scanned from text.

func (Currency) Sqrt

func (x Currency) Sqrt() (c Currency)

Sqrt returns a new Currency value y = sqrt(c). Result is rounded down to the nearest integer.

func (Currency) String

func (c Currency) String() string

String implements the fmt.Stringer interface.

func (Currency) Sub

func (x Currency) Sub(y Currency) (c Currency)

Sub returns a new Currency value c = x - y. Behavior is undefined when x < y.

func (Currency) Uint64

func (c Currency) Uint64() (u uint64, err error)

Uint64 converts a Currency to a uint64. An error is returned because this function is sometimes called on values that can be determined by users - rather than have all user-facing points do input checking, the input checking should happen at the base type. This minimizes the chances of a rogue user causing a build.Critical to be triggered.

func (*Currency) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. An error is returned if a negative number is provided.

func (*Currency) UnmarshalSia

func (c *Currency) UnmarshalSia(r io.Reader) error

UnmarshalSia implements the encoding.SiaUnmarshaler interface.

type Difficulty added in v0.1.0

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

A Difficulty represents a number in number of blockstake times time in seconds Normally the difficulty is the number of active blockstake times the BlockFrequency. ex. If the number of active blockstake grows, the difficulty will also increase to maintain the same BlockFrequency.

func NewDifficulty added in v0.1.0

func NewDifficulty(b *big.Int) (d Difficulty)

NewDifficulty creates a Difficulty value from a big.Int. Undefined behavior occurs if a negative input is used.

func (Difficulty) Big added in v0.1.0

func (x Difficulty) Big() *big.Int

Big returns the value of c as a *big.Int. Importantly, it does not provide access to the c's internal big.Int object, only a copy.

func (Difficulty) Cmp added in v0.1.0

func (x Difficulty) Cmp(y Difficulty) int

Cmp compares two Difficulty values. The return value follows the convention of math/big.

func (Difficulty) Div64 added in v0.1.0

func (x Difficulty) Div64(y uint64) (c Difficulty)

Div64 returns a new Difficulty value c = x / y.

func (Difficulty) MarshalJSON added in v0.1.0

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

MarshalJSON implements the json.Marshaler interface.

func (Difficulty) MarshalSia added in v0.1.0

func (c Difficulty) MarshalSia(w io.Writer) error

MarshalSia implements the encoding.SiaMarshaler interface. It writes the byte-slice representation of the Difficulty's internal big.Int to w. Note that as the bytes of the big.Int correspond to the absolute value of the integer, there is no way to marshal a negative Difficulty.

func (*Difficulty) Scan added in v0.1.0

func (c *Difficulty) Scan(s fmt.ScanState, ch rune) error

Scan implements the fmt.Scanner interface, allowing Difficulty values to be scanned from text.

func (Difficulty) String added in v0.1.0

func (c Difficulty) String() string

String implements the fmt.Stringer interface.

func (*Difficulty) UnmarshalJSON added in v0.1.0

func (c *Difficulty) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. An error is returned if a negative number is provided.

func (*Difficulty) UnmarshalSia added in v0.1.0

func (c *Difficulty) UnmarshalSia(r io.Reader) error

UnmarshalSia implements the encoding.SiaUnmarshaler interface.

type OutputID

type OutputID crypto.Hash

func (OutputID) MarshalJSON

func (oid OutputID) MarshalJSON() ([]byte, error)

MarshalJSON marshales an id as a hex string.

func (OutputID) String

func (oid OutputID) String() string

String prints the id in hex.

func (*OutputID) UnmarshalJSON

func (oid *OutputID) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json hex string of the id.

type SiaPublicKey

type SiaPublicKey struct {
	Algorithm Specifier `json:"algorithm"`
	Key       []byte    `json:"key"`
}

A SiaPublicKey is a public key prefixed by a Specifier. The Specifier indicates the algorithm used for signing and verification. Unrecognized algorithms will always verify, which allows new algorithms to be added to the protocol via a soft-fork.

func (*SiaPublicKey) String added in v0.1.0

func (spk *SiaPublicKey) String() string

String defines how to print a SiaPublicKey - hex is used to keep things compact during logging. The key type prefix and lack of a checksum help to separate it from a sia address.

type Specifier

type Specifier [SpecifierLen]byte

A Specifier is a fixed-length byte-array that serves two purposes. In the wire protocol, they are used to identify a particular encoding algorithm, signature algorithm, etc. This allows nodes to communicate on their own terms; for example, to reduce bandwidth costs, a node might only accept compressed messages.

Internally, Specifiers are used to guarantee unique IDs. Various consensus types have an associated ID, calculated by hashing the data contained in the type. By prepending the data with Specifier, we can guarantee that distinct types will never produce the same hash.

func (Specifier) MarshalJSON

func (s Specifier) MarshalJSON() ([]byte, error)

MarshalJSON marshales a specifier as a hex string.

func (Specifier) String

func (s Specifier) String() string

String prints the specifier in hex.

func (*Specifier) UnmarshalJSON

func (s *Specifier) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json hex string of the id.

type StdClock

type StdClock struct{}

StdClock is an implementation of Clock that retrieves the current time using the system time.

func (StdClock) Now

func (c StdClock) Now() Timestamp

Now retrieves the current timestamp.

type Target

type Target crypto.Hash

A Target is a hash that a block's ID must be "less than" in order for the block to be considered valid. Miners vary the block's 'Nonce' field in order to brute-force such an ID. The inverse of a Target is called the "difficulty," because it is proportional to the amount of time required to brute-force the Target.

func IntToTarget

func IntToTarget(i *big.Int) (t Target)

IntToTarget converts a big.Int to a Target. Negative inputs trigger a panic.

func NewTarget added in v0.1.0

func NewTarget(difficulty Difficulty) Target

NewTarget makes a new target from a given difficulty

func RatToTarget

func RatToTarget(r *big.Rat) (t Target)

RatToTarget converts a big.Rat to a Target.

func (Target) AddDifficulties

func (x Target) AddDifficulties(y Target) (t Target)

AddDifficulties returns the resulting target with the difficulty of 'x' and 'y' are added together. Note that the difficulty is the inverse of the target. The sum is defined by:

sum(x, y) = 1/(1/x + 1/y)

func (Target) Cmp

func (x Target) Cmp(y Target) int

Cmp compares the difficulties of two targets. Note that the difficulty is the inverse of the target. The results are as follows:

-1 if x <  y
 0 if x == y
+1 if x >  y

func (Target) Difficulty

func (t Target) Difficulty() Difficulty

Difficulty returns the difficulty associated with a given target.

func (Target) Int

func (t Target) Int() *big.Int

Int converts a Target to a big.Int.

func (Target) Inverse

func (t Target) Inverse() *big.Rat

Inverse returns the inverse of a Target as a big.Rat

func (Target) MulDifficulty

func (x Target) MulDifficulty(y *big.Rat) (t Target)

Mul multiplies the difficulty of a target by y. The product is defined by:

y / x

func (Target) Rat

func (t Target) Rat() *big.Rat

Rat converts a Target to a big.Rat.

func (Target) SubtractDifficulties

func (x Target) SubtractDifficulties(y Target) (t Target)

SubtractDifficulties returns the resulting target with the difficulty of 'x' is subtracted from the target with difficulty 'y'. Note that the difficulty is the inverse of the target. The difference is defined by:

sum(x, y) = 1/(1/x - 1/y)

type Timestamp

type Timestamp uint64

func CurrentTimestamp

func CurrentTimestamp() Timestamp

CurrentTimestamp returns the current time as a Timestamp.

type TimestampSlice

type TimestampSlice []Timestamp

func (TimestampSlice) Len

func (ts TimestampSlice) Len() int

Len is part of sort.Interface

func (TimestampSlice) Less

func (ts TimestampSlice) Less(i, j int) bool

Less is part of sort.Interface

func (TimestampSlice) Swap

func (ts TimestampSlice) Swap(i, j int)

Swap is part of sort.Interface

type Transaction

type Transaction struct {
	CoinInputs            []CoinInput            `json:"coininputs"`
	CoinOutputs           []CoinOutput           `json:"coinoutputs"`
	BlockStakeInputs      []BlockStakeInput      `json:"blockstakeinputs"`
	BlockStakeOutputs     []BlockStakeOutput     `json:"blockstakeoutputs"`
	MinerFees             []Currency             `json:"minerfees"`
	ArbitraryData         [][]byte               `json:"arbitrarydata"`
	TransactionSignatures []TransactionSignature `json:"transactionsignatures"`
}

A Transaction is an atomic component of a block. Transactions can contain inputs and outputs and even arbitrary data. They can also contain signatures to prove that a given party has approved the transaction, or at least a particular subset of it.

Transactions can depend on other previous transactions in the same block, but transactions cannot spend outputs that they create or otherwise be self-dependent.

func (Transaction) BlockStakeOutputID

func (t Transaction) BlockStakeOutputID(i uint64) BlockStakeOutputID

BlockStakeOutputID returns the ID of a BlockStakeOutput at the given index, which is calculated by hashing the concatenation of the BlockStakeOutput Specifier, all of the fields in the transaction (except the signatures), and output index.

func (Transaction) CoinOutputID added in v0.1.0

func (t Transaction) CoinOutputID(i uint64) CoinOutputID

CoinOutputID returns the ID of a coin output at the given index, which is calculated by hashing the concatenation of the CoinOutput Specifier, all of the fields in the transaction (except the signatures), and output index.

func (Transaction) CoinOutputSum added in v0.1.0

func (t Transaction) CoinOutputSum() (sum Currency)

CoinOutputSum returns the sum of all the coin outputs in the transaction, which must match the sum of all the coin inputs.

func (Transaction) ID

func (t Transaction) ID() TransactionID

ID returns the id of a transaction, which is taken by marshalling all of the fields except for the signatures and taking the hash of the result.

func (Transaction) SigHash

func (t Transaction) SigHash(i int) crypto.Hash

SigHash returns the hash of the fields in a transaction covered by a given signature. See CoveredFields for more details.

func (Transaction) StandaloneValid

func (t Transaction) StandaloneValid(currentHeight BlockHeight) (err error)

StandaloneValid returns an error if a transaction is not valid in any context, for example if the same output is spent twice in the same transaction. StandaloneValid will not check that all outputs being spent are legal outputs, as it has no confirmed or unconfirmed set to look at.

type TransactionID

type TransactionID crypto.Hash

IDs are used to refer to a type without revealing its contents. They are constructed by hashing specific fields of the type, along with a Specifier. While all of these types are hashes, defining type aliases gives us type safety and makes the code more readable.

func (TransactionID) MarshalJSON

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

MarshalJSON marshales an id as a hex string.

func (TransactionID) String

func (tid TransactionID) String() string

String prints the id in hex.

func (*TransactionID) UnmarshalJSON

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

UnmarshalJSON decodes the json hex string of the id.

type TransactionSignature

type TransactionSignature struct {
	ParentID       crypto.Hash   `json:"parentid"`
	PublicKeyIndex uint64        `json:"publickeyindex"`
	Timelock       BlockHeight   `json:"timelock"`
	CoveredFields  CoveredFields `json:"coveredfields"`
	Signature      []byte        `json:"signature"`
}

A TransactionSignature is a signature that is included in the transaction. The signature should correspond to a public key in one of the UnlockConditions of the transaction. This key is specified first by 'ParentID', which specifies the UnlockConditions, and then 'PublicKeyIndex', which indicates the key in the UnlockConditions. There are three types that use UnlockConditions: SiacoinInputs, SiafundInputs, and FileContractTerminations. Each of these types also references a ParentID, and this is the hash that 'ParentID' must match. The 'Timelock' prevents the signature from being used until a certain height. 'CoveredFields' indicates which parts of the transaction are being signed; see CoveredFields.

type UnlockConditions

type UnlockConditions struct {
	Timelock           BlockHeight    `json:"timelock"`
	PublicKeys         []SiaPublicKey `json:"publickeys"`
	SignaturesRequired uint64         `json:"signaturesrequired"`
}

UnlockConditions are a set of conditions which must be met to execute certain actions, such as spending a SiacoinOutput or terminating a FileContract.

The simplest requirement is that the block containing the UnlockConditions must have a height >= 'Timelock'.

'PublicKeys' specifies the set of keys that can be used to satisfy the UnlockConditions; of these, at least 'SignaturesRequired' unique keys must sign the transaction. The keys that do not need to use the same cryptographic algorithm.

If 'SignaturesRequired' == 0, the UnlockConditions are effectively "anyone can unlock." If 'SignaturesRequired' > len('PublicKeys'), then the UnlockConditions cannot be fulfilled under any circumstances.

func (UnlockConditions) UnlockHash

func (uc UnlockConditions) UnlockHash() UnlockHash

UnlockHash calculates the root hash of a Merkle tree of the UnlockConditions object. The leaves of this tree are formed by taking the hash of the timelock, the hash of the public keys (one leaf each), and the hash of the number of signatures. The keys are put in the middle because Timelock and SignaturesRequired are both low entropy fields; they can bee protected by having random public keys next to them.

type UnlockHash

type UnlockHash crypto.Hash

An UnlockHash is a specially constructed hash of the UnlockConditions type. "Locked" values can be unlocked by providing the UnlockConditions that hash to a given UnlockHash. See SpendConditions.UnlockHash for details on how the UnlockHash is constructed.

func (*UnlockHash) LoadString

func (uh *UnlockHash) LoadString(strUH string) error

LoadString loads a hex representation (including checksum) of an unlock hash into an unlock hash object. An error is returned if the string is invalid or fails the checksum.

func (UnlockHash) MarshalJSON

func (uh UnlockHash) MarshalJSON() ([]byte, error)

MarshalJSON is implemented on the unlock hash to always produce a hex string upon marshalling.

func (UnlockHash) String

func (uh UnlockHash) String() string

String returns the hex representation of the unlock hash as a string - this includes a checksum.

func (*UnlockHash) UnmarshalJSON

func (uh *UnlockHash) UnmarshalJSON(b []byte) error

UnmarshalJSON is implemented on the unlock hash to recover an unlock hash that has been encoded to a hex string.

type UnlockHashSlice

type UnlockHashSlice []UnlockHash

func (UnlockHashSlice) Len

func (uhs UnlockHashSlice) Len() int

Len implements the Len method of sort.Interface.

func (UnlockHashSlice) Less

func (uhs UnlockHashSlice) Less(i, j int) bool

Less implements the Less method of sort.Interface.

func (UnlockHashSlice) Swap

func (uhs UnlockHashSlice) Swap(i, j int)

Swap implements the Swap method of sort.Interface.

type UnspentBlockStakeOutput added in v0.1.0

type UnspentBlockStakeOutput struct {
	BlockStakeOutputID BlockStakeOutputID
	Indexes            BlockStakeOutputIndexes
	Value              Currency
	UnlockHash         UnlockHash
}

UnspentBlockStakeOutput groups the BlockStakeOutputID, the block height, the transaction index, the output index and the value

Jump to

Keyboard shortcuts

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