types

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2018 License: MIT Imports: 15 Imported by: 71

Documentation

Index

Constants

View Source
const (
	// AtomicSwapSecretLen is the required/fixed length
	// of an atomic swap secret, the pre-image of an hashed secret.
	AtomicSwapSecretLen = sha256.Size
	// AtomicSwapHashedSecretLen is the required/fixed length
	// of an atomic swap hashed secret, the post-image of a secret.
	AtomicSwapHashedSecretLen = sha256.Size
)

Constants that are used as part of AtomicSwap Conditions/Fulfillments.

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 (
	// LockTimeMinTimestampValue defines the minimum value a LockTime can be
	// in order to be interpreted as a (unix epoch seconds) timestamp,
	// otherwise it is interpreted as the block height instead.
	LockTimeMinTimestampValue = 500 * 1000 * 1000
)
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 (
	// 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. see Consensus.md for more details.
	SignatureEd25519 = Specifier{'e', 'd', '2', '5', '5', '1', '9'}

	ErrFrivolousSignature        = errors.New("transaction contains a frivolous signature")
	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")
)
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'}

	ErrInvalidTransactionVersion = errors.New("invalid transaction version")
	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 (
	// ErrUnexpectedUnlockCondition is returnd when a fulfillment is given
	// an UnlockCondition of an unexpected type.
	ErrUnexpectedUnlockCondition = errors.New("unexpected unlock condition")

	// ErrUnexpectedUnlockFulfillment is returnd when an UnlockCondition is given
	// an UnlockFulfillment of an unexpected type.
	ErrUnexpectedUnlockFulfillment = errors.New("unexpected unlock fulfillment")

	// ErrUnexpectedUnlockType is returned when an unlock hash has the wrong type.
	ErrUnexpectedUnlockType = errors.New("unexpected unlock (hash) type")

	// ErrFulfillmentDoubleSign is returned when a fulfillment that is already signed,
	// is attempted to be signed once again.
	ErrFulfillmentDoubleSign = errors.New("cannot sign a fulfillment which is already signed")

	// ErrUnknownConditionType is returned to define the non-standardness
	// of an UnknownUnlockCondition.
	ErrUnknownConditionType = errors.New("unknown condition type")
	// ErrUnknownFulfillmentType is returned to define the non-standardness
	// of an UnknownUnlockFulfillment.
	ErrUnknownFulfillmentType = errors.New("unknown fulfillment type")

	// ErrNilFulfillmentType is returned by pretty much any method of the
	// NilFullfilment type, as it is not to be used for anything.
	ErrNilFulfillmentType = errors.New("nil fulfillment type")

	// ErrUnknownSignAlgorithmType is an error returned in case
	// one tries to sign using an unknown signing algorithm type.
	//
	// NOTE That verification of unknown signing algorithm types does always succeed!
	ErrUnknownSignAlgorithmType = errors.New("unknown signature algorithm type")
)

Various errors returned by unlock conditions and fulfillments.

View Source
var (
	// ErrInvalidPreImageSha256 is returned as the result of a failed fulfillment,
	// in case the condition-defined hashed secret (pre image) does not match
	// the fulfillment-defined secret (image).
	ErrInvalidPreImageSha256 = errors.New("invalid pre-image sha256")
	// ErrInvalidRedeemer is returned in case the redeemer, one of two parties,
	// is the wrong redeemer due to the timelock rule.
	// Prior to the timelock only the receiver can redeem,
	// while after that timelock only the sender can redeem.
	ErrInvalidRedeemer = errors.New("invalid input redeemer")
)

Errors related to atomic swap validation.

View Source
var (
	ErrDoubleSpend         = errors.New("transaction uses a parent object twice")
	ErrNonZeroRevision     = errors.New("new file contract has a nonzero revision number")
	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")
)
View Source
var (
	// ErrUnexpectedExtensionType is an error returned by a transaction controller,
	// in case it expects an extention type it didn't expect.
	ErrUnexpectedExtensionType = errors.New("unexpected transaction data extension type")
)
View Source
var (
	ErrUnknownTransactionType = errors.New("unknown transaction type")
)

Functions

func RegisterTransactionVersion added in v1.0.5

func RegisterTransactionVersion(v TransactionVersion, c TransactionController)

RegisterTransactionVersion registers or unregisters a given transaction version, by attaching a controller to it that helps define the behavior surrounding its state.

NOTE: this function should only be called in the `init` func, doing it anywhere else can result in undefined behavior.

func RegisterUnlockConditionType added in v1.0.5

func RegisterUnlockConditionType(ct ConditionType, cc MarshalableUnlockConditionConstructor)

RegisterUnlockConditionType is used to register a condition type, by linking it to a constructor which constructs a fresh MarshalableUnlockCondition each time it is called.

RegisterUnlockConditionType can also used to unregister a condition type, by calling this funciton with nil as the MarshalableUnlockConditionConstructor.

func RegisterUnlockFulfillmentType added in v1.0.5

func RegisterUnlockFulfillmentType(ft FulfillmentType, fc MarshalableUnlockFulfillmentConstructor)

RegisterUnlockFulfillmentType is used to register a fulfillment type, by linking it to a constructor which constructs a fresh MarshalableUnlockFulfillment each time it is called.

RegisterUnlockFulfillmentType can also used to unregister a fulfillment type, by calling this funciton with nil as the MarshalableUnlockFulfillmentConstructor.

Types

type AtomicSwapCondition added in v0.6.0

type AtomicSwapCondition struct {
	Sender       UnlockHash             `json:"sender"`
	Receiver     UnlockHash             `json:"receiver"`
	HashedSecret AtomicSwapHashedSecret `json:"hashedsecret"`
	TimeLock     Timestamp              `json:"timelock"`
}

AtomicSwapCondition implements the ConditionTypeSingleSignature (unlock) ConditionType. See ConditionTypeSingleSignature for more information.

func (*AtomicSwapCondition) ConditionType added in v1.0.5

func (as *AtomicSwapCondition) ConditionType() ConditionType

ConditionType implements UnlockCondition.ConditionType

func (*AtomicSwapCondition) Equal added in v1.0.5

Equal implements UnlockCondition.Equal

func (*AtomicSwapCondition) Fulfill added in v1.0.5

func (as *AtomicSwapCondition) Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

Fulfill implements UnlockCondition.Fulfill

func (*AtomicSwapCondition) Fulfillable added in v1.0.5

func (as *AtomicSwapCondition) Fulfillable(FulfillableContext) bool

Fulfillable implements UnlockCondition.Fulfillable

func (*AtomicSwapCondition) IsStandardCondition added in v1.0.5

func (as *AtomicSwapCondition) IsStandardCondition() error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*AtomicSwapCondition) Marshal added in v1.0.5

func (as *AtomicSwapCondition) Marshal() []byte

Marshal implements MarshalableUnlockCondition.Marshal

func (*AtomicSwapCondition) UnlockHash added in v1.0.5

func (as *AtomicSwapCondition) UnlockHash() UnlockHash

UnlockHash implements UnlockCondition.UnlockHash

func (*AtomicSwapCondition) Unmarshal added in v1.0.5

func (as *AtomicSwapCondition) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockCondition.Unmarshal

type AtomicSwapFulfillment added in v0.6.0

type AtomicSwapFulfillment struct {
	PublicKey SiaPublicKey     `json:"publickey"`
	Signature ByteSlice        `json:"signature"`
	Secret    AtomicSwapSecret `json:"secret,omitempty"`
}

AtomicSwapFulfillment implements the (new) FulfillmentTypeAtomicSwap (unlock) FulfillmentType. See FulfillmentTypeAtomicSwap for more information.

func NewAtomicSwapClaimFulfillment added in v1.0.5

func NewAtomicSwapClaimFulfillment(pk SiaPublicKey, secret AtomicSwapSecret) *AtomicSwapFulfillment

NewAtomicSwapClaimFulfillment creates an unsigned atomic swap fulfillment, as to spend an output as a claim (meaning redeeming the money as the receiver).

Returned fulfillment still has to be signed, as to add the signature, with the parent transaction as the input as well as the matching private key.

Note that this fulfillment will fail if the current time is equal to or past the timestamp specified as time lock in the parent output.

func NewAtomicSwapRefundFulfillment added in v1.0.5

func NewAtomicSwapRefundFulfillment(pk SiaPublicKey) *AtomicSwapFulfillment

NewAtomicSwapRefundFulfillment creates an unsigned atomic swap fulfillment, as to get a refund (meaning redeeming the money as the sender).

Returned fulfillment still has to be signed, as to add the signature, with the parent transaction as the input as well as the matching private key.

Note that this fulfillment will fail if the current time is prior to the timestamp specified as time lock in the parent output.

func (*AtomicSwapFulfillment) AtomicSwapSecret added in v1.0.5

func (as *AtomicSwapFulfillment) AtomicSwapSecret() AtomicSwapSecret

AtomicSwapSecret returns the AtomicSwapSecret defined in this legacy fulfillmen

func (*AtomicSwapFulfillment) Equal added in v1.0.5

Equal implements UnlockFulfillment.Equal

func (*AtomicSwapFulfillment) FulfillmentType added in v1.0.5

func (as *AtomicSwapFulfillment) FulfillmentType() FulfillmentType

FulfillmentType implements UnlockFulfillment.FulfillmentType

func (*AtomicSwapFulfillment) IsStandardFulfillment added in v1.0.5

func (as *AtomicSwapFulfillment) IsStandardFulfillment() error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*AtomicSwapFulfillment) Marshal added in v1.0.5

func (as *AtomicSwapFulfillment) Marshal() []byte

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*AtomicSwapFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*AtomicSwapFulfillment) UnlockHash added in v1.0.5

func (as *AtomicSwapFulfillment) UnlockHash() UnlockHash

UnlockHash implements UnlockFulfillment.UnlockHash

func (*AtomicSwapFulfillment) Unmarshal added in v1.0.5

func (as *AtomicSwapFulfillment) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockFulfillment.Unmarshal

type AtomicSwapHashedSecret added in v0.6.0

type AtomicSwapHashedSecret [sha256.Size]byte

AtomicSwapHashedSecret defines the 256 image byte slice, used as hashed secret within the Atomic Swap protocol/contract.

func NewAtomicSwapHashedSecret added in v1.0.0

func NewAtomicSwapHashedSecret(secret AtomicSwapSecret) AtomicSwapHashedSecret

NewAtomicSwapHashedSecret creates a new atomic swap hashed secret, using a pre-generated atomic swap secret.

func (*AtomicSwapHashedSecret) LoadString added in v0.6.0

func (hs *AtomicSwapHashedSecret) LoadString(str string) error

LoadString loads a hashed secret from a hex-formatted string.

func (AtomicSwapHashedSecret) MarshalJSON added in v0.6.0

func (hs AtomicSwapHashedSecret) MarshalJSON() ([]byte, error)

MarshalJSON marshals a hashed secret as a hex string.

func (AtomicSwapHashedSecret) String added in v0.6.0

func (hs AtomicSwapHashedSecret) String() string

String turns this hashed secret into a hex-formatted string.

func (*AtomicSwapHashedSecret) UnmarshalJSON added in v0.6.0

func (hs *AtomicSwapHashedSecret) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json string of the hashed secret.

type AtomicSwapSecret added in v0.6.0

type AtomicSwapSecret [sha256.Size]byte

AtomicSwapSecret defines the 256 pre-image byte slice, used as secret within the Atomic Swap protocol/contract.

func NewAtomicSwapSecret added in v1.0.0

func NewAtomicSwapSecret() (ass AtomicSwapSecret, err error)

NewAtomicSwapSecret creates a new cryptographically secure atomic swap secret

func (*AtomicSwapSecret) LoadString added in v0.6.0

func (s *AtomicSwapSecret) LoadString(str string) error

LoadString loads a secret from a hex-formatted string.

func (AtomicSwapSecret) MarshalJSON added in v0.6.0

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

MarshalJSON marshals a secret as a hex string.

func (AtomicSwapSecret) String added in v0.6.0

func (s AtomicSwapSecret) String() string

String turns this secret into a hex-formatted string.

func (*AtomicSwapSecret) UnmarshalJSON added in v0.6.0

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

UnmarshalJSON decodes the json string of the secret.

type Block

type Block struct {
	ParentID     BlockID                 `json:"parentid"`
	Timestamp    Timestamp               `json:"timestamp"`
	POBSOutput   BlockStakeOutputIndexes `json:"pobsindexes"`
	MinerPayouts []MinerPayout           `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) CalculateTotalMinerFees added in v1.0.0

func (b Block) CalculateTotalMinerFees() Currency

CalculateTotalMinerFees determines the sum of the minerfees

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"`
	Fulfillment UnlockFulfillmentProxy `json:"fulfillment"`
}

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"`
	Condition UnlockConditionProxy `json:"condition"`
}

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) LoadString added in v0.6.0

func (bsoid *BlockStakeOutputID) LoadString(str string) error

LoadString loads the given blockstake output id from a hex string

func (BlockStakeOutputID) MarshalJSON

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

MarshalJSON marshals an blockstake output id as a hex string.

func (BlockStakeOutputID) String

func (bsoid BlockStakeOutputID) String() string

String prints the blockstake output id in hex.

func (*BlockStakeOutputID) UnmarshalJSON

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

UnmarshalJSON decodes the json hex string of the blockstake output 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 BlockchainInfo added in v0.6.0

type BlockchainInfo struct {
	Name            string
	ChainVersion    build.ProtocolVersion
	ProtocolVersion build.ProtocolVersion
}

BlockchainInfo contains information about a blockchain.

func DefaultBlockchainInfo added in v0.6.0

func DefaultBlockchainInfo() BlockchainInfo

DefaultBlockchainInfo returns the blockchain information for the default (Rivine) blockchain, using the version which is set as part of the build process.

type ByteSlice added in v0.6.0

type ByteSlice []byte

ByteSlice defines any kind of raw binary value, in-memory defined as a byte slice, and JSON-encoded in hexadecimal form.

func (*ByteSlice) LoadString added in v0.6.0

func (bs *ByteSlice) LoadString(str string) error

LoadString loads a byte slice from a hex-formatted string.

func (ByteSlice) MarshalJSON added in v0.6.0

func (bs ByteSlice) MarshalJSON() ([]byte, error)

MarshalJSON marshals a byte slice as a hex string.

func (ByteSlice) String added in v0.6.0

func (bs ByteSlice) String() string

String turns this byte slice into a hex-formatted string.

func (*ByteSlice) UnmarshalJSON added in v0.6.0

func (bs *ByteSlice) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json string of the byte slice.

type ChainConstants added in v0.6.0

type ChainConstants struct {
	// BlockSizeLimit is the maximum size a single block can have, in bytes
	BlockSizeLimit uint64
	RootDepth      Target
	// BlockFrequency is the average timespan between blocks, in seconds.
	// I.E.: On average, 1 block will be created every 1 in *BlockFrequency* seconds
	BlockFrequency BlockHeight
	// MaturityDelay is the amount of blocks for which a miner payout must "mature" before it
	// gets added to the consensus set. Until this time has passed, a miner payout cannot be spend
	MaturityDelay BlockHeight

	MedianTimestampWindow uint64

	// TargetWindow is the amount of blocks to go back to adjust the difficulty of the network.
	TargetWindow BlockHeight
	// MaxAdjustmentUp is the maximum multiplier to difficulty over the course of 500 blocks
	MaxAdjustmentUp *big.Rat
	// MaxAdjustmentDown is the minimum multiplier to the difficulty over the course of 500 blocks
	MaxAdjustmentDown *big.Rat
	// FutureThreshold is the amount of seconds that a block timestamp can be "in the future",
	// while stil being accepted by the consensus set. I.E. a block is accepted if:
	// 	block timestamp < current timestamp + future treshold
	// Blocks who's timestamp is bigger than this value will not be accepted, but they might be
	// recondisered as soon as their timestamp is within the future treshold
	FutureThreshold Timestamp
	// ExtremeFutureThreshold is the maximum amount of time a block timstamp can be in the future
	// before sais block is outright rejected. Blocks who's timestamp is between now + FutureThreshold
	// and now + ExtremeFutureThreshold are kept and retried as soon as their timestamp is lower than
	// now + FutureThreshold. In case the block timestamp is higher than now + ExtremeFutureThreshold, we
	// consider that the block will no longer be valid as soon as its timestamp becomes accepteable, the block
	// will no longer be on the longest chain. Also, we can't keep all the blocks to eventually verify this as that
	// opens up a DOS vector
	ExtremeFutureThreshold Timestamp

	// StakeModifierDelay is the amount of blocks to go back to start calculating the Stake Modifier,
	// which is used in the proof of blockstake protoco. The formula for the Stake Modifier is as follows:
	// 	For x = 0 .. 255
	// 	bit x of Stake Modifier = bit x of h(block N-(StakeModifierDelay+x))
	StakeModifierDelay BlockHeight
	// BlockStakeAging is the amount of seconds to wait before a blockstake output
	// which is not on index 0 in the first transaction of a block can be used to
	// participate in the proof of blockstake protocol
	BlockStakeAging uint64
	// BlockCreatorFee is the amount of hastings you get for creating a block on top of
	// all the other rewards such as collected transaction fees.
	BlockCreatorFee Currency

	// MinimumTransactionFee is the minimum amount of hastings you need to pay
	// in order to get your transaction to be accepted by block creators.
	MinimumTransactionFee Currency

	// TransactionFeeCondition allows you to define a static unlock hash which collects all transaction fees,
	// by default it is undefined, meaning the transaction fee will go to the creator of the relevant block.
	TransactionFeeCondition UnlockConditionProxy

	// GenesisTimestamp is the unix timestamp of the genesis block
	GenesisTimestamp Timestamp
	// GenesisBlockStakeAllocation are the blockstake outputs of the genesis block
	GenesisBlockStakeAllocation []BlockStakeOutput
	// GenesisCoinDistribution are the coin outputs of the genesis block
	GenesisCoinDistribution []CoinOutput

	// GenesisTransactionVersion defines the transaction versions to be used
	// for the transaction of the genesis block.
	GenesisTransactionVersion TransactionVersion

	// DefaultTransactionVersion defines the default transaction to be used
	// for all to be created transactions. It does not impact how transactions are validated or understood.
	DefaultTransactionVersion TransactionVersion

	CurrencyUnits CurrencyUnits
}

ChainConstants is a utility struct which groups together the chain configuration

func DefaultChainConstants added in v0.6.0

func DefaultChainConstants() ChainConstants

DefaultChainConstants provide sane defaults for a new chain. Not all constants are set, since some (e.g. GenesisTimestamp) are chain specific, and this also allows some santiy checking later GenesisTimestamp, GenesisBlockStakeAllocation, and GenesisCoinDistribution aren't set as there is no such thing as a "sane default" for these variables since they are really chain specific

func (*ChainConstants) GenesisBlock added in v0.6.0

func (c *ChainConstants) GenesisBlock() Block

GenesisBlock returns the genesis block based on the blockchain config

func (*ChainConstants) GenesisBlockID added in v0.6.0

func (c *ChainConstants) GenesisBlockID() BlockID

GenesisBlockID returns the ID of the genesis Block

func (*ChainConstants) GenesisBlockStakeCount added in v0.6.0

func (c *ChainConstants) GenesisBlockStakeCount() (bsc Currency)

GenesisBlockStakeCount computes and returns the total amount of block stakes allocated in the genesis block.

func (*ChainConstants) GenesisCoinCount added in v0.6.0

func (c *ChainConstants) GenesisCoinCount() (cc Currency)

GenesisCoinCount computes and returns the total amount of coins distributed in the genesis block.

func (*ChainConstants) RootTarget added in v0.6.0

func (c *ChainConstants) RootTarget() Target

RootTarget computes the new target, based on the root depth and the computed start difficulty

func (*ChainConstants) StartDifficulty added in v0.6.0

func (c *ChainConstants) StartDifficulty() Difficulty

StartDifficulty computes the start difficulty based on the set block frequency, and the computer genesis block stake count.

func (*ChainConstants) Validate added in v0.6.0

func (c *ChainConstants) Validate() error

Validate does a sanity check on some of the constants to see if proper initialization is done

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"`
	Fulfillment UnlockFulfillmentProxy `json:"fulfillment"`
}

A CoinInput consumes a CoinInput and adds the coins to the set of coins 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"`
	Condition UnlockConditionProxy `json:"condition"`
}

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) LoadString added in v0.6.0

func (coid *CoinOutputID) LoadString(str string) error

LoadString loads the given coin output id from a hex string

func (CoinOutputID) MarshalJSON added in v0.1.0

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

MarshalJSON marshals an coin output id as a hex string.

func (CoinOutputID) String added in v0.1.0

func (coid CoinOutputID) String() string

String prints the coin output id in hex.

func (*CoinOutputID) UnmarshalJSON added in v0.1.0

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

UnmarshalJSON decodes the json hex string of the coin output id.

type ConditionType added in v1.0.5

type ConditionType byte

ConditionType defines the type of a condition.

const (
	// ConditionTypeNil defines the nil condition,
	// meaning it explicitly defines that the output can be used by anyone.
	// Whoever claims the output as input does have to sign the input,
	// using SingleSignatureFulfillment.
	//
	// Implemented by the NilCondition type.
	ConditionTypeNil ConditionType = iota
	// ConditionTypeUnlockHash defines a condition which is to be unlocked,
	// by a fulfillment which produces the specified unlock hash.
	//
	// Depending upon the unlock type of the specified unlock hash,
	// a different type of fulfillment can fulfill this condition.
	// If the hash's unlock type is a UnlockTypePubKey,
	// it can be fulfilled by a SingleSignatureFulfillment.
	// If the hash's unlock type is a UnlockTypeAtomicSwap,
	// it can be fulfilled by a LegacyAtomicSwapFulfillment.
	// No other unlock type is supported by this unlock condition.
	//
	// Implemented by the UnlockHashCondition type.
	ConditionTypeUnlockHash
	// ConditionTypeAtomicSwap defines the (new) atomic swap condition,
	// replacing the legacy UnlockHash-based atomic swap condition.
	// It can be fulfilled only by an AtomicSwapFulfillment.
	//
	// Implemented by the AtomicSwapCondition type.
	ConditionTypeAtomicSwap

	// ConditionTypeTimeLock defines an unlock condition
	// which locks another condition with a timestamp.
	// The internal condition has to be one of: [
	// NilCondition,
	// UnlockHashCondition(0x01 unlock hash type is the only standard one at the moment, others are always fulfilled),
	// ]
	ConditionTypeTimeLock
)

The following enumeration defines the different possible and standard unlock conditions. All are defined by an implementation of MarshalableUnlockCondition.

func (ConditionType) MarshalSia added in v1.0.5

func (ct ConditionType) MarshalSia(w io.Writer) error

MarshalSia implements encoding.SiaMarshaler.MarshalSia

Marshals this ConditionType as a single byte.

func (*ConditionType) UnmarshalSia added in v1.0.5

func (ct *ConditionType) UnmarshalSia(r io.Reader) error

UnmarshalSia implements encoding.SiaUnmarshaler.UnmarshalSia

Unmarshals this ConditionType from a single byte.

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) Cmp64 added in v0.6.0

func (x Currency) Cmp64(y uint64) int

Cmp64 compares x to a uint64. 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) Equals added in v0.6.0

func (x Currency) Equals(y Currency) bool

Equals returns true if x and y have the same value.

func (Currency) Equals64 added in v0.6.0

func (x Currency) Equals64(y uint64) bool

Equals64 returns true if x and y have the same value.

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 CurrencyUnits added in v0.6.0

type CurrencyUnits struct {
	// OneCoin is the size of a "coin", making it possible to split a coin up if wanted
	OneCoin Currency
}

CurrencyUnits defines the units used for the different kind of currencies.

func DefaultCurrencyUnits added in v0.6.0

func DefaultCurrencyUnits() CurrencyUnits

DefaultCurrencyUnits provides sane defaults for currency units

type DefaultTransactionController added in v1.0.5

type DefaultTransactionController struct{}

DefaultTransactionController is the default transaction controller used, and is also by default the controller for the default transaction version 0x01.

func (DefaultTransactionController) DecodeTransactionData added in v1.0.5

func (dtc DefaultTransactionController) DecodeTransactionData(b []byte) (td TransactionData, err error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (DefaultTransactionController) EncodeTransactionData added in v1.0.5

func (dtc DefaultTransactionController) EncodeTransactionData(td TransactionData) ([]byte, error)

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (DefaultTransactionController) JSONDecodeTransactionData added in v1.0.5

func (dtc DefaultTransactionController) JSONDecodeTransactionData(b []byte) (td TransactionData, err error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (DefaultTransactionController) JSONEncodeTransactionData added in v1.0.5

func (dtc DefaultTransactionController) JSONEncodeTransactionData(td TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

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 FulfillContext added in v1.0.5

type FulfillContext struct {
	// Index of the input that is to be fulfilled,
	// whether that input is a coin- or blockStake- input is of no importance.
	InputIndex uint64
	// BlockHeight of the currently last registered block.
	BlockHeight BlockHeight
	// BlockTime defines the time of the currently last registered block,
	// the transaction belonged to.
	BlockTime Timestamp
	// (Parent) transaction the fulfillment belongs to.
	Transaction Transaction
}

FulfillContext is given as part of the fulfill call of an UnlockCondition, as to provide the necessary context required for fulfilling a fulfillment.

type FulfillableContext added in v1.0.5

type FulfillableContext struct {
	// BlockHeight of the currently last registered block.
	BlockHeight BlockHeight
	// BlockTime defines the time of the currently last registered block,
	// the transaction belonged to.
	BlockTime Timestamp
}

FulfillableContext is given as part of the fulfillable call of an UnlockCondition, as to provide the necessary context required for fulfilling a fulfillment.

type FulfillmentSignContext added in v1.0.5

type FulfillmentSignContext struct {
	// Index of the input that is to be signed,
	// whether that input is a coin- or blockStake- input is of no importance.
	InputIndex uint64
	// (Parent) transaction the fulfillment belongs to.
	//
	// It is expected that all properties of this transactions
	// are defined at this point, even though it is allowed that one or multiple
	// inputs haven't been signed yet, and this should have no influence on the signature.
	Transaction Transaction
	// (Private) key to be used for signing, what type it is or whether it is defined at all
	// is of no importance, as long as the fulfillment supports its (none) definition.
	Key interface{}
}

FulfillmentSignContext is given as part of the sign call of an UnlockFullment, as to provide the necessary context required for signing a fulfillment.

type FulfillmentType added in v1.0.5

type FulfillmentType byte

FulfillmentType defines the type of a fulfillment.

const (
	// FulfillmentTypeNil defines the nil fulfillment,
	// and cannot fulfill any condition. It only serves as the nil-fulfillment,
	// which is the default value for a fulfillment type, should none be given.
	// It is considered non-standard.
	//
	// A NilCondition is fulfilled by the SingleSignatureFulfillment,
	// not the NilFulfillment. This as to ensure all fulfillments are secured by a signature,
	// as a protection against tampering.
	//
	// Implemented by the NilFulfillment type.
	FulfillmentTypeNil FulfillmentType = iota
	// FulfillmentTypeSingleSignature defines the single signature fulfillment,
	// and is defined by a public key, matching a private key which is used to
	// produce the given transaction-based signature.
	//
	// It is used to fulfill UnlockHashConditions which are described using an unlock hash
	// of type UnlockTypePubKey, as well as NilConditions.
	//
	// Implemented by the SingleSignatureFulfillment type.
	FulfillmentTypeSingleSignature
	// FulfillmentTypeAtomicSwap defines both the legacy as well as the new
	// AtomicSwapFulfillment. Whether the fulfillemnt is of the legacy or the latter type,
	// depends upon the properties that are defined as part of the fulfillment.
	//
	// In legacy mode it is used to fulfill UnlockHashConditions which are described using
	// an unlock hash of type UnlockTypeAtomicSwap. While the (new) atomic swap fulfillments
	// are used to fulfill AtomicSwapConditions.
	//
	// Implemented by the AtomicSwapFulfillment.
	FulfillmentTypeAtomicSwap
)

The following enumeration defines the different possible and standard unlock fulfillments. All are defined by an implementation of MarshalableUnlockFulfillment.

func (FulfillmentType) MarshalSia added in v1.0.5

func (ft FulfillmentType) MarshalSia(w io.Writer) error

MarshalSia implements encoding.Marshaler.MarshalSia

Marshals this FulfillmentType as a single byte.

func (*FulfillmentType) UnmarshalSia added in v1.0.5

func (ft *FulfillmentType) UnmarshalSia(r io.Reader) error

UnmarshalSia implements encoding.Unmarshaler.UnmarshalSia

Unmarshals this FulfillmentType from a single byte.

type InputSigHasher added in v1.0.3

type InputSigHasher interface {
	InputSigHash(t Transaction, inputIndex uint64, extraObjects ...interface{}) crypto.Hash
}

InputSigHasher defines the interface a transaction controller can optionally implement, in order to define custom Input signatures, overwriting the default input sig hash logic.

type LegacyAtomicSwapFulfillment added in v1.0.5

type LegacyAtomicSwapFulfillment struct {
	Sender       UnlockHash             `json:"sender"`
	Receiver     UnlockHash             `json:"receiver"`
	HashedSecret AtomicSwapHashedSecret `json:"hashedsecret"`
	TimeLock     Timestamp              `json:"timelock"`
	PublicKey    SiaPublicKey           `json:"publickey"`
	Signature    ByteSlice              `json:"signature"`
	Secret       AtomicSwapSecret       `json:"secret,omitempty"`
}

LegacyAtomicSwapFulfillment implements the (legacy) FulfillmentTypeAtomicSwap (unlock) FulfillmentType. See FulfillmentTypeAtomicSwap for more information.

func (*LegacyAtomicSwapFulfillment) AtomicSwapSecret added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) AtomicSwapSecret() AtomicSwapSecret

AtomicSwapSecret returns the AtomicSwapSecret defined in this legacy fulfillment.

func (*LegacyAtomicSwapFulfillment) Equal added in v1.0.5

Equal implements UnlockFulfillment.Equal

func (*LegacyAtomicSwapFulfillment) FulfillmentType added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) FulfillmentType() FulfillmentType

FulfillmentType implements UnlockFulfillment.FulfillmentType

func (*LegacyAtomicSwapFulfillment) IsStandardFulfillment added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) IsStandardFulfillment() error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*LegacyAtomicSwapFulfillment) Marshal added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) Marshal() []byte

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*LegacyAtomicSwapFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*LegacyAtomicSwapFulfillment) UnlockHash added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) UnlockHash() UnlockHash

UnlockHash implements UnlockFulfillment.UnlockHash

func (*LegacyAtomicSwapFulfillment) Unmarshal added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockFulfillment.Unmarshal

type MarshalableUnlockCondition added in v1.0.5

type MarshalableUnlockCondition interface {
	UnlockCondition

	// Marshal this UnlockCondition into a binary format.
	// The returned byte slice should be usable in order
	// to recreate the same unlock condition using the paired
	// Unmarshal method.
	Marshal() []byte
	// Unmarshal this unlock condition from a binary format,
	// the whole byte slice is expected to be used.
	Unmarshal([]byte) error
}

MarshalableUnlockCondition adds binary marshaling as a required interface to the regular unlock condition interface. This allows the condition to be used as an internal condition of an UnlockConditionProxy.

NOTE: it is also expected that an implementation implementing this interface, supports JSON marshaling/unmarshaling, whether this is implicit through tags, or explicit by implementing the relevant JSON interfaces is of no importance. This is however not enforced, even though it is expected.

type MarshalableUnlockConditionConstructor added in v1.0.5

type MarshalableUnlockConditionConstructor func() MarshalableUnlockCondition

MarshalableUnlockConditionConstructor defines a constructor type, which is expected to construct a new MarshalableUnlockCondition each time it is called.

type MarshalableUnlockFulfillment added in v1.0.5

type MarshalableUnlockFulfillment interface {
	UnlockFulfillment

	// Marshal this UnlockFulfillment into a binary format.
	// The returned byte slice should be usable in order
	// to recreate the same unlock fulfillment using the paired
	// Unmarshal method.
	Marshal() []byte
	// Unmarshal this unlock fulfillment from a binary format,
	// the whole byte slice is expected to be used.
	Unmarshal([]byte) error
}

MarshalableUnlockFulfillment adds binary marshaling as a required interface to the regular unlock fulfillment interface. This allows the fulfillment to be used as an internal fulfillment of an UnlockFulfillmentProxy.

NOTE: it is also expected that an implementation implementing this interface, supports JSON marshaling/unmarshaling, whether this is implicit through tags, or explicit by implementing the relevant JSON interfaces is of no importance. This is however not enforced, even though it is expected.

type MarshalableUnlockFulfillmentConstructor added in v1.0.5

type MarshalableUnlockFulfillmentConstructor func() MarshalableUnlockFulfillment

MarshalableUnlockFulfillmentConstructor defines a constructor type, which is expected to construct a new MarshalableUnlockFulfillment each time it is called.

type MinerPayout added in v1.0.5

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

MinerPayout defines a miner payout, as (to be) payed out, as orchestrated by this block's transactions.

It is a structure created as to keep the Block Structure unchanged, to how it used to be.

type NilCondition added in v1.0.5

type NilCondition struct{} // can only be fulfilled by a SingleSignatureFulfillment

NilCondition implements the ConditionTypeNil (unlock) ConditionType. See ConditionTypeNil for more information.

func (*NilCondition) ConditionType added in v1.0.5

func (n *NilCondition) ConditionType() ConditionType

ConditionType implements UnlockCondition.ConditionType

func (*NilCondition) Equal added in v1.0.5

func (n *NilCondition) Equal(c UnlockCondition) bool

Equal implements UnlockCondition.Equal

func (*NilCondition) Fulfill added in v1.0.5

func (n *NilCondition) Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

Fulfill implements UnlockCondition.Fulfill

func (*NilCondition) Fulfillable added in v1.0.5

func (n *NilCondition) Fulfillable(FulfillableContext) bool

Fulfillable implements UnlockCondition.Fulfillable

func (*NilCondition) IsStandardCondition added in v1.0.5

func (n *NilCondition) IsStandardCondition() error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*NilCondition) Marshal added in v1.0.5

func (n *NilCondition) Marshal() []byte

Marshal implements MarshalableUnlockCondition.Marshal

func (*NilCondition) UnlockHash added in v1.0.5

func (n *NilCondition) UnlockHash() UnlockHash

UnlockHash implements UnlockCondition.UnlockHash

func (*NilCondition) Unmarshal added in v1.0.5

func (n *NilCondition) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockCondition.Unmarshal

type NilFulfillment added in v1.0.5

type NilFulfillment struct{} // invalid fulfillment

NilFulfillment implements the FulfillmentTypeNil (unlock) FulfillmentType. See FulfillmentTypeNil for more information.

func (*NilFulfillment) Equal added in v1.0.5

Equal implements UnlockFulfillment.Equal

func (*NilFulfillment) FulfillmentType added in v1.0.5

func (n *NilFulfillment) FulfillmentType() FulfillmentType

FulfillmentType implements UnlockFulfillment.FulfillmentType

func (*NilFulfillment) IsStandardFulfillment added in v1.0.5

func (n *NilFulfillment) IsStandardFulfillment() error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*NilFulfillment) Marshal added in v1.0.5

func (n *NilFulfillment) Marshal() []byte

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*NilFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*NilFulfillment) UnlockHash added in v1.0.5

func (n *NilFulfillment) UnlockHash() UnlockHash

UnlockHash implements UnlockFulfillment.UnlockHash

func (*NilFulfillment) Unmarshal added in v1.0.5

func (n *NilFulfillment) Unmarshal([]byte) error

Unmarshal implements MarshalableUnlockFulfillment.Unmarshal

type OutputID

type OutputID crypto.Hash

func (*OutputID) LoadString added in v0.6.0

func (oid *OutputID) LoadString(str string) error

LoadString loads the given output id from a hex string

func (OutputID) MarshalJSON

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

MarshalJSON marshals an output id as a hex string.

func (OutputID) String

func (oid OutputID) String() string

String prints the output id in hex.

func (*OutputID) UnmarshalJSON

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

UnmarshalJSON decodes the json hex string of the output id.

type SiaPublicKey

type SiaPublicKey struct {
	Algorithm Specifier
	Key       ByteSlice
}

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 Ed25519PublicKey added in v0.6.0

func Ed25519PublicKey(pk crypto.PublicKey) SiaPublicKey

Ed25519PublicKey returns pk as a SiaPublicKey, denoting its algorithm as Ed25519.

func (*SiaPublicKey) LoadString added in v0.6.0

func (spk *SiaPublicKey) LoadString(s string) error

LoadString is the inverse of SiaPublicKey.String().

func (SiaPublicKey) MarshalJSON added in v0.6.0

func (spk SiaPublicKey) MarshalJSON() ([]byte, error)

MarshalJSON marshals a byte slice as a hex string.

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.

func (*SiaPublicKey) UnmarshalJSON added in v0.6.0

func (spk *SiaPublicKey) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json string of the byte slice.

type SingleSignatureFulfillment added in v1.0.5

type SingleSignatureFulfillment struct {
	PublicKey SiaPublicKey `json:"publickey"`
	Signature ByteSlice    `json:"signature"`
}

SingleSignatureFulfillment implements the FulfillmentTypeSingleSignature (unlock) FulfillmentType. See FulfillmentTypeSingleSignature for more information.

func NewSingleSignatureFulfillment added in v1.0.5

func NewSingleSignatureFulfillment(pk SiaPublicKey) *SingleSignatureFulfillment

NewSingleSignatureFulfillment creates an unsigned SingleSignatureFulfillment, using the given Public Key, which is to be matched with the private key given as part of the later sign call to the returned instance.

func (*SingleSignatureFulfillment) Equal added in v1.0.5

Equal implements UnlockFulfillment.Equal

func (*SingleSignatureFulfillment) FulfillmentType added in v1.0.5

func (ss *SingleSignatureFulfillment) FulfillmentType() FulfillmentType

FulfillmentType implements UnlockFulfillment.FulfillmentType

func (*SingleSignatureFulfillment) IsStandardFulfillment added in v1.0.5

func (ss *SingleSignatureFulfillment) IsStandardFulfillment() error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*SingleSignatureFulfillment) Marshal added in v1.0.5

func (ss *SingleSignatureFulfillment) Marshal() []byte

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*SingleSignatureFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*SingleSignatureFulfillment) UnlockHash added in v1.0.5

func (ss *SingleSignatureFulfillment) UnlockHash() UnlockHash

UnlockHash implements UnlockFulfillment.UnlockHash

func (*SingleSignatureFulfillment) Unmarshal added in v1.0.5

func (ss *SingleSignatureFulfillment) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockFulfillment.Unmarshal

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) LoadString added in v0.6.0

func (s *Specifier) LoadString(str string) error

LoadString loads a stringified specifier into the specifier type

func (Specifier) MarshalJSON

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

MarshalJSON marshals a specifier as a string.

func (Specifier) String

func (s Specifier) String() string

String returns the specifier as a string, trimming any trailing zeros.

func (*Specifier) UnmarshalJSON

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

UnmarshalJSON decodes the json string of the specifier.

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, rootDepth Target) (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, depth Target) Target

NewTarget makes a new target from a given difficulty with a given root depth

func RatToTarget

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

RatToTarget converts a big.Rat to a Target.

func (Target) AddDifficulties

func (x Target) AddDifficulties(y Target, rootDepth 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(rootDepth Target) 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, rootDepth Target) (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, rootDepth 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 TimeLockCondition added in v1.0.5

type TimeLockCondition struct {
	// LockTime defines either a block height or a timestamp.
	// If the value is less than LockTimeMinTimestampValue it is concidered a lock based on block height,
	// otherwise it is used as a unix epoch value expressed in seconds.
	LockTime uint64
	// Condition defines the condition which has to be fulfilled
	// on top of the LockTime condition defined by this condition.
	// See ConditionTypeTimeLock in order to know which conditions are supported.
	Condition MarshalableUnlockCondition
}

TimeLockCondition defines an unlock condition which require a LockTime to be reached on top of some other defined condition, which both have to be fulfilled in order to unlock/spend/use the unspend output as an input.

func NewTimeLockCondition added in v1.0.5

func NewTimeLockCondition(lockTime uint64, condition MarshalableUnlockCondition) *TimeLockCondition

NewTimeLockCondition creates a new TimeLockCondition. If no MarshalableUnlockCondition is given, the NilCondition is assumed.

func (*TimeLockCondition) ConditionType added in v1.0.5

func (tl *TimeLockCondition) ConditionType() ConditionType

ConditionType implements UnlockCondition.ConditionType

func (*TimeLockCondition) Equal added in v1.0.5

func (tl *TimeLockCondition) Equal(c UnlockCondition) bool

Equal implements UnlockCondition.Equal

func (*TimeLockCondition) Fulfill added in v1.0.5

func (tl *TimeLockCondition) Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

Fulfill implements UnlockFulfillment.Fulfill

The TimeLockFulfillment can only be used to fulfill a TimeLockCondition.

func (*TimeLockCondition) Fulfillable added in v1.0.5

func (tl *TimeLockCondition) Fulfillable(ctx FulfillableContext) bool

Fulfillable implements UnlockCondition.Fulfillable

func (*TimeLockCondition) IsStandardCondition added in v1.0.5

func (tl *TimeLockCondition) IsStandardCondition() error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*TimeLockCondition) Marshal added in v1.0.5

func (tl *TimeLockCondition) Marshal() []byte

Marshal implements MarshalableUnlockCondition.Marshal

func (*TimeLockCondition) MarshalJSON added in v1.0.5

func (tl *TimeLockCondition) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.MarshalJSON

This function is required, as to ensure the underlying properties are properly serialized, including the type of the internal condition.

func (*TimeLockCondition) UnlockHash added in v1.0.5

func (tl *TimeLockCondition) UnlockHash() UnlockHash

UnlockHash implements UnlockCondition.UnlockHash

func (*TimeLockCondition) Unmarshal added in v1.0.5

func (tl *TimeLockCondition) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockCondition.Unmarshal

func (*TimeLockCondition) UnmarshalJSON added in v1.0.5

func (tl *TimeLockCondition) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON

This function is required, as to be able to unmarshal the internal condition based on the encoded condition type.

type Timestamp

type Timestamp uint64

func CurrentTimestamp

func CurrentTimestamp() Timestamp

CurrentTimestamp returns the current time as a Timestamp.

func OffsetTimestamp added in v0.6.0

func OffsetTimestamp(offset time.Duration) Timestamp

CurrentTimestamp returns the offset based on the current time as a Timestamp.

func (*Timestamp) LoadString added in v1.0.0

func (t *Timestamp) LoadString(str string) error

func (Timestamp) String added in v0.6.0

func (t Timestamp) String() string

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 {
	// Version of the transaction.
	Version TransactionVersion

	// Core data of a transaction,
	// as expected by the rivine protocol,
	// and will always be available, defined or not.
	CoinInputs        []CoinInput
	CoinOutputs       []CoinOutput
	BlockStakeInputs  []BlockStakeInput
	BlockStakeOutputs []BlockStakeOutput
	MinerFees         []Currency
	ArbitraryData     []byte

	// can adhere any (at once) of {TransactionDataEncoder, TransactionValidator, InputSigHasher},
	// or simply be nil.
	//
	// It is to be used to allow the transactions to take whatever logic and shape
	// as it requires to be, without the rest of the code having to wory about that.
	Extension interface{}
}

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() (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) InputSigHash added in v0.6.0

func (t Transaction) InputSigHash(inputIndex uint64, extraObjects ...interface{}) crypto.Hash

InputSigHash returns the hash of all fields in a transaction, relevant to an input sig.

func (Transaction) IsStandardTransaction added in v1.0.3

func (t Transaction) IsStandardTransaction() error

IsStandardTransaction returns an error if this transaction is not to be considered standard.

func (Transaction) MarshalJSON added in v0.6.0

func (t Transaction) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Transaction) MarshalSia added in v0.6.0

func (t Transaction) MarshalSia(w io.Writer) error

MarshalSia implements the encoding.SiaMarshaler interface.

func (*Transaction) UnmarshalJSON added in v0.6.0

func (t *Transaction) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Transaction) UnmarshalSia added in v0.6.0

func (t *Transaction) UnmarshalSia(r io.Reader) error

UnmarshalSia implements the encoding.SiaUnmarshaler interface.

func (Transaction) ValidateTransaction added in v1.0.3

func (t Transaction) ValidateTransaction(blockSizeLimit uint64) error

ValidateTransaction validates this transaction in the given context.

type TransactionController added in v1.0.5

type TransactionController interface {
	// EncodeTransactionData binary-encodes the transaction data,
	// which is all transaction properties except for the version.
	EncodeTransactionData(TransactionData) ([]byte, error)
	// DecodeTransactionData binary-decodes the transaction data,
	// which is all transaction properties except for the version.
	DecodeTransactionData([]byte) (TransactionData, error)

	// JSONEncodeTransactionData JSON-encodes the transaction data,
	// which is all transaction properties except for the version.
	JSONEncodeTransactionData(TransactionData) ([]byte, error)
	// JSONDecodeTransactionData JSON-decodes the transaction data,
	// which is all transaction properties except for the version.
	JSONDecodeTransactionData([]byte) (TransactionData, error)
}

TransactionController is the required interface that has to be implemented for each registered transaction version.

Besides the required interface, a transaction controller can also implement one or multiple supported extension interfaces supported by this lib.

type TransactionData added in v1.0.5

type TransactionData struct {
	CoinInputs        []CoinInput        `json:"coininputs"` // required
	CoinOutputs       []CoinOutput       `json:"coinoutputs,omitempty"`
	BlockStakeInputs  []BlockStakeInput  `json:"blockstakeinputs,omitempty"`
	BlockStakeOutputs []BlockStakeOutput `json:"blockstakeoutputs,omitempty"`
	MinerFees         []Currency         `json:"minerfees"` // required
	ArbitraryData     []byte             `json:"arbitrarydata,omitempty"`

	// Extension is an optional field that can be used,
	// in order to attach non-standard state to a transaction.
	Extension interface{} `json:"-"` // omited from JSON
}

TransactionData contains all the core data of a transaction, which is all data except for the version.

Extension is never binary/json encoded/decoded.

func (TransactionData) MarshalSia added in v1.0.5

func (td TransactionData) MarshalSia(w io.Writer) error

MarshalSia implements encoding.SiaMarshaller.MarshalSia

func (*TransactionData) UnmarshalSia added in v1.0.5

func (td *TransactionData) UnmarshalSia(r io.Reader) error

UnmarshalSia implements encoding.SiaUnmarshaller.UnmarshalSia

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) LoadString added in v0.6.0

func (tid *TransactionID) LoadString(str string) error

LoadString loads the given transaction ID from a hex string

func (TransactionID) MarshalJSON

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

MarshalJSON marshals 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 TransactionIsStandardChecker added in v1.0.5

type TransactionIsStandardChecker interface {
	IsStandardTransaction(t Transaction) error
}

TransactionIsStandardChecker defines the interface a transaction controller can optionally implement, in order to define logic, which defines if a transaction is to be concidered standard.

type TransactionShortID added in v0.6.0

type TransactionShortID uint64

TransactionShortID is another way to uniquely identify a transaction, just as the default hash-based (32-byte) ID uniquely identifies a transaction as well. The differences with the default/long ID is that it is 4 times smaller (only 8 bytes), and is not just unique, but also ordered. Meaning that byte-wise, this short ID informs about its position within the blockchain, on such a precise level that you not only to which block it belongs, but also its position within that transaction.

The position (indicated by the transaction index), is obviously not as important as it is more of a client-side choice, rather something agreed upon by consensus.

In memory the transaction is used and manipulated as a uint64, where the first 50 bits (going from left to right), define the block height, which can have a maximum of about 1.126e+15 (2^50) blocks, and the last 14 bits (again going from left to right), define the transaction sequence ID, or in other words, its unique and shorted position within a given block. When serialized into a binary (byte slice) format, is done so using LittleEndian, as to correctly preserve the sorted property in all cases. Meaning that the ID can be represented in memory and in serialized form as follows:

[ blockHeight: 50 bits | txSequenceID: 14 bits ]

func NewTransactionShortID added in v0.6.0

func NewTransactionShortID(height BlockHeight, txSequenceID uint16) TransactionShortID

NewTransactionShortID creates a new Transaction ShortID, combining a blockheight together with a transaction index. See the TransactionShortID type for more information.

func (TransactionShortID) BlockHeight added in v0.6.0

func (txsid TransactionShortID) BlockHeight() BlockHeight

BlockHeight returns the block height part of the transacton short ID.

func (TransactionShortID) MarshalSia added in v0.6.0

func (txsid TransactionShortID) MarshalSia(w io.Writer) error

MarshalSia implements SiaMarshaler.SiaMarshaler

func (TransactionShortID) TransactionSequenceIndex added in v0.6.0

func (txsid TransactionShortID) TransactionSequenceIndex() uint16

TransactionSequenceIndex returns the transaction sequence index, which is the local (sequence) index of the transaction within a block, of the transacton short ID.

func (*TransactionShortID) UnmarshalSia added in v0.6.0

func (txsid *TransactionShortID) UnmarshalSia(r io.Reader) error

UnmarshalSia implements SiaMarshaler.UnmarshalSia

type TransactionValidator added in v1.0.3

type TransactionValidator interface {
	ValidateTransaction(t Transaction, blockSizeLimit uint64) error
}

TransactionValidator defines the interface a transaction controller can optonally implement, in order to define custom validation logic for a transaction, overwriting the default validation logic.

type TransactionVersion added in v0.6.0

type TransactionVersion byte

TransactionVersion defines the format version of a transaction. However in the future we might wish to support one or multiple new formats, which will be identifable during encoding/decoding by this version number.

const (
	// TransactionVersionZero defines the initial (and currently only)
	// version format. Any other version number is concidered invalid.
	TransactionVersionZero TransactionVersion = iota
	TransactionVersionOne
)

func (TransactionVersion) IsValidTransactionVersion added in v1.0.5

func (v TransactionVersion) IsValidTransactionVersion() error

IsValidTransactionVersion returns an error in case the transaction version is not 0, and isn't registered either.

func (TransactionVersion) MarshalSia added in v0.6.0

func (v TransactionVersion) MarshalSia(w io.Writer) error

MarshalSia implements SiaMarshaler.MarshalSia

func (*TransactionVersion) UnmarshalSia added in v0.6.0

func (v *TransactionVersion) UnmarshalSia(r io.Reader) error

UnmarshalSia implements SiaUnmarshaler.UnmarshalSia

type UnlockCondition added in v1.0.5

type UnlockCondition interface {
	// Fulfill this condition using the given fulfillment, if supported,
	// within the given (fulfill) context.
	// An error is to be returned in case the given UnlockFulfillment
	// cannot fulfill the UnlockCondition (within the given context).
	Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

	// ConditionType returns the condition type of the UnlockCondtion.
	ConditionType() ConditionType
	// IsStandardCondtion returns if this (unlock) condition is standard.
	// An error result means it is not standard,
	// and it will consequently prevent the transaction, which includes the
	// the output that has this condition, from being minted into a block.
	IsStandardCondition() error

	// UnlockHash returns the deterministic unlock hash of this UnlockCondition.
	// It identifies the owner(s) or contract which own the output,
	// and can spend it, once the conditions becomes `Fulfillable`.
	UnlockHash() UnlockHash

	// Equal returns if the given unlock condition
	// equals the called unlock condition.
	Equal(UnlockCondition) bool

	// Fulfillable returns true if the unlock condition can be fullfilled,
	// should the right fulfillment be given with the same (fulfill)
	// context as given.
	//
	// NOTE: that this method does assume that the condition is a standard condition.
	Fulfillable(FulfillableContext) bool
}

UnlockCondition defines the condition that has to be fulfilled using a UnlockFulfillment which supports the implemented unlock condition.

An UnlockCondition can be used/supported by multiple UnlockFulfillments.

An unlock condtion will be propagated even when it is non-standard, but in that case it will not be minted into a block, unless a (block) creator sees it as standard.

type UnlockConditionProxy added in v1.0.5

type UnlockConditionProxy struct {
	Condition MarshalableUnlockCondition
}

UnlockConditionProxy wraps around a (binary/json) marshalable UnlockCondition, as to allow implicit nil conditions, as well as implicit and universal json/binary unmarshaling and binary marshaling.

func NewCondition added in v1.0.5

NewCondition creates an optional unlock condition, using an optionally given MarshalableUnlockCondition.

func (UnlockConditionProxy) ConditionType added in v1.0.5

func (up UnlockConditionProxy) ConditionType() ConditionType

ConditionType implements UnlockCondition.ConditionType

ConditionType returns the ConditionType of the child UnlockCondition. If no child is defined, a NilCondition is assumed.

func (UnlockConditionProxy) Equal added in v1.0.5

Equal implements UnlockCondition.Equal

If no child is defined, the given UnlockCondition will be compared to the NilCondition, otherwise the child condition will be returned with the given UnlockCondition.

func (UnlockConditionProxy) Fulfill added in v1.0.5

func (up UnlockConditionProxy) Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

Fulfill implements UnlockFulfillment.Fulfill

If no child is defined, an error will be returned, otherwise the child condition will be attempted to be fulfilled using the given fulfillment within the given (fulfill) context.

func (UnlockConditionProxy) Fulfillable added in v1.0.5

func (up UnlockConditionProxy) Fulfillable(ctx FulfillableContext) bool

Fulfillable implements UnlockCondition.Fulfillable

func (UnlockConditionProxy) IsStandardCondition added in v1.0.5

func (up UnlockConditionProxy) IsStandardCondition() error

IsStandardCondition implements UnlockCondition.IsStandardCondition

If no child is defined, nil will be returned, otherwise the question will be delegated to the child condition.

func (UnlockConditionProxy) MarshalJSON added in v1.0.5

func (up UnlockConditionProxy) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.MarshalJSON

If no child is defined, the nil condition will be marshaled, otherwise the child condition will be marshaled either implicitly or explicitly, depending on the child condition.

func (UnlockConditionProxy) MarshalSia added in v1.0.5

func (up UnlockConditionProxy) MarshalSia(w io.Writer) error

MarshalSia implements encoding.SiaMarshaler.MarshalSia

If no child is defined, the nil condition will be marshaled, otherwise the child condition will be marshaled using the MarshalableUnlockCondition.Marshal's method, appending the result after the binary-marshaled version of its type.

func (UnlockConditionProxy) UnlockHash added in v1.0.5

func (up UnlockConditionProxy) UnlockHash() UnlockHash

UnlockHash implements UnlockCondition.UnlockHash

If no child is defined, a nil hash will be returned, otherwise the child condition's unlock hash will be returned.

func (*UnlockConditionProxy) UnmarshalJSON added in v1.0.5

func (up *UnlockConditionProxy) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON

First the top-level condition structure is unmarshaled, resulting in the ConditionType property and a dynamic Data property. Using the now known ConditionType, the correct UnlockCondition constructor is used to create an unlock condition instance, as to be able to (binary) unmarshal the child UnlockCondition.

If the unmarshaled ConditionType is unknown, an error will be returned.

func (*UnlockConditionProxy) UnmarshalSia added in v1.0.5

func (up *UnlockConditionProxy) UnmarshalSia(r io.Reader) error

UnmarshalSia implements encoding.SiaUnmarshaler.UnmarshalSia

First the ConditionType is unmarshaled, using that type, the correct UnlockCondition constructor is used to create an unlock condition instance, as to be able to (binary) unmarshal the child UnlockCondition.

If the decoded type is unknown, the condition will not be attempted to be decoded, and instead the raw bytes will be kept in-memory as to be able to write it directly, when it is required to (binary) marshal this condition once again.

type UnlockFulfillment added in v1.0.5

type UnlockFulfillment interface {
	// Sign the given fulfillment, which is to be done after all properties
	// have been filled of the parent transaction
	// (including the unsigned fulfillments of all inputs).
	//
	// The signing is to be done within the given (fulfillment sign) context.
	Sign(ctx FulfillmentSignContext) error

	// UnlockHash returns the unlock hash of this UnlockFulfillment.
	// It identifies the spender of the output linked by the input's parent ID.
	//
	// The UnlockHash, as returned by the UnlockFulfillment,
	// does not have to be deterministic and can depend on how it fulfills a condition.
	// (e.g. if multiple people can fulfill by means of signing,
	//       than the returned unlock hash might depend upon who signed it)
	UnlockHash() UnlockHash

	// Equal returns if the given unlock fulfillment
	// equals the called unlock fulfillment.
	Equal(UnlockFulfillment) bool

	// FulfillmentType returns the fulfillment type of the UnlockFulfillment.
	FulfillmentType() FulfillmentType
	// IsStandardFulfillment returns if this (unlock) fulfillment is standard.
	// An error result means it is not standard,
	// and it will consequently prevent the transaction, which includes the
	// the input that has this fulfillment, from being minted into a block.
	IsStandardFulfillment() error
}

UnlockFulfillment defines the fulfillment that fulfills one or multiple UnlockConditions.

An unlock fulfillment will be propagated even when it is non-standard, but in that case it will not be minted into a block, unless a (block) creator sees it as standard.

type UnlockFulfillmentProxy added in v1.0.5

type UnlockFulfillmentProxy struct {
	Fulfillment MarshalableUnlockFulfillment
}

UnlockFulfillmentProxy wraps around a (binary/json) marshalable UnlockFulfillment, as to allow implicit nil fulfillments, as well as implicit and universal json/binary unmarshaling and binary marshaling.

func NewFulfillment added in v1.0.5

NewFulfillment creates an optional unlock fulfillment, using an optionally given MarshalableUnlockFulfillment.

func (UnlockFulfillmentProxy) Equal added in v1.0.5

Equal implements UnlockFulfillment.Equal

If no child is defined, the given unlock fulfillment will be compared to the NilFulfillment, otherwise the given fulfillment will be compared to the child fulfillment

func (UnlockFulfillmentProxy) FulfillmentType added in v1.0.5

func (fp UnlockFulfillmentProxy) FulfillmentType() FulfillmentType

FulfillmentType implements UnlockFulfillment.FulfillmentType

If no child is defined, the Nil Fulfillment Type will be returned, otherwise the child fulfillment's type will be returned.

func (UnlockFulfillmentProxy) IsStandardFulfillment added in v1.0.5

func (fp UnlockFulfillmentProxy) IsStandardFulfillment() error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

If no child is defined, an error will be returned, otherwise the question will be delegated to the child fulfillmment.

func (UnlockFulfillmentProxy) MarshalJSON added in v1.0.5

func (fp UnlockFulfillmentProxy) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.MarshalJSON

If no child is defined, the nil fulfillment will be marshaled, otherwise the child fulfillment will be marshaled either implicitly or explicitly, depending on the child fulfillment.

func (UnlockFulfillmentProxy) MarshalSia added in v1.0.5

func (fp UnlockFulfillmentProxy) MarshalSia(w io.Writer) error

MarshalSia implements encoding.SiaMarshaler.MarshalSia

If no child is defined, the nil fulfillment will be marshaled, otherwise the child fulfillment will be marshaled using the MarshalableUnlockFulfillment.Marshal's method, appending the result after the binary-marshaled version of its type.

func (UnlockFulfillmentProxy) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

If no child is defined, an error will be returned, otherwise the child fulfillment will be signed within the given (fulfill sign) context.

func (UnlockFulfillmentProxy) UnlockHash added in v1.0.5

func (fp UnlockFulfillmentProxy) UnlockHash() UnlockHash

UnlockHash implements UnlockFulfillment.UnlockHash

If no child is defined, the Nil UnlockHash will be returned, otherwise the child fulfillment's unlock hash will be returned.

func (*UnlockFulfillmentProxy) UnmarshalJSON added in v1.0.5

func (fp *UnlockFulfillmentProxy) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON

First the top-level fulfillment structure is unmarshaled, resulting in the FulfillmentType property and a dynamic Data property. Using the now known FulfillmentType, the correct UnlockFulfillment constructor is used to create an unlock condition instance, as to be able to (binary) unmarshal the child UnlockFulfillment.

If the unmarshaled FulfillmentType is unknown, an error will be returned.

func (*UnlockFulfillmentProxy) UnmarshalSia added in v1.0.5

func (fp *UnlockFulfillmentProxy) UnmarshalSia(r io.Reader) error

UnmarshalSia implements encoding.SiaUnmarshaler.UnmarshalSia

First the FulfillmentType is unmarshaled, using that type, the correct UnlockFulfillment constructor is used to create an unlock fulfillment instance, as to be able to (binary) unmarshal the child UnlockFulfillment.

If the decoded type is unknown, the fulfillment will not be attempted to be decoded, and instead the raw bytes will be kept in-memory as to be able to write it directly, when it is required to (binary) marshal this fulfillment once again.

type UnlockHash

type UnlockHash struct {
	Type UnlockType
	Hash 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.

var (
	NilUnlockHash     UnlockHash
	UnknownUnlockHash = UnlockHash{
		Type: UnlockTypeNil,
		Hash: crypto.Hash{
			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,
		},
	}
)

func NewEd25519PubKeyUnlockHash added in v1.0.5

func NewEd25519PubKeyUnlockHash(pk crypto.PublicKey) UnlockHash

NewEd25519PubKeyUnlockHash creates a new unlock hash of type UnlockTypePubKey, using a given public key which is assumed to be used in combination with the Ed25519 algorithm.

func NewPubKeyUnlockHash added in v1.0.5

func NewPubKeyUnlockHash(pk SiaPublicKey) UnlockHash

NewPubKeyUnlockHash creates a new unlock hash of type UnlockTypePubKey, using a given Sia-standard Public key.

func NewUnlockHash added in v0.6.0

func NewUnlockHash(t UnlockType, h crypto.Hash) UnlockHash

NewUnlockHash creates a new unlock hash

func (UnlockHash) Cmp added in v1.0.0

func (uh UnlockHash) Cmp(other UnlockHash) int

Cmp compares returns an integer comparing two unlock hashes lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b. A nil argument is equivalent to an empty slice.

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) MarshalSia added in v0.6.0

func (uh UnlockHash) MarshalSia(w io.Writer) error

MarshalSia implements SiaMarshaler.MarshalSia

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.

func (*UnlockHash) UnmarshalSia added in v0.6.0

func (uh *UnlockHash) UnmarshalSia(r io.Reader) error

UnmarshalSia implements SiaUnmarshaler.UnmarshalSia

type UnlockHashCondition added in v1.0.5

type UnlockHashCondition struct {
	TargetUnlockHash UnlockHash `json:"unlockhash"`
}

UnlockHashCondition implements the ConditionTypeUnlockHash (unlock) ConditionType. See ConditionTypeUnlockHash for more information.

func NewUnlockHashCondition added in v1.0.5

func NewUnlockHashCondition(uh UnlockHash) *UnlockHashCondition

NewUnlockHashCondition creates a new unlock condition, using a (target) unlock hash as the condtion to be fulfilled.

func (*UnlockHashCondition) ConditionType added in v1.0.5

func (uh *UnlockHashCondition) ConditionType() ConditionType

ConditionType implements UnlockCondition.ConditionType

func (*UnlockHashCondition) Equal added in v1.0.5

Equal implements UnlockCondition.Equal

func (*UnlockHashCondition) Fulfill added in v1.0.5

func (uh *UnlockHashCondition) Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

Fulfill implements UnlockCondition.Fulfill

func (*UnlockHashCondition) Fulfillable added in v1.0.5

func (uh *UnlockHashCondition) Fulfillable(FulfillableContext) bool

Fulfillable implements UnlockCondition.Fulfillable

func (*UnlockHashCondition) IsStandardCondition added in v1.0.5

func (uh *UnlockHashCondition) IsStandardCondition() error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*UnlockHashCondition) Marshal added in v1.0.5

func (uh *UnlockHashCondition) Marshal() []byte

Marshal implements MarshalableUnlockCondition.Marshal

func (*UnlockHashCondition) UnlockHash added in v1.0.5

func (uh *UnlockHashCondition) UnlockHash() UnlockHash

UnlockHash implements UnlockCondition.UnlockHash

func (*UnlockHashCondition) Unmarshal added in v1.0.5

func (uh *UnlockHashCondition) Unmarshal(b []byte) error

Unmarshal implements MarshalableUnlockCondition.Unmarshal

type UnlockHashSlice

type UnlockHashSlice []UnlockHash

UnlockHashSlice defines an optionally sorted slice of unlock hashes.

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 UnlockType added in v0.6.0

type UnlockType byte

UnlockType defines the type of an unlock condition-fulfillment pair.

const (
	// UnlockTypeNil defines a nil (empty) Input Lock and is the default.
	UnlockTypeNil UnlockType = iota

	// UnlockTypePubKey provides the standard and most simple unlock type.
	// In it the sender gives the public key of the intendend receiver.
	// The receiver can redeem the relevant locked input by providing a signature
	// which proofs the ownership of the private key linked to the known public key.
	UnlockTypePubKey

	// UnlockTypeAtomicSwap provides the unlocking of a more advanced condition,
	// where before the TimeLock expired, the output can only go to the receiver,
	// who has to give the secret in order to do so. After the TimeLock,
	// the output can only be claimed by the sender, with no deadline in this phase.
	UnlockTypeAtomicSwap
)

func (UnlockType) MarshalSia added in v0.6.0

func (t UnlockType) MarshalSia(w io.Writer) error

MarshalSia implements SiaMarshaler.MarshalSia

func (*UnlockType) UnmarshalSia added in v0.6.0

func (t *UnlockType) UnmarshalSia(r io.Reader) error

UnmarshalSia implements SiaUnmarshaler.UnmarshalSia

type UnspentBlockStakeOutput added in v0.1.0

type UnspentBlockStakeOutput struct {
	BlockStakeOutputID BlockStakeOutputID
	Indexes            BlockStakeOutputIndexes
	Value              Currency
	Condition          UnlockConditionProxy
}

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