types

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 19 Imported by: 70

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 TransactionNonceLength = 8

TransactionNonceLength defines the length of a TransactionNonce

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 (
	SignatureAlgoNilSpecifier     = Specifier{}
	SignatureAlgoEd25519Specifier = Specifier{'e', 'd', '2', '5', '5', '1', '9'}
)

These Specifiers enumerate the string versions of the types of signatures that are recognized by this implementation. see Consensus.md for more details.

View Source
var (
	//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")
)

Signature-related errors

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

	// ErrUnexpectedUnlockFulfillment is returned 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")

	// ErrInsufficientSignatures is an error returned when a multisig
	// condition is attempted to be fulfilled, but the fulfillment does not
	// (yet) have the required amount of signatures
	ErrInsufficientSignatures = errors.New("not enough signatures")

	// ErrUnauthorizedPubKey is an error returned when a public key used in a multisig
	// fulfillment is not allowed to unlock the input (as the associated pubkey hash is not
	// listed in the conditions unlockhashes)
	ErrUnauthorizedPubKey = errors.New("public key used which is not allowed to sign this input")

	// ErrPrematureRefund is an error returned when a refund is requested for a contract,
	// while the contract is still active, and thus not yet expired.
	ErrPrematureRefund = errors.New("contract cannot yet be refunded")
)

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")
	ErrTooSmallMinerFee              = errors.New("transaction has a too small miner fee")
	ErrZeroOutput                    = errors.New("transaction cannot have an output or payout that has zero value")
	ErrArbitraryDataTooLarge         = errors.New("arbitrary data is too large to fit in a transaction")
	ErrCoinInputOutputMismatch       = errors.New("coin inputs do not equal coin outputs for transaction")
	ErrBlockStakeInputOutputMismatch = errors.New("blockstake inputs do not equal blockstake outputs for transaction")
	ErrMissingMinerFee               = errors.New("transaction does not specify any miner fees")
)

various errors that can be returned as result of a specific transaction validation

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("Severe error: negative value used when converting to target")
)
View Source
var (
	// ErrUnexpectedExtensionType is an error returned by a transaction controller,
	// in case it expects an extension type it didn't expect.
	ErrUnexpectedExtensionType = errors.New("unexpected transaction data extension type")
)
View Source
var (
	// ErrUnknownTransactionType is returned when an unknown transaction version/type was encountered.
	ErrUnknownTransactionType = errors.New("unknown transaction type")
)

Functions

func ArbitraryDataFits added in v1.0.7

func ArbitraryDataFits(arbitraryData []byte, sizeLimit uint64) error

ArbitraryDataFits checks if an arbtirary data first within a given size limit.

func DefaultNetworkName added in v1.2.0

func DefaultNetworkName() string

DefaultNetworkName returns a sane default network name, based on the build.Release tag (NOTE that in most cases you do really want a user-approved default network name rather than this static value).

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, or at the very least prior to starting to create the daemon server, 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 function 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 function with nil as the MarshalableUnlockFulfillmentConstructor.

func TransactionFitsInABlock added in v1.0.7

func TransactionFitsInABlock(t Transaction, blockSizeLimit uint64) error

TransactionFitsInABlock checks if the transaction is likely to fit in a block. Currently there is no limitation on transaction size other than it must fit in a block.

func TransactionFollowsMinimumValues added in v1.0.7

func TransactionFollowsMinimumValues(t Transaction, minimumMinerFee Currency, IsBlockCreatingTx bool) error

TransactionFollowsMinimumValues checks that all outputs adhere to the rules for the minimum allowed values

func ValidateNoDoubleSpendsWithinTransaction added in v1.0.7

func ValidateNoDoubleSpendsWithinTransaction(t Transaction) (err error)

ValidateNoDoubleSpendsWithinTransaction validates that no output has been spend twice, within the given transaction. NOTE that this is a local test only, and does not guarantee that an output isn't already spend in another transaction.

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(ValidationContext) error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*AtomicSwapCondition) Marshal added in v1.0.5

func (as *AtomicSwapCondition) Marshal(f MarshalFunc) ([]byte, error)

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, f UnmarshalFunc) error

Unmarshal implements MarshalableUnlockCondition.Unmarshal

type AtomicSwapFulfillment added in v0.6.0

type AtomicSwapFulfillment struct {
	PublicKey PublicKey        `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 PublicKey, 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 PublicKey) *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(ValidationContext) error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*AtomicSwapFulfillment) Marshal added in v1.0.5

func (as *AtomicSwapFulfillment) Marshal(f MarshalFunc) ([]byte, error)

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*AtomicSwapFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*AtomicSwapFulfillment) Unmarshal added in v1.0.5

func (as *AtomicSwapFulfillment) Unmarshal(b []byte, f UnmarshalFunc) 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) MarshalRivine added in v1.2.0

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

MarshalRivine implements the rivbin.RivineMarshaler interface.

func (Block) MarshalSia

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

MarshalSia implements the siabin.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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements the rivbin.RivineUnmarshaler interface.

func (*Block) UnmarshalSia

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

UnmarshalSia implements the siabin.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
	NetworkName     string
	CoinUnit        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
	// ArbitraryDataSizeLimit is the maximum size an arbitrary data block
	// within a single transaction can have, in bytes
	ArbitraryDataSizeLimit 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

	TransactionPool TransactionPoolConstants
}

ChainConstants is a utility struct which groups together the chain configuration

func DevnetChainConstants added in v1.2.0

func DevnetChainConstants() ChainConstants

DevnetChainConstants provide sane defaults for a new devnet 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 StandardnetChainConstants added in v1.2.0

func StandardnetChainConstants() ChainConstants

StandardnetChainConstants provide sane defaults for a new standard network 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 TestnetChainConstants added in v1.2.0

func TestnetChainConstants() ChainConstants

TestnetChainConstants provide sane defaults for a new testnet 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 ClientError added in v1.2.0

type ClientError struct {
	Err  error
	Kind ClientErrorKind
}

func NewClientError added in v1.2.0

func NewClientError(err error, kind ClientErrorKind) ClientError

func (ClientError) Error added in v1.2.0

func (ce ClientError) Error() string

type ClientErrorKind added in v1.2.0

type ClientErrorKind uint32
const (
	ClientErrorBadRequest      ClientErrorKind = 0
	ClientErrorUnauthorized    ClientErrorKind = 1
	ClientErrorPaymentRequired ClientErrorKind = 2
	ClientErrorForbidden       ClientErrorKind = 3
	ClientErrorNotFound        ClientErrorKind = 4
	ClientErrorTimeout         ClientErrorKind = 8
)

func (ClientErrorKind) AsHTTPStatusCode added in v1.2.0

func (kind ClientErrorKind) AsHTTPStatusCode() int

func (ClientErrorKind) String added in v1.2.0

func (kind ClientErrorKind) String() string

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 CommonTransactionExtensionData added in v1.2.0

type CommonTransactionExtensionData struct {
	UnlockConditions []UnlockConditionProxy
}

CommonTransactionExtensionData collects the common-understood Tx Extension data as a single struct.

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 aren't allowed),
	// MultiSignatureCondition,
	// ]
	ConditionTypeTimeLock

	// ConditionTypeMultiSignature defines an unlock condition which
	// can only be unlocked by multiple signatures. The
	// accepted signatures are declared up front by
	// specifying the unlockhash created from the public key
	// which matches the private key that will be used for signing,
	// for every person who is allowed to sign. Additionally, a minimum
	// required amount of signatures must be specified, which is the minimum
	// amount of signatures required to spend the output. More signatures
	// can be given, but these additional signatures are not required.
	//
	// Implemented by the MultiSignatureCondition type
	ConditionTypeMultiSignature
)

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

func (ConditionType) MarshalRivine added in v1.2.0

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

MarshalRivine implements rivbin.RivineMarshaler.MarshalRivine

Marshals this ConditionType as a single byte.

func (ConditionType) MarshalSia added in v1.0.5

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

MarshalSia implements siabin.SiaMarshaler.MarshalSia

Marshals this ConditionType as a single byte.

func (*ConditionType) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements rivbin.RivineUnmarshaler.UnmarshalRivine

Unmarshals this ConditionType from a single byte.

func (*ConditionType) UnmarshalSia added in v1.0.5

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

UnmarshalSia implements siabin.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 (c Currency) Add(y Currency) (z Currency)

Add returns a new Currency value z = c + y

func (Currency) Big

func (c 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 (c 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 (c Currency) Cmp64(y uint64) int

Cmp64 compares x to a uint64. The return value follows the convention of math/big.

func (Currency) Div

func (c Currency) Div(y Currency) (z Currency)

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

func (Currency) Div64

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

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

func (Currency) Equals added in v0.6.0

func (c Currency) Equals(y Currency) bool

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

func (Currency) Equals64 added in v0.6.0

func (c Currency) Equals64(y uint64) bool

Equals64 returns true if c 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) LoadString added in v1.2.0

func (c *Currency) LoadString(str string) error

LoadString loads the given Currency from a string.

func (Currency) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Currency) MarshalRivine added in v1.2.0

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

MarshalRivine implements the rivbin.MarshalRivine 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) MarshalSia

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

MarshalSia implements the siabin.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 (c Currency) Mul(y Currency) (z Currency)

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

func (Currency) Mul64

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

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

func (Currency) MulFloat

func (c Currency) MulFloat(y float64) (z 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 z = c * y, where y is a float64. Behavior is undefined when y is negative.

func (Currency) MulRat

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

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

func (Currency) RoundDown

func (c Currency) RoundDown(y Currency) (z 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 (c Currency) Sqrt() (z 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 (c Currency) Sub(y Currency) (z Currency)

Sub returns a new Currency value z = c - y. Behavior is undefined when c < 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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements the rivbin.RivineMarshaler interface.

func (*Currency) UnmarshalSia

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

UnmarshalSia implements the siabin.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(r io.Reader) (td TransactionData, err error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (DefaultTransactionController) EncodeTransactionData added in v1.0.5

func (dtc DefaultTransactionController) EncodeTransactionData(w io.Writer, td TransactionData) 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 (c 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 (c 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 (c Difficulty) Div64(y uint64) (z Difficulty)

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

func (Difficulty) MarshalJSON added in v0.1.0

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

MarshalJSON implements the json.Marshaler interface.

func (Difficulty) MarshalRivine added in v1.2.0

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

MarshalRivine implements the rivbin.RivineMarshaler 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) MarshalSia added in v0.1.0

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

MarshalSia implements the siabin.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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements the rivbin.RivineMarshaler interface.

func (*Difficulty) UnmarshalSia added in v0.1.0

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

UnmarshalSia implements the siabin.SiaUnmarshaler interface.

type DisabledTransactionController added in v1.2.0

type DisabledTransactionController struct {
	DefaultTransactionController
}

DisabledTransactionController is used for transaction versions that are disabled but still need to be JSON decodable.

func (DisabledTransactionController) DecodeTransactionData added in v1.2.0

func (dtc DisabledTransactionController) DecodeTransactionData(r io.Reader) (TransactionData, error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (DisabledTransactionController) EncodeTransactionData added in v1.2.0

func (dtc DisabledTransactionController) EncodeTransactionData(w io.Writer, td TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (DisabledTransactionController) JSONDecodeTransactionData added in v1.2.0

func (dtc DisabledTransactionController) JSONDecodeTransactionData(b []byte) (TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (DisabledTransactionController) JSONEncodeTransactionData added in v1.2.0

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

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

type FulfillContext added in v1.0.5

type FulfillContext struct {
	// ExtraObjects are objects to be hashed together with the Tx, in order
	// to get the input hash that will be signed for this fulfillment.
	ExtraObjects []interface{}
	// 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 {
	// ExtraObjects are objects to be hashed together with the Tx, in order
	// to get the input hash that will be signed for this fulfillment.
	ExtraObjects []interface{}
	// (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
	// FulfillmentTypeMultiSignature defines the multisig fulfillment, and is defined by a
	// slice of public keys, and a slice of transaction-based signatures generated from
	// the matching private keys. The index of the signature is the same as the corresponding
	// public key
	//
	// Implemented by the MultiSignatureFulfillment type
	FulfillmentTypeMultiSignature
)

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

func (FulfillmentType) MarshalRivine added in v1.2.0

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

MarshalRivine implements rivbin.RivineMarshaler.MarshalRivine

Marshals this FulfillmentType as a single byte.

func (FulfillmentType) MarshalSia added in v1.0.5

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

MarshalSia implements siabin.SiaMarshaler.MarshalSia

Marshals this FulfillmentType as a single byte.

func (*FulfillmentType) UnmarshalRivin added in v1.2.0

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

UnmarshalRivin implements rivbin.RivineUnmarshaler.UnmarshalRivin

Unmarshals this FulfillmentType from a single byte.

func (*FulfillmentType) UnmarshalSia added in v1.0.5

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

UnmarshalSia implements siabin.SiaUnmarshaler.UnmarshalSia

Unmarshals this FulfillmentType from a single byte.

type FundValidationContext added in v1.2.0

type FundValidationContext struct {
	// BlockHeight defines either the height of the block the (parent) transaction is part of,
	// or it defines the height of the last confirmed/created block.
	// It's the latter in case Confirmed is false, the first otherwise.
	BlockHeight BlockHeight
	// BlockTime defines the time of the currently last registered block,
	// the transaction belonged to.
	BlockTime Timestamp
}

FundValidationContext is used for coin- and block stake- validators, optional types which validate if a fund output is properly backed by an input.

type KeyPair added in v1.0.6

type KeyPair struct {
	PublicKey  PublicKey
	PrivateKey ByteSlice
}

KeyPair is a matching public and private key

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    PublicKey              `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(ValidationContext) error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*LegacyAtomicSwapFulfillment) Marshal added in v1.0.5

func (as *LegacyAtomicSwapFulfillment) Marshal(f MarshalFunc) ([]byte, error)

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*LegacyAtomicSwapFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*LegacyAtomicSwapFulfillment) Unmarshal added in v1.0.5

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

Unmarshal implements MarshalableUnlockFulfillment.Unmarshal

type LegacyTransactionController added in v1.0.7

type LegacyTransactionController struct{}

LegacyTransactionController is a legacy transaction controller, which used to be the default when Rivine launched. It should however not be used any longer, and only exists, as to support chains which launched together with Rivine.

func (LegacyTransactionController) DecodeTransactionData added in v1.0.7

func (ltc LegacyTransactionController) DecodeTransactionData(r io.Reader) (TransactionData, error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (LegacyTransactionController) EncodeTransactionData added in v1.0.7

func (ltc LegacyTransactionController) EncodeTransactionData(w io.Writer, td TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (LegacyTransactionController) EncodeTransactionIDInput added in v1.0.7

func (ltc LegacyTransactionController) EncodeTransactionIDInput(w io.Writer, td TransactionData) error

EncodeTransactionIDInput implements TransactionIDEncoder.EncodeTransactionIDInput

func (LegacyTransactionController) JSONDecodeTransactionData added in v1.0.7

func (ltc LegacyTransactionController) JSONDecodeTransactionData(b []byte) (TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (LegacyTransactionController) JSONEncodeTransactionData added in v1.0.7

func (ltc LegacyTransactionController) JSONEncodeTransactionData(td TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

func (LegacyTransactionController) SignatureHash added in v1.2.0

func (ltc LegacyTransactionController) SignatureHash(t Transaction, extraObjects ...interface{}) (crypto.Hash, error)

SignatureHash implements TransactionSignatureHasher.SignatureHash

type MarshalFunc added in v1.2.0

type MarshalFunc = func(...interface{}) ([]byte, error)

MarshalFunc represents the signature of a Marshal function, as used by MarshalableUnlockConditions and MarshalableUnlockFulfillments.

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(MarshalFunc) ([]byte, error)
	// Unmarshal this unlock condition from a binary format,
	// the whole byte slice is expected to be used.
	Unmarshal([]byte, UnmarshalFunc) 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 MarshalableUnlockConditionGetter added in v1.0.7

type MarshalableUnlockConditionGetter interface {
	GetMarshalableUnlockCondition() MarshalableUnlockCondition
}

MarshalableUnlockConditionGetter is an optional interface an MarshalableUnlockCondition can implement, in case it wraps around another MarshalableUnlockCondition.

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(MarshalFunc) ([]byte, error)
	// Unmarshal this unlock fulfillment from a binary format,
	// the whole byte slice is expected to be used.
	Unmarshal([]byte, UnmarshalFunc) 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) paid 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 MultiSignatureCondition added in v1.0.6

type MultiSignatureCondition struct {
	UnlockHashes          UnlockHashSlice `json:"unlockhashes"`
	MinimumSignatureCount uint64          `json:"minimumsignaturecount"`
}

MultiSignatureCondition implements the ConditionTypeMultiSignature ConditionType. See ConditionTypeMultiSignature for more information.

func NewMultiSignatureCondition added in v1.0.6

func NewMultiSignatureCondition(uhs UnlockHashSlice, minsigs uint64) *MultiSignatureCondition

NewMultiSignatureCondition creates a new multisig unlock condition, using the given unlockhashes as a representation of the identities who can unlock the output

func (*MultiSignatureCondition) ConditionType added in v1.0.6

func (ms *MultiSignatureCondition) ConditionType() ConditionType

ConditionType implements UnlockCondition.ConditionType

func (*MultiSignatureCondition) Equal added in v1.0.6

Equal implements UnlockCondition.Equal

func (*MultiSignatureCondition) Fulfill added in v1.0.6

func (ms *MultiSignatureCondition) Fulfill(fulfillment UnlockFulfillment, ctx FulfillContext) error

Fulfill implements UnlockFulfillment.Fulfill

func (*MultiSignatureCondition) Fulfillable added in v1.0.6

func (ms *MultiSignatureCondition) Fulfillable(ctx FulfillableContext) bool

Fulfillable implements UnlockCondition.Fulfillable

func (*MultiSignatureCondition) GetMinimumSignatureCount added in v1.0.7

func (ms *MultiSignatureCondition) GetMinimumSignatureCount() uint64

GetMinimumSignatureCount returns the minimum amount of signatures required in order to fulfill this MultiSignatureCondition using a MultiSignatureFulfillment.

func (*MultiSignatureCondition) IsStandardCondition added in v1.0.6

func (ms *MultiSignatureCondition) IsStandardCondition(ValidationContext) error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*MultiSignatureCondition) Marshal added in v1.0.6

func (ms *MultiSignatureCondition) Marshal(f MarshalFunc) ([]byte, error)

Marshal implements MarshalableUnlockCondition.Marshal

func (*MultiSignatureCondition) UnlockHash added in v1.0.6

func (ms *MultiSignatureCondition) UnlockHash() UnlockHash

UnlockHash implements UnlockCondition.UnlockHash

UnlockHash calculates the root hash of a Merkle tree of the MultiSignatureCondition object. The leaves of this tree are formed by taking the hash of the length of unlock hashes, the hash of the sorted unlock hashes (one leaf each), and the hash of the number of minimum signatures required. The unlock hashes are put in the middle because unlockhash length and MinimumSignatureCount are both low entropy fields; they can be protected by having random unlock hashes next to them.

func (*MultiSignatureCondition) UnlockHashSlice added in v1.0.7

func (ms *MultiSignatureCondition) UnlockHashSlice() []UnlockHash

UnlockHashSlice implements UnlockHashSliceGetter.UnlockHashSlice

func (*MultiSignatureCondition) Unmarshal added in v1.0.6

func (ms *MultiSignatureCondition) Unmarshal(b []byte, f UnmarshalFunc) error

Unmarshal implements MarshalableUnlockCondition.Unmarshal

type MultiSignatureFulfillment added in v1.0.6

type MultiSignatureFulfillment struct {
	Pairs []PublicKeySignaturePair `json:"pairs"`
}

MultiSignatureFulfillment implements the FulfillmentTypeMultiSignature FulfillmentType. See FulfillmentTypeMultiSignature for more information.

func NewMultiSignatureFulfillment added in v1.0.6

func NewMultiSignatureFulfillment(pairs []PublicKeySignaturePair) *MultiSignatureFulfillment

NewMultiSignatureFulfillment creates a new unsigned multisig fulfillment from the given public keys. The keys are later matched to the private keys used for signing

func (*MultiSignatureFulfillment) Equal added in v1.0.6

Equal implements UnlockFulfillment.Equal

func (*MultiSignatureFulfillment) FulfillmentType added in v1.0.6

func (ms *MultiSignatureFulfillment) FulfillmentType() FulfillmentType

FulfillmentType implements UnlockFulfillment.FulfillmentType

func (*MultiSignatureFulfillment) IsStandardFulfillment added in v1.0.6

func (ms *MultiSignatureFulfillment) IsStandardFulfillment(ValidationContext) error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*MultiSignatureFulfillment) Marshal added in v1.0.6

func (ms *MultiSignatureFulfillment) Marshal(f MarshalFunc) ([]byte, error)

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*MultiSignatureFulfillment) Sign added in v1.0.6

Sign implements UnlockFulfillment.Sign

func (*MultiSignatureFulfillment) Unmarshal added in v1.0.6

func (ms *MultiSignatureFulfillment) Unmarshal(b []byte, f UnmarshalFunc) error

Unmarshal implements MarshalableUnlockFulfillment.Unmarshal

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(ValidationContext) error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*NilCondition) Marshal added in v1.0.5

func (n *NilCondition) Marshal(MarshalFunc) ([]byte, error)

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, _ UnmarshalFunc) 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(ValidationContext) error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*NilFulfillment) Marshal added in v1.0.5

func (n *NilFulfillment) Marshal(MarshalFunc) ([]byte, error)

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*NilFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*NilFulfillment) Unmarshal added in v1.0.5

func (n *NilFulfillment) Unmarshal([]byte, UnmarshalFunc) 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 PublicKey added in v1.2.0

type PublicKey struct {
	Algorithm SignatureAlgoType
	Key       ByteSlice
}

A PublicKey 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) PublicKey

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

func (*PublicKey) LoadString added in v1.2.0

func (pk *PublicKey) LoadString(s string) error

LoadString is the inverse of PublicKey.String().

func (PublicKey) MarshalJSON added in v1.2.0

func (pk PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON marshals a byte slice as a hex string.

func (PublicKey) MarshalRivine added in v1.2.0

func (pk PublicKey) MarshalRivine(w io.Writer) error

MarshalRivine implements RivineMarshaler.MarshalRivine

func (PublicKey) MarshalSia added in v1.2.0

func (pk PublicKey) MarshalSia(w io.Writer) error

MarshalSia implements SiaMarshaler.MarshalSia

func (*PublicKey) String added in v1.2.0

func (pk *PublicKey) String() string

String defines how to print a PublicKey - 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 (*PublicKey) UnmarshalJSON added in v1.2.0

func (pk *PublicKey) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the json string of the byte slice.

func (*PublicKey) UnmarshalRivine added in v1.2.0

func (pk *PublicKey) UnmarshalRivine(r io.Reader) error

UnmarshalRivine implements RivineUnmarshaler.UnmarshalRivine

func (*PublicKey) UnmarshalSia added in v1.2.0

func (pk *PublicKey) UnmarshalSia(r io.Reader) error

UnmarshalSia implements SiaUnmarshaler.UnmarshalSia

type PublicKeySignaturePair added in v1.0.6

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

PublicKeySignaturePair is a public key and a signature created from the corresponding private key

type SignatureAlgoType added in v1.2.0

type SignatureAlgoType uint8

SignatureAlgoType identifies a signature algorithm as a single byte.

const (
	// SignatureAlgoNil identifies a nil SignatureAlgoType value.
	SignatureAlgoNil SignatureAlgoType = iota
	// SignatureAlgoEd25519 identifies the Ed25519 signature Algorithm,
	// the default (and only) algorithm supported by this chain.
	SignatureAlgoEd25519
)

func (*SignatureAlgoType) LoadSpecifier added in v1.2.0

func (sat *SignatureAlgoType) LoadSpecifier(specifier Specifier) error

LoadSpecifier loads the algorithm type in specifier-format.

func (*SignatureAlgoType) LoadString added in v1.2.0

func (sat *SignatureAlgoType) LoadString(str string) error

LoadString loads the stringified algo type as its single byte representation.

func (SignatureAlgoType) Specifier added in v1.2.0

func (sat SignatureAlgoType) Specifier() Specifier

Specifier returns the specifier linked to this Signature Algorithm Type, returns the SignatureAlgoNilSpecifier if the algorithm type is unknown.

func (SignatureAlgoType) String added in v1.2.0

func (sat SignatureAlgoType) String() string

type SingleSignatureFulfillment added in v1.0.5

type SingleSignatureFulfillment struct {
	PublicKey PublicKey `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 PublicKey) *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(ValidationContext) error

IsStandardFulfillment implements UnlockFulfillment.IsStandardFulfillment

func (*SingleSignatureFulfillment) Marshal added in v1.0.5

func (ss *SingleSignatureFulfillment) Marshal(f MarshalFunc) ([]byte, error)

Marshal implements MarshalableUnlockFulfillment.Marshal

func (*SingleSignatureFulfillment) Sign added in v1.0.5

Sign implements UnlockFulfillment.Sign

func (*SingleSignatureFulfillment) Unmarshal added in v1.0.5

func (ss *SingleSignatureFulfillment) Unmarshal(b []byte, f UnmarshalFunc) 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 (t Target) AddDifficulties(y Target, rootDepth Target) Target

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

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

func (Target) Cmp

func (t 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 t <  y
 0 if t == y
+1 if t >  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 (t Target) MulDifficulty(y *big.Rat, rootDepth Target) Target

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

y / t

func (Target) Rat

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

Rat converts a Target to a big.Rat.

func (Target) SubtractDifficulties

func (t Target) SubtractDifficulties(y Target, rootDepth Target) Target

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

sum(t, y) = 1/(1/t - 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 considered 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) GetMarshalableUnlockCondition added in v1.0.7

func (tl *TimeLockCondition) GetMarshalableUnlockCondition() MarshalableUnlockCondition

GetMarshalableUnlockCondition implements MarshalableUnlockConditionGetter.GetMarshalableUnlockCondition

func (*TimeLockCondition) IsStandardCondition added in v1.0.5

func (tl *TimeLockCondition) IsStandardCondition(ctx ValidationContext) error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*TimeLockCondition) Marshal added in v1.0.5

func (tl *TimeLockCondition) Marshal(f MarshalFunc) ([]byte, error)

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, f UnmarshalFunc) 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) (id 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) (id 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) CommonExtensionData added in v1.2.0

func (t Transaction) CommonExtensionData() (CommonTransactionExtensionData, error)

CommonExtensionData returns the common-understood Extension data.

func (Transaction) CustomMinerPayouts added in v1.2.0

func (t Transaction) CustomMinerPayouts() ([]MinerPayout, error)

CustomMinerPayouts returns any miner payouts originating from this transaction, that are not registered as regular MinerFees.

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

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

MarshalJSON implements the json.Marshaler interface.

func (Transaction) MarshalRivine added in v1.2.0

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

MarshalRivine implements the rivbin.RivineMarshaler interface.

func (Transaction) MarshalSia added in v0.6.0

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

MarshalSia implements the siabin.SiaMarshaler interface.

func (*Transaction) SignExtension added in v1.2.0

func (t *Transaction) SignExtension(sign func(*UnlockFulfillmentProxy, UnlockConditionProxy, ...interface{}) error) error

SignExtension allows the transaction to sign —using the given sign callback— any fulfillment defined within the extension data of the transaction that has to be signed.

func (Transaction) SignatureHash added in v1.2.0

func (t Transaction) SignatureHash(extraObjects ...interface{}) (crypto.Hash, error)

SignatureHash returns the hash of all fields in a transaction, relevant to a Tx sig.

func (*Transaction) UnmarshalJSON added in v0.6.0

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Transaction) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements the rivbin.RivineUnmarshaler interface.

func (*Transaction) UnmarshalSia added in v0.6.0

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

UnmarshalSia implements the siabin.SiaUnmarshaler interface.

type TransactionCommonExtensionDataGetter added in v1.2.0

type TransactionCommonExtensionDataGetter interface {
	// GetCommonExtensionData allows a transaction controllor to extract
	// the common-understood data from the Extension data for consumption by the callee.
	GetCommonExtensionData(extension interface{}) (CommonTransactionExtensionData, error)
}

TransactionCommonExtensionDataGetter defines an interface for transactions which have common-understood data in the Extension data, allowing Rivine code to extract this generic extension data, without having to know about the actual format/structure of this Tx.

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(io.Writer, TransactionData) error
	// DecodeTransactionData binary-decodes the transaction data,
	// which is all transaction properties except for the version.
	DecodeTransactionData(io.Reader) (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 TransactionCreationValidationContext added in v1.2.0

type TransactionCreationValidationContext struct {
	FundValidationContext

	BlockSizeLimit         uint64
	ArbitraryDataSizeLimit uint64
	MinimumMinerFee        Currency
}

TransactionCreationValidationContext is given to any transaction creation validator function, as to be able to validate with a full overview of the context it validates within. It contains relevant constants as well as state-related variables for this Txn in specific.

type TransactionCustomMinerPayoutGetter added in v1.2.0

type TransactionCustomMinerPayoutGetter interface {
	// GetCustomMinerPayouts allows a transaction controller to extract
	// MinerPayouts orginating from the transaction's extension data,
	// for any miner payouts to be added to the parent block,
	// which is not considered as regular MinerFees
	// (and thus is not simply defined in the Transaction's MinerFees property).
	GetCustomMinerPayouts(extension interface{}) ([]MinerPayout, error)
}

TransactionCustomMinerPayoutGetter defines an interface for transactions which have custom MinerPayouts, stored in its extension data, that are not seen as regular Miner Fees.

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.
	// It is used for data only, controller logic is all to be implemented
	// as extended interfaces of the (transaction) controller.
	Extension interface{} `json:"-"` // omitted 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) MarshalRivine added in v1.2.0

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

MarshalRivine implements rivbin.RivineMarshaler.MarshalRivine

func (TransactionData) MarshalSia added in v1.0.5

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

MarshalSia implements siabin.SiaMarshaller.MarshalSia

func (*TransactionData) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements rivbin.RivineMarshaler.UnmarshalRivine

func (*TransactionData) UnmarshalSia added in v1.0.5

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

UnmarshalSia implements siabin.SiaUnmarshaller.UnmarshalSia

type TransactionExtensionSigner added in v1.2.0

type TransactionExtensionSigner interface {
	// SignExtension allows the transaction to sign —using the given sign callback—
	// any fulfillment (giving its condition as reference) that has to be signed.
	SignExtension(extension interface{}, sign func(*UnlockFulfillmentProxy, UnlockConditionProxy, ...interface{}) error) (interface{}, error)
}

TransactionExtensionSigner defines an interface for transactions which have fulfillments in the extension part of the data that have to be signed as well.

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 TransactionIDEncoder added in v1.0.7

type TransactionIDEncoder interface {
	EncodeTransactionIDInput(io.Writer, TransactionData) error
}

TransactionIDEncoder is an optional interface a transaction controller can implement, in order to use a different binary encoding for ID-generation purposes, instead of using the default binary encoding logic for that transaction (version).

type TransactionNonce added in v1.2.0

type TransactionNonce [TransactionNonceLength]byte

TransactionNonce is a nonce used to ensure the uniqueness of an otherwise potentially non-unique Tx

func RandomTransactionNonce added in v1.2.0

func RandomTransactionNonce() (nonce TransactionNonce)

RandomTransactionNonce creates a random Transaction nonce

func (TransactionNonce) MarshalJSON added in v1.2.0

func (tn TransactionNonce) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON.Marshaller.MarshalJSON encodes the Nonce as a base64-encoded string

func (*TransactionNonce) UnmarshalJSON added in v1.2.0

func (tn *TransactionNonce) UnmarshalJSON(in []byte) error

UnmarshalJSON implements JSON.Unmarshaller.UnmarshalJSON piggy-backing on the base64-decoding used for byte slices in the std JSON lib

type TransactionPoolConstants added in v1.0.7

type TransactionPoolConstants struct {
	// TransactionSizeLimit defines the size of the largest transaction that
	// will be accepted by the transaction pool according to the IsStandard
	// rules.
	TransactionSizeLimit int

	// TransactionSetSizeLimit defines the largest set of dependent unconfirmed
	// transactions that will be accepted by the transaction pool.
	TransactionSetSizeLimit int

	// The TransactionPoolSizeLimit is first checked, and then a transaction
	// set is added. The current transaction pool does not do any priority
	// ordering, so the size limit is such that the transaction pool will never
	// exceed the size of a block.
	PoolSizeLimit int
}

TransactionPoolConstants defines the constants used by the TransactionPool.

func DefaultTransactionPoolConstants added in v1.0.7

func DefaultTransactionPoolConstants() TransactionPoolConstants

DefaultTransactionPoolConstants provides sane defaults for TransactionPool constants.

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) MarshalRivine added in v1.2.0

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

MarshalRivine implements RivineMarshaler.MarshalRivine

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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements RivineUnmarshaler.UnmarshalRivine

func (*TransactionShortID) UnmarshalSia added in v0.6.0

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

UnmarshalSia implements SiaMarshaler.UnmarshalSia

type TransactionSignatureHasher added in v1.2.0

type TransactionSignatureHasher interface {
	SignatureHash(t Transaction, extraObjects ...interface{}) (crypto.Hash, error)
}

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

type TransactionValidationConstants added in v1.0.6

type TransactionValidationConstants struct {
	BlockSizeLimit         uint64
	ArbitraryDataSizeLimit uint64
	MinimumMinerFee        Currency
}

TransactionValidationConstants defines the contants that a TransactionValidator can use in order to validate the transaction, within its local scope.

type TransactionValidationContext added in v1.0.3

type TransactionValidationContext struct {
	ValidationContext

	BlockSizeLimit         uint64
	ArbitraryDataSizeLimit uint64
	MinimumMinerFee        Currency
}

TransactionValidationContext is given to any transaction validator function, as to be able to validate with a full overview of the context it validates within. It contains relevant constants as well as state-related variables for this Txn in specific.

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 considered invalid.
	TransactionVersionZero TransactionVersion = iota
	// TransactionVersionOne defines the new (default) transaction version,
	// which deprecates and is based upon TransactionVersionZero.
	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) MarshalRivine added in v1.2.0

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

MarshalRivine implements RivineMarshaler.MarshalRivine

func (TransactionVersion) MarshalSia added in v0.6.0

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

MarshalSia implements SiaMarshaler.MarshalSia

func (*TransactionVersion) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements RivineUnmarshaler.UnmarshalRivine

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(ValidationContext) 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 fulfilled,
	// 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(ctx ValidationContext) 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) MarshalRivine added in v1.2.0

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

MarshalRivine implements rivbin.RivineMarshaler.MarshalRivine

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

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

MarshalSia implements siabin.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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements rivbin.RivineMarshaler.UnmarshalRivine

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.

func (*UnlockConditionProxy) UnmarshalSia added in v1.0.5

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

UnmarshalSia implements siabin.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

	// 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(ValidationContext) 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(ctx ValidationContext) 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) MarshalRivine added in v1.2.0

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

MarshalRivine implements rivbin.RivineMarshaler.MarshalRivine

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

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

MarshalSia implements siabin.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) 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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements rivbin.RivineUnmarshaler.UnmarshalRivine

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.

func (*UnlockFulfillmentProxy) UnmarshalSia added in v1.0.5

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

UnmarshalSia implements siabin.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 ComputeLegacyFulfillmentUnlockHash added in v1.0.6

func ComputeLegacyFulfillmentUnlockHash(ff UnlockFulfillment) UnlockHash

ComputeLegacyFulfillmentUnlockHash computes unlock hashes as they used to be computed, back when fulfillments had an unlock hash function

func NewEd25519PubKeyUnlockHash added in v1.0.5

func NewEd25519PubKeyUnlockHash(pk crypto.PublicKey) (UnlockHash, error)

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 PublicKey) (UnlockHash, error)

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) MarshalRivine added in v1.2.0

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

MarshalRivine implements RivineMarshaler.MarshalRivine

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) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements RivineUnmarshaler.UnmarshalRivine

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(ValidationContext) error

IsStandardCondition implements UnlockCondition.IsStandardCondition

func (*UnlockHashCondition) Marshal added in v1.0.5

func (uh *UnlockHashCondition) Marshal(f MarshalFunc) ([]byte, error)

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, f UnmarshalFunc) 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 UnlockHashSliceGetter added in v1.0.7

type UnlockHashSliceGetter interface {
	UnlockHashSlice() []UnlockHash
}

UnlockHashSliceGetter is an optional interface an UnlockCondition can implement, in case it can be unlocked by multiple wallets. The unlock hash type should be used to know how exactly those different unlock hashes come into play.

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

	// UnlockTypeMultiSig provides a condition in which the receiving party
	// consists of multiple (possibly separate) identities. The output can only
	// be spent after at least the specified amount of identities have agreed,
	// by means of providing their signature.
	UnlockTypeMultiSig
)

func (UnlockType) MarshalRivine added in v1.2.0

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

MarshalRivine implements RivineMarshaler.MarshalRivine

func (UnlockType) MarshalSia added in v0.6.0

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

MarshalSia implements SiaMarshaler.MarshalSia

func (*UnlockType) UnmarshalRivine added in v1.2.0

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

UnmarshalRivine implements RivineUnmarshaler.UnmarshalRivine

func (*UnlockType) UnmarshalSia added in v0.6.0

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

UnmarshalSia implements SiaUnmarshaler.UnmarshalSia

type UnmarshalFunc added in v1.2.0

type UnmarshalFunc = func([]byte, ...interface{}) error

UnmarshalFunc represents the signature of an Unmarshal function, as used by MarshalableUnlockConditions and MarshalableUnlockFulfillments.

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

type ValidationContext added in v1.0.7

type ValidationContext struct {
	// Confirmed defines whether or not the (parent) transaction
	// is already confirmed, or in other words is part of a created block already.
	Confirmed bool
	// BlockHeight defines either the height of the block the (parent) transaction is part of,
	// or it defines the height of the last confirmed/created block.
	// It's the latter in case Confirmed is false, the first otherwise.
	BlockHeight BlockHeight
	// BlockTime defines the time of the currently last registered block,
	// the transaction belonged to.
	BlockTime Timestamp
	// IsBlockCreatingTx defines if a transaction is used for the sole purpose
	// of creating a block. More specifically, a transaction is considered a
	// block creating transaction if it only respends a blockstake output
	// for the purpose of the proof of blockstake protocol
	IsBlockCreatingTx bool
}

ValidationContext is given as part of any IsStandard check, as to give some context in order to present a more informed conclusion of whether or not a condition/fulfillment is standard, as well as if a transaction is valid on a local level.

Jump to

Keyboard shortcuts

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