Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterUnlockType(t UnlockType, ilc InputLockConstructor)
- func UnregisterUnlockType(t UnlockType)
- type AtomicSwapClaimKey
- type AtomicSwapCondition
- type AtomicSwapFulfillment
- type AtomicSwapHashedSecret
- type AtomicSwapInputLock
- func (as *AtomicSwapInputLock) Decode(rf RawInputLockFormat) error
- func (as *AtomicSwapInputLock) EncodeCondition() []byte
- func (as *AtomicSwapInputLock) EncodeFulfillment() []byte
- func (as *AtomicSwapInputLock) Lock(inputIndex uint64, tx Transaction, key interface{}) error
- func (as *AtomicSwapInputLock) StrictCheck() error
- func (as *AtomicSwapInputLock) Unlock(inputIndex uint64, tx Transaction) error
- type AtomicSwapRefundKey
- type AtomicSwapSecret
- type Block
- func (b Block) CalculateTotalMinerFees() Currency
- func (b Block) Header() BlockHeader
- func (b Block) ID() BlockID
- func (b Block) MarshalSia(w io.Writer) error
- func (b Block) MerkleRoot() crypto.Hash
- func (b Block) MinerPayoutID(i uint64) CoinOutputID
- func (b *Block) UnmarshalBlockHeadersParentIDAndTS(raw []byte) (BlockID, Timestamp)
- func (b *Block) UnmarshalSia(r io.Reader) error
- type BlockHeader
- type BlockHeight
- type BlockID
- type BlockStakeInput
- type BlockStakeOutput
- type BlockStakeOutputID
- type BlockStakeOutputIndexes
- type BlockchainInfo
- type ByteSlice
- type ChainConstants
- func (c *ChainConstants) GenesisBlock() Block
- func (c *ChainConstants) GenesisBlockID() BlockID
- func (c *ChainConstants) GenesisBlockStakeCount() (bsc Currency)
- func (c *ChainConstants) GenesisCoinCount() (cc Currency)
- func (c *ChainConstants) RootTarget() Target
- func (c *ChainConstants) StartDifficulty() Difficulty
- func (c *ChainConstants) Validate() error
- type Clock
- type CoinInput
- type CoinOutput
- type CoinOutputID
- type Currency
- func (x Currency) Add(y Currency) (c Currency)
- func (x Currency) Big() *big.Int
- func (x Currency) Cmp(y Currency) int
- func (x Currency) Cmp64(y uint64) int
- func (x Currency) Div(y Currency) (c Currency)
- func (x Currency) Div64(y uint64) (c Currency)
- func (x Currency) Equals(y Currency) bool
- func (x Currency) Equals64(y uint64) bool
- func (c Currency) IsZero() bool
- func (c Currency) MarshalJSON() ([]byte, error)
- func (c Currency) MarshalSia(w io.Writer) error
- func (x Currency) Mul(y Currency) (c Currency)
- func (x Currency) Mul64(y uint64) (c Currency)
- func (x Currency) MulFloat(y float64) (c Currency)
- func (x Currency) MulRat(y *big.Rat) (c Currency)
- func (x Currency) RoundDown(y Currency) (c Currency)
- func (c *Currency) Scan(s fmt.ScanState, ch rune) error
- func (x Currency) Sqrt() (c Currency)
- func (c Currency) String() string
- func (x Currency) Sub(y Currency) (c Currency)
- func (c Currency) Uint64() (u uint64, err error)
- func (c *Currency) UnmarshalJSON(b []byte) error
- func (c *Currency) UnmarshalSia(r io.Reader) error
- type CurrencyUnits
- type Difficulty
- func (x Difficulty) Big() *big.Int
- func (x Difficulty) Cmp(y Difficulty) int
- func (x Difficulty) Div64(y uint64) (c Difficulty)
- func (c Difficulty) MarshalJSON() ([]byte, error)
- func (c Difficulty) MarshalSia(w io.Writer) error
- func (c *Difficulty) Scan(s fmt.ScanState, ch rune) error
- func (c Difficulty) String() string
- func (c *Difficulty) UnmarshalJSON(b []byte) error
- func (c *Difficulty) UnmarshalSia(r io.Reader) error
- type InputLock
- type InputLockConstructor
- type InputLockProxy
- func (p InputLockProxy) AtomicSwapInputLock() (*AtomicSwapInputLock, bool)
- func (p InputLockProxy) Lock(inputIndex uint64, tx Transaction, key interface{}) error
- func (p InputLockProxy) MarshalJSON() ([]byte, error)
- func (p InputLockProxy) MarshalSia(w io.Writer) error
- func (p InputLockProxy) StrictCheck() error
- func (p InputLockProxy) Unlock(inputIndex uint64, tx Transaction) error
- func (p InputLockProxy) UnlockHash() UnlockHash
- func (p *InputLockProxy) UnmarshalJSON(b []byte) error
- func (p *InputLockProxy) UnmarshalSia(r io.Reader) error
- type OutputID
- type RawInputLockFormat
- type SiaPublicKey
- type SingleSignatureInputLock
- func (ss *SingleSignatureInputLock) Decode(rf RawInputLockFormat) error
- func (ss *SingleSignatureInputLock) EncodeCondition() []byte
- func (ss *SingleSignatureInputLock) EncodeFulfillment() []byte
- func (ss *SingleSignatureInputLock) Lock(inputIndex uint64, tx Transaction, key interface{}) error
- func (ss *SingleSignatureInputLock) MarshalSia(w io.Writer) error
- func (ss *SingleSignatureInputLock) StrictCheck() error
- func (ss *SingleSignatureInputLock) Unlock(inputIndex uint64, tx Transaction) error
- func (ss *SingleSignatureInputLock) UnmarshalSia(r io.Reader) error
- type Specifier
- type StdClock
- type Target
- func (x Target) AddDifficulties(y Target, rootDepth Target) (t Target)
- func (x Target) Cmp(y Target) int
- func (t Target) Difficulty(rootDepth Target) Difficulty
- func (t Target) Int() *big.Int
- func (t Target) Inverse() *big.Rat
- func (x Target) MulDifficulty(y *big.Rat, rootDepth Target) (t Target)
- func (t Target) Rat() *big.Rat
- func (x Target) SubtractDifficulties(y Target, rootDepth Target) (t Target)
- type Timestamp
- type TimestampSlice
- type Transaction
- func (t Transaction) BlockStakeOutputID(i uint64) BlockStakeOutputID
- func (t Transaction) CoinOutputID(i uint64) CoinOutputID
- func (t Transaction) CoinOutputSum() (sum Currency)
- func (t Transaction) ID() TransactionID
- func (t Transaction) InputSigHash(inputIndex uint64, extraObjects ...interface{}) (hash crypto.Hash)
- func (t Transaction) MarshalJSON() ([]byte, error)
- func (t Transaction) MarshalSia(w io.Writer) error
- func (t Transaction) StandaloneValid(currentHeight BlockHeight, blockSizeLimit uint64) (err error)
- func (t *Transaction) UnmarshalJSON(b []byte) error
- func (t *Transaction) UnmarshalSia(r io.Reader) error
- type TransactionID
- type TransactionShortID
- type TransactionVersion
- type UnknownInputLock
- func (u *UnknownInputLock) Decode(rf RawInputLockFormat) error
- func (u *UnknownInputLock) EncodeCondition() []byte
- func (u *UnknownInputLock) EncodeFulfillment() []byte
- func (u *UnknownInputLock) Lock(_ uint64, _ Transaction, _ interface{}) error
- func (u *UnknownInputLock) StrictCheck() error
- func (u *UnknownInputLock) Unlock(_ uint64, _ Transaction) error
- type UnlockHash
- func (uh UnlockHash) Cmp(other UnlockHash) int
- func (uh *UnlockHash) LoadString(strUH string) error
- func (uh UnlockHash) MarshalJSON() ([]byte, error)
- func (uh UnlockHash) MarshalSia(w io.Writer) error
- func (uh UnlockHash) String() string
- func (uh *UnlockHash) UnmarshalJSON(b []byte) error
- func (uh *UnlockHash) UnmarshalSia(r io.Reader) error
- type UnlockHashSlice
- type UnlockType
- type UnspentBlockStakeOutput
Constants ¶
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 )
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 )
const (
SpecifierLen = 16
)
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 ¶
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") )
var ( ErrInvalidInputLockType = errors.New("invalid input lock type") ErrUnlockConditionLocked = errors.New("unlock condition is already locked") // ErrUnknownUnlockType is an error returned in case // one tries to use an input lock of unknown type where it's not supported ErrUnknownUnlockType = errors.New("unknown unlock 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") )
Errors returned by input lock types.
var ( ErrInvalidPreImageSha256 = errors.New("invalid pre-image sha256") ErrInvalidRedeemer = errors.New("invalid input redeemer") )
Errors related to atomic swaps
var ( // These Specifiers enumerate the types of signatures that are recognized // by this implementation. If a signature's type is unrecognized, the // signature is treated as valid. Signatures using the special "entropy" // type are always treated as invalid; see Consensus.md for more details. SignatureEntropy = Specifier{'e', 'n', 't', 'r', 'o', 'p', 'y'} SignatureEd25519 = Specifier{'e', 'd', '2', '5', '5', '1', '9'} ErrEntropyKey = errors.New("transaction tries to sign an entproy public key") 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") )
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.
var ( ErrDoubleSpend = errors.New("transaction uses a parent object twice") ErrNonZeroRevision = errors.New("new file contract has a nonzero revision number") ErrTransactionTooLarge = errors.New("transaction is too large to fit in a block") ErrZeroMinerFee = errors.New("transaction has a zero value miner fee") ErrZeroOutput = errors.New("transaction cannot have an output or payout that has zero value") )
var ( // ErrNegativeDifficulty is the error that is returned if performing an // operation results in a negative difficulty. ErrNegativeDifficulty = errors.New("negative difficulty not allowed") )
var (
ErrNegativeTarget = errors.New("negative value used when converting to target")
)
Functions ¶
func RegisterUnlockType ¶ added in v0.6.0
func RegisterUnlockType(t UnlockType, ilc InputLockConstructor)
RegisterUnlockType registers the given non-nil locker constructor, for the given UnlockType, essentially linking the given locker constructor to the given type.
func UnregisterUnlockType ¶ added in v0.6.0
func UnregisterUnlockType(t UnlockType)
UnregisterUnlockType unregisters the given UnlockType, meaning the given UnlockType will no longer have a matching unlocker constructor.
Types ¶
type AtomicSwapClaimKey ¶ added in v0.6.0
type AtomicSwapClaimKey struct { PublicKey SiaPublicKey SecretKey ByteSlice Secret AtomicSwapSecret }
AtomicSwapClaimKey defines the claim key pair used by the participant/receiver of such a contract, used to lock the contract from their side.
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 defines the condition of an atomic swap contract/input-lock. Only used for encoding purposes.
type AtomicSwapFulfillment ¶ added in v0.6.0
type AtomicSwapFulfillment struct { PublicKey SiaPublicKey `json:"publickey"` Signature ByteSlice `json:"signature"` Secret AtomicSwapSecret `json:"secret"` }
AtomicSwapFulfillment defines the fulfillment of an atomic swap contract/input-lock. Only used for encoding purposes.
type AtomicSwapHashedSecret ¶ added in v0.6.0
AtomicSwapHashedSecret defines the 256 image byte slice, used as hashed secret within the Atomic Swap protocol/contract.
func NewAtomicSwapHashedSecret ¶ added in v1.0.2
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 AtomicSwapInputLock ¶ added in v0.6.0
type AtomicSwapInputLock struct { TimeLock Timestamp Sender, Receiver UnlockHash HashedSecret AtomicSwapHashedSecret PublicKey SiaPublicKey Signature ByteSlice Secret AtomicSwapSecret }
AtomicSwapInputLock (0x02) is a more advanced unlocker, which allows for a more advanced InputLock, 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 InputLock, the output can only be claimed by the sender, with no deadline in this phase.
func (*AtomicSwapInputLock) Decode ¶ added in v0.6.0
func (as *AtomicSwapInputLock) Decode(rf RawInputLockFormat) error
Decode implements InputLock.Decode
func (*AtomicSwapInputLock) EncodeCondition ¶ added in v0.6.0
func (as *AtomicSwapInputLock) EncodeCondition() []byte
EncodeCondition implements InputLock.EncodeCondition
func (*AtomicSwapInputLock) EncodeFulfillment ¶ added in v0.6.0
func (as *AtomicSwapInputLock) EncodeFulfillment() []byte
EncodeFulfillment implements InputLock.EncodeFulfillment
func (*AtomicSwapInputLock) Lock ¶ added in v0.6.0
func (as *AtomicSwapInputLock) Lock(inputIndex uint64, tx Transaction, key interface{}) error
Lock implements InputLock.Lock
func (*AtomicSwapInputLock) StrictCheck ¶ added in v0.6.0
func (as *AtomicSwapInputLock) StrictCheck() error
StrictCheck implements InputLock.StrictCheck
func (*AtomicSwapInputLock) Unlock ¶ added in v0.6.0
func (as *AtomicSwapInputLock) Unlock(inputIndex uint64, tx Transaction) error
Unlock implements InputLock.Unlock
type AtomicSwapRefundKey ¶ added in v0.6.0
type AtomicSwapRefundKey struct { PublicKey SiaPublicKey SecretKey ByteSlice }
AtomicSwapRefundKey defines the refund key pair used by the initiator/sender of such a contract.
type AtomicSwapSecret ¶ added in v0.6.0
AtomicSwapSecret defines the 256 pre-image byte slice, used as secret within the Atomic Swap protocol/contract.
func NewAtomicSwapSecret ¶ added in v1.0.2
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 []CoinOutput `json:"minerpayouts"` Transactions []Transaction `json:"transactions"` }
A Block is a summary of changes to the state that have occurred since the previous block. Blocks reference the ID of the previous block (their "parent"), creating the linked-list commonly known as the blockchain. Their primary function is to bundle together transactions on the network. Blocks are created by "blockcreators," who collect transactions from other nodes, and then use there BlockStake and some other parameters to come below a given target.
func (Block) CalculateTotalMinerFees ¶ added in v1.0.2
CalculateTotalMinerFees determines the sum of the minerfees
func (Block) ID ¶
ID returns the ID of a Block, which is calculated by hashing the concatenation of the block's parent's ID, nonce, and the result of the b.MerkleRoot(). It is equivalent to calling block.Header().ID()
func (Block) MarshalSia ¶
MarshalSia implements the encoding.SiaMarshaler interface.
func (Block) MerkleRoot ¶
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
UnmarshalBlockHeadersParentIDAndTS The MerkleRoot is not unmarshalled from the header because
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 ¶
func (BlockID) MarshalJSON ¶
MarshalJSON marshales a block id as a hex string.
func (*BlockID) UnmarshalJSON ¶
UnmarshalJSON decodes the json hex string of the block id.
type BlockStakeInput ¶
type BlockStakeInput struct { ParentID BlockStakeOutputID `json:"parentid"` Unlocker InputLockProxy `json:"unlocker"` }
A BlockStakeInput consumes a BlockStakeOutput and adds the blockstakes to the set of blockstakes that can be spent in the transaction. The ParentID points to the output that is getting consumed, and the UnlockConditions contain the rules for spending the output. The UnlockConditions must match the UnlockHash of the output.
type BlockStakeOutput ¶
type BlockStakeOutput struct { Value Currency `json:"value"` UnlockHash UnlockHash `json:"unlockhash"` }
A BlockStakeOutput holds a volume of blockstakes. Outputs must be spent atomically; that is, they must all be spent in the same transaction. The UnlockHash is the hash of a set of UnlockConditions that must be fulfilled in order to spend the output.
type BlockStakeOutputID ¶
func (*BlockStakeOutputID) LoadString ¶ added in v0.6.0
func (bsoid *BlockStakeOutputID) LoadString(str string) error
LoadString loads the given blockstake output id from a hex string
func (BlockStakeOutputID) MarshalJSON ¶
func (bsoid BlockStakeOutputID) MarshalJSON() ([]byte, error)
MarshalJSON marshals an blockstake output id as a hex string.
func (BlockStakeOutputID) String ¶
func (bsoid BlockStakeOutputID) String() string
String prints the blockstake output id in hex.
func (*BlockStakeOutputID) UnmarshalJSON ¶
func (bsoid *BlockStakeOutputID) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes the json hex string of the blockstake output id.
type BlockStakeOutputIndexes ¶ added in v0.1.0
type BlockStakeOutputIndexes struct { BlockHeight BlockHeight TransactionIndex uint64 OutputIndex uint64 }
BlockStakeOutputIndexes groups the block height, the transaction index and the output index to uniquely identify a blockstake output. These indexes and the value are required for the POBS protocol.
type BlockchainInfo ¶ added in v0.6.0
type BlockchainInfo struct { Name string ChainVersion build.ProtocolVersion ProtocolVersion build.ProtocolVersion }
BlockchainInfo contains information about a blockchain.
func DefaultBlockchainInfo ¶ added in v0.6.0
func DefaultBlockchainInfo() BlockchainInfo
DefaultBlockchainInfo returns the blockchain information for the default (Rivine) blockchain, using the version which is set as part of the build process.
type ByteSlice ¶ added in v0.6.0
type ByteSlice []byte
ByteSlice defines any kind of raw binary value, in-memory defined as a byte slice, and JSON-encoded in hexadecimal form.
func (*ByteSlice) LoadString ¶ added in v0.6.0
LoadString loads a byte slice from a hex-formatted string.
func (ByteSlice) MarshalJSON ¶ added in v0.6.0
MarshalJSON marshals a byte slice as a hex string.
func (*ByteSlice) UnmarshalJSON ¶ added in v0.6.0
UnmarshalJSON decodes the json string of the byte slice.
type ChainConstants ¶ added in v0.6.0
type ChainConstants struct { // BlockSizeLimit is the maximum size a single block can have, in bytes BlockSizeLimit uint64 RootDepth Target // BlockFrequency is the average timespan between blocks, in seconds. // I.E.: On average, 1 block will be created every 1 in *BlockFrequency* seconds BlockFrequency BlockHeight // MaturityDelay is the amount of blocks for which a miner payout must "mature" before it // gets added to the consensus set. Until this time has passed, a miner payout cannot be spend MaturityDelay BlockHeight MedianTimestampWindow uint64 // TargetWindow is the amount of blocks to go back to adjust the difficulty of the network. TargetWindow BlockHeight // MaxAdjustmentUp is the maximum multiplier to difficulty over the course of 500 blocks MaxAdjustmentUp *big.Rat // MaxAdjustmentDown is the minimum multiplier to the difficulty over the course of 500 blocks MaxAdjustmentDown *big.Rat // FutureThreshold is the amount of seconds that a block timestamp can be "in the future", // while stil being accepted by the consensus set. I.E. a block is accepted if: // block timestamp < current timestamp + future treshold // Blocks who's timestamp is bigger than this value will not be accepted, but they might be // recondisered as soon as their timestamp is within the future treshold FutureThreshold Timestamp // ExtremeFutureThreshold is the maximum amount of time a block timstamp can be in the future // before sais block is outright rejected. Blocks who's timestamp is between now + FutureThreshold // and now + ExtremeFutureThreshold are kept and retried as soon as their timestamp is lower than // now + FutureThreshold. In case the block timestamp is higher than now + ExtremeFutureThreshold, we // consider that the block will no longer be valid as soon as its timestamp becomes accepteable, the block // will no longer be on the longest chain. Also, we can't keep all the blocks to eventually verify this as that // opens up a DOS vector ExtremeFutureThreshold Timestamp // StakeModifierDelay is the amount of blocks to go back to start calculating the Stake Modifier, // which is used in the proof of blockstake protoco. The formula for the Stake Modifier is as follows: // For x = 0 .. 255 // bit x of Stake Modifier = bit x of h(block N-(StakeModifierDelay+x)) StakeModifierDelay BlockHeight // BlockStakeAging is the amount of seconds to wait before a blockstake output // which is not on index 0 in the first transaction of a block can be used to // participate in the proof of blockstake protocol BlockStakeAging uint64 // BlockCreatorFee is the amount of hastings you get for creating a block on top of // all the other rewards such as collected transaction fees. BlockCreatorFee Currency // MinimumTransactionFee is the minimum amount of hastings you need to pay // in order to get your transaction to be accepted by block creators. MinimumTransactionFee Currency // TransactionFeeBeneficiary 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. TransactionFeeBeneficiary UnlockHash // 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 CurrencyUnits CurrencyUnits }
ChainConstants is a utility struct which groups together the chain configuration
func DefaultChainConstants ¶ added in v0.6.0
func DefaultChainConstants() ChainConstants
DefaultChainConstants provide sane defaults for a new chain. Not all constants are set, since some (e.g. GenesisTimestamp) are chain specific, and this also allows some santiy checking later GenesisTimestamp, GenesisBlockStakeAllocation, and GenesisCoinDistribution aren't set as there is no such thing as a "sane default" for these variables since they are really chain specific
func (*ChainConstants) GenesisBlock ¶ added in v0.6.0
func (c *ChainConstants) GenesisBlock() Block
GenesisBlock returns the genesis block based on the blockchain config
func (*ChainConstants) GenesisBlockID ¶ added in v0.6.0
func (c *ChainConstants) GenesisBlockID() BlockID
GenesisBlockID returns the ID of the genesis Block
func (*ChainConstants) GenesisBlockStakeCount ¶ added in v0.6.0
func (c *ChainConstants) GenesisBlockStakeCount() (bsc Currency)
GenesisBlockStakeCount computes and returns the total amount of block stakes allocated in the genesis block.
func (*ChainConstants) GenesisCoinCount ¶ added in v0.6.0
func (c *ChainConstants) GenesisCoinCount() (cc Currency)
GenesisCoinCount computes and returns the total amount of coins distributed in the genesis block.
func (*ChainConstants) RootTarget ¶ added in v0.6.0
func (c *ChainConstants) RootTarget() Target
RootTarget computes the new target, based on the root depth and the computed start difficulty
func (*ChainConstants) StartDifficulty ¶ added in v0.6.0
func (c *ChainConstants) StartDifficulty() Difficulty
StartDifficulty computes the start difficulty based on the set block frequency, and the computer genesis block stake count.
func (*ChainConstants) Validate ¶ added in v0.6.0
func (c *ChainConstants) Validate() error
Validate does a sanity check on some of the constants to see if proper initialization is done
type Clock ¶
type Clock interface {
Now() Timestamp
}
Clock allows clients to retrieve the current time.
type CoinInput ¶ added in v0.1.0
type CoinInput struct { ParentID CoinOutputID `json:"parentid"` Unlocker InputLockProxy `json:"unlocker"` }
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"` UnlockHash UnlockHash `json:"unlockhash"` }
A CoinOutput holds a volume of siacoins. Outputs must be spent atomically; that is, they must all be spent in the same transaction. The UnlockHash is the hash of the UnlockConditions that must be fulfilled in order to spend the output.
type CoinOutputID ¶ added in v0.1.0
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 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 ¶
NewCurrency creates a Currency value from a big.Int. Undefined behavior occurs if a negative input is used.
func NewCurrency64 ¶
NewCurrency64 creates a Currency value from a uint64.
func (Currency) Big ¶
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 ¶
Cmp compares two Currency values. The return value follows the convention of math/big.
func (Currency) Cmp64 ¶ added in v0.6.0
Cmp64 compares x to a uint64. The return value follows the convention of math/big.
func (Currency) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Currency) MarshalSia ¶
MarshalSia implements the encoding.SiaMarshaler interface. It writes the byte-slice representation of the Currency's internal big.Int to w. Note that as the bytes of the big.Int correspond to the absolute value of the integer, there is no way to marshal a negative Currency.
func (Currency) MulFloat ¶
COMPATv0.4.0 - until the first 10e3 blocks have been archived, MulFloat is needed while verifying the first set of blocks.
MulFloat returns a new Currency value y = c * x, where x is a float64. Behavior is undefined when x is negative.
func (*Currency) Scan ¶
Scan implements the fmt.Scanner interface, allowing Currency values to be scanned from text.
func (Currency) Sqrt ¶
Sqrt returns a new Currency value y = sqrt(c). Result is rounded down to the nearest integer.
func (Currency) Uint64 ¶
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 ¶
UnmarshalJSON implements the json.Unmarshaler interface. An error is returned if a negative number is provided.
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 Difficulty ¶ added in v0.1.0
type Difficulty struct {
// contains filtered or unexported fields
}
A Difficulty represents a number in number of blockstake times time in seconds Normally the difficulty is the number of active blockstake times the BlockFrequency. ex. If the number of active blockstake grows, the difficulty will also increase to maintain the same BlockFrequency.
func NewDifficulty ¶ added in v0.1.0
func NewDifficulty(b *big.Int) (d Difficulty)
NewDifficulty creates a Difficulty value from a big.Int. Undefined behavior occurs if a negative input is used.
func (Difficulty) Big ¶ added in v0.1.0
func (x Difficulty) Big() *big.Int
Big returns the value of c as a *big.Int. Importantly, it does not provide access to the c's internal big.Int object, only a copy.
func (Difficulty) Cmp ¶ added in v0.1.0
func (x Difficulty) Cmp(y Difficulty) int
Cmp compares two Difficulty values. The return value follows the convention of math/big.
func (Difficulty) Div64 ¶ added in v0.1.0
func (x Difficulty) Div64(y uint64) (c Difficulty)
Div64 returns a new Difficulty value c = x / y.
func (Difficulty) MarshalJSON ¶ added in v0.1.0
func (c Difficulty) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (Difficulty) MarshalSia ¶ added in v0.1.0
func (c Difficulty) MarshalSia(w io.Writer) error
MarshalSia implements the encoding.SiaMarshaler interface. It writes the byte-slice representation of the Difficulty's internal big.Int to w. Note that as the bytes of the big.Int correspond to the absolute value of the integer, there is no way to marshal a negative Difficulty.
func (*Difficulty) Scan ¶ added in v0.1.0
func (c *Difficulty) Scan(s fmt.ScanState, ch rune) error
Scan implements the fmt.Scanner interface, allowing Difficulty values to be scanned from text.
func (Difficulty) String ¶ added in v0.1.0
func (c Difficulty) String() string
String implements the fmt.Stringer interface.
func (*Difficulty) UnmarshalJSON ¶ added in v0.1.0
func (c *Difficulty) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface. An error is returned if a negative number is provided.
func (*Difficulty) UnmarshalSia ¶ added in v0.1.0
func (c *Difficulty) UnmarshalSia(r io.Reader) error
UnmarshalSia implements the encoding.SiaUnmarshaler interface.
type InputLock ¶ added in v0.6.0
type InputLock interface { // Lock the current Input within the context of // the transaction it exists in and its position in there. Lock(inputIndex uint64, tx Transaction, key interface{}) error // Unlock checks if the Input it lives in can be used (thus unlocked), // within the context of the transaction it lives in, the defined UnlockConditions // (defined by its UnlockHash) and the extra input parameters serializd as well. Unlock(inputIndex uint64, tx Transaction) error // StrictCheck ensures that all conditions and unlock input params, // are known and strict. This is useful as to make sure an input (and thus transaction) // can be understood by all nodes in the network. StrictCheck() error // EncodeCondition encodes the unlock conditon part of the InputLock, // which is the static part of an input lock, also used to generate the unlock hash, // and thus defined by the sender, and redefined by the receiver. EncodeCondition() []byte // EncodeFulfillment encodes the encode fulfillment part of the InputLock, // which is the dynamic part (the input parameters or signature as to speak) of an input lock. EncodeFulfillment() []byte // Decode the unlockCondition and fulfillment // from binary format into a known in-memory format. Decode(rf RawInputLockFormat) error }
InputLock is a generic interface which hides the InputLock, which is all serialized data used for generating a determenistic UnlockHash, as well as the input used to unlock the input in the context of the used InputLock, extra serialized input and Transaction it lives in.
type InputLockConstructor ¶ added in v0.6.0
type InputLockConstructor func() InputLock
InputLockConstructor is used to create a fresh internal input lock.
type InputLockProxy ¶ added in v0.6.0
type InputLockProxy struct {
// contains filtered or unexported fields
}
InputLockProxy contains either no lock, or it does, when it does it forwwards the functionality to the internal InputLock, otherwise it acts as a nop-InputLock.
InputLockProxy serves 2 important purposes:
- it provides a sane default for the InputLock interface, which will turn the input lock into a nop-lock, should the input not be defined.
- it makes it so that all inputlocks are serialized in the same way. this is important as it means we can ensure that an input's unlock hash, is the same, no matter if it's a known or unknown unlock type.
The latter point (2) is very important, as it is the one requirement that allows soft-forks to safely add new input locks, without having to be afraid that their transactions will screw up older/non-forked nodes.
func NewAtomicSwapInputLock ¶ added in v0.6.0
func NewAtomicSwapInputLock(condition AtomicSwapCondition) InputLockProxy
NewAtomicSwapInputLock creates a new input lock as part of an atomic swap, using the given public keys, timelock and timestamp. Prior to the timestamp only the receiver can claim, using the required secret, after te deadline only the sender can claim a fund.
func NewInputLockProxy ¶ added in v0.6.0
func NewInputLockProxy(t UnlockType, il InputLock) InputLockProxy
NewInputLockProxy creates a new input lock proxy, from a type and (existing) input lock.
func NewSingleSignatureInputLock ¶ added in v0.6.0
func NewSingleSignatureInputLock(pk SiaPublicKey) InputLockProxy
NewSingleSignatureInputLock creates a new input lock, using the given public key and signature.
func (InputLockProxy) AtomicSwapInputLock ¶ added in v1.0.2
func (p InputLockProxy) AtomicSwapInputLock() (*AtomicSwapInputLock, bool)
AtomicSwapInputLock casts this input lock proxy into a AtomicSwapInputLock if possible.
func (InputLockProxy) Lock ¶ added in v0.6.0
func (p InputLockProxy) Lock(inputIndex uint64, tx Transaction, key interface{}) error
Lock implements InputLock.Lock
func (InputLockProxy) MarshalJSON ¶ added in v0.6.0
func (p InputLockProxy) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.MarshalJSON
func (InputLockProxy) MarshalSia ¶ added in v0.6.0
func (p InputLockProxy) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.MarshalSia
func (InputLockProxy) StrictCheck ¶ added in v0.6.0
func (p InputLockProxy) StrictCheck() error
StrictCheck implements InputLock.StrictCheck
func (InputLockProxy) Unlock ¶ added in v0.6.0
func (p InputLockProxy) Unlock(inputIndex uint64, tx Transaction) error
Unlock implements InputLock.Unlock
func (InputLockProxy) UnlockHash ¶ added in v0.6.0
func (p InputLockProxy) UnlockHash() UnlockHash
UnlockHash implements InputLock.UnlockHash
func (*InputLockProxy) UnmarshalJSON ¶ added in v0.6.0
func (p *InputLockProxy) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON
func (*InputLockProxy) UnmarshalSia ¶ added in v0.6.0
func (p *InputLockProxy) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaMarshaler.UnmarshalSia
type OutputID ¶
func (*OutputID) LoadString ¶ added in v0.6.0
LoadString loads the given output id from a hex string
func (OutputID) MarshalJSON ¶
MarshalJSON marshals an output id as a hex string.
func (*OutputID) UnmarshalJSON ¶
UnmarshalJSON decodes the json hex string of the output id.
type RawInputLockFormat ¶ added in v0.6.0
RawInputLockFormat defines the binary format of a condition-fullfilment pair, used internally of an input lock.
func (RawInputLockFormat) MarshalSia ¶ added in v0.6.0
func (rf RawInputLockFormat) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.MarshalSia
func (*RawInputLockFormat) UnmarshalSia ¶ added in v0.6.0
func (rf *RawInputLockFormat) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaUnmarshaler.UnmarshalSia
type SiaPublicKey ¶
A SiaPublicKey is a public key prefixed by a Specifier. The Specifier indicates the algorithm used for signing and verification. Unrecognized algorithms will always verify, which allows new algorithms to be added to the protocol via a soft-fork.
func Ed25519PublicKey ¶ added in v0.6.0
func Ed25519PublicKey(pk crypto.PublicKey) SiaPublicKey
Ed25519PublicKey returns pk as a SiaPublicKey, denoting its algorithm as Ed25519.
func (*SiaPublicKey) LoadString ¶ added in v0.6.0
func (spk *SiaPublicKey) LoadString(s string) error
LoadString is the inverse of SiaPublicKey.String().
func (SiaPublicKey) MarshalJSON ¶ added in v0.6.0
func (spk SiaPublicKey) MarshalJSON() ([]byte, error)
MarshalJSON marshals a byte slice as a hex string.
func (*SiaPublicKey) String ¶ added in v0.1.0
func (spk *SiaPublicKey) String() string
String defines how to print a SiaPublicKey - hex is used to keep things compact during logging. The key type prefix and lack of a checksum help to separate it from a sia address.
func (*SiaPublicKey) UnmarshalJSON ¶ added in v0.6.0
func (spk *SiaPublicKey) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes the json string of the byte slice.
type SingleSignatureInputLock ¶ added in v0.6.0
type SingleSignatureInputLock struct { PublicKey SiaPublicKey Signature ByteSlice }
SingleSignatureInputLock (0x01) is the only and most simplest unlocker. It uses a public key (used as UnlockHash), such that only one public key is expected. The spender will need to proof ownership of that public key by providing a correct signature.
func (*SingleSignatureInputLock) Decode ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) Decode(rf RawInputLockFormat) error
Decode implements InputLock.Decode
func (*SingleSignatureInputLock) EncodeCondition ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) EncodeCondition() []byte
EncodeCondition implements InputLock.EncodeCondition
func (*SingleSignatureInputLock) EncodeFulfillment ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) EncodeFulfillment() []byte
EncodeFulfillment implements InputLock.EncodeFulfillment
func (*SingleSignatureInputLock) Lock ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) Lock(inputIndex uint64, tx Transaction, key interface{}) error
Lock implements InputLock.Lock
func (*SingleSignatureInputLock) MarshalSia ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.MarshalSia
func (*SingleSignatureInputLock) StrictCheck ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) StrictCheck() error
StrictCheck implements InputLock.StrictCheck
func (*SingleSignatureInputLock) Unlock ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) Unlock(inputIndex uint64, tx Transaction) error
Unlock implements InputLock.Unlock
func (*SingleSignatureInputLock) UnmarshalSia ¶ added in v0.6.0
func (ss *SingleSignatureInputLock) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaUnmarshaler.UnmarshalSia
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
LoadString loads a stringified specifier into the specifier type
func (Specifier) MarshalJSON ¶
MarshalJSON marshals a specifier as a string.
func (*Specifier) UnmarshalJSON ¶
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.
type Target ¶
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 ¶
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 ¶
RatToTarget converts a big.Rat to a Target.
func (Target) AddDifficulties ¶
AddDifficulties returns the resulting target with the difficulty of 'x' and 'y' are added together. Note that the difficulty is the inverse of the target. The sum is defined by:
sum(x, y) = 1/(1/x + 1/y)
func (Target) Cmp ¶
Cmp compares the difficulties of two targets. Note that the difficulty is the inverse of the target. The results are as follows:
-1 if x < y 0 if x == y +1 if x > y
func (Target) Difficulty ¶
func (t Target) Difficulty(rootDepth Target) Difficulty
Difficulty returns the difficulty associated with a given target.
func (Target) MulDifficulty ¶
Mul multiplies the difficulty of a target by y. The product is defined by:
y / x
func (Target) SubtractDifficulties ¶
SubtractDifficulties returns the resulting target with the difficulty of 'x' is subtracted from the target with difficulty 'y'. Note that the difficulty is the inverse of the target. The difference is defined by:
sum(x, y) = 1/(1/x - 1/y)
type Timestamp ¶
type Timestamp uint64
func CurrentTimestamp ¶
func CurrentTimestamp() Timestamp
CurrentTimestamp returns the current time as a Timestamp.
func OffsetTimestamp ¶ added in v0.6.0
CurrentTimestamp returns the offset based on the current time as a Timestamp.
func (*Timestamp) LoadString ¶ added in v1.0.2
type TimestampSlice ¶
type TimestampSlice []Timestamp
func (TimestampSlice) Less ¶
func (ts TimestampSlice) Less(i, j int) bool
Less is part of sort.Interface
type Transaction ¶
type Transaction struct { CoinInputs []CoinInput CoinOutputs []CoinOutput BlockStakeInputs []BlockStakeInput BlockStakeOutputs []BlockStakeOutput MinerFees []Currency ArbitraryData []byte // contains filtered or unexported fields }
A Transaction is an atomic component of a block. Transactions can contain inputs and outputs and even arbitrary data. They can also contain signatures to prove that a given party has approved the transaction, or at least a particular subset of it.
Transactions can depend on other previous transactions in the same block, but transactions cannot spend outputs that they create or otherwise be self-dependent.
func (Transaction) BlockStakeOutputID ¶
func (t Transaction) BlockStakeOutputID(i uint64) BlockStakeOutputID
BlockStakeOutputID returns the ID of a BlockStakeOutput at the given index, which is calculated by hashing the concatenation of the BlockStakeOutput Specifier, all of the fields in the transaction (except the signatures), and output index.
func (Transaction) CoinOutputID ¶ added in v0.1.0
func (t Transaction) CoinOutputID(i uint64) CoinOutputID
CoinOutputID returns the ID of a coin output at the given index, which is calculated by hashing the concatenation of the CoinOutput Specifier, all of the fields in the transaction (except the signatures), and output index.
func (Transaction) CoinOutputSum ¶ added in v0.1.0
func (t Transaction) CoinOutputSum() (sum Currency)
CoinOutputSum returns the sum of all the coin outputs in the transaction, which must match the sum of all the coin inputs.
func (Transaction) ID ¶
func (t Transaction) ID() TransactionID
ID returns the id of a transaction, which is taken by marshalling all of the fields except for the signatures and taking the hash of the result.
func (Transaction) InputSigHash ¶ added in v0.6.0
func (t Transaction) InputSigHash(inputIndex uint64, extraObjects ...interface{}) (hash crypto.Hash)
InputSigHash returns the hash of all fields in a transaction, relevant to an input sig.
func (Transaction) MarshalJSON ¶ added in v0.6.0
func (t Transaction) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (Transaction) MarshalSia ¶ added in v0.6.0
func (t Transaction) MarshalSia(w io.Writer) error
MarshalSia implements the encoding.SiaMarshaler interface.
func (Transaction) StandaloneValid ¶
func (t Transaction) StandaloneValid(currentHeight BlockHeight, blockSizeLimit uint64) (err error)
StandaloneValid returns an error if a transaction is not valid in any context, for example if the same output is spent twice in the same transaction. StandaloneValid will not check that all outputs being spent are legal outputs, as it has no confirmed or unconfirmed set to look at.
func (*Transaction) UnmarshalJSON ¶ added in v0.6.0
func (t *Transaction) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Transaction) UnmarshalSia ¶ added in v0.6.0
func (t *Transaction) UnmarshalSia(r io.Reader) error
UnmarshalSia implements the encoding.SiaUnmarshaler interface.
type TransactionID ¶
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) UnmarshalJSON ¶
func (tid *TransactionID) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes the json hex string of the id.
type TransactionShortID ¶ added in v0.6.0
type TransactionShortID uint64
TransactionShortID is another way to uniquely identify a transaction, just as the default hash-based (32-byte) ID uniquely identifies a transaction as well. The differences with the default/long ID is that it is 4 times smaller (only 8 bytes), and is not just unique, but also ordered. Meaning that byte-wise, this short ID informs about its position within the blockchain, on such a precise level that you not only to which block it belongs, but also its position within that transaction.
The position (indicated by the transaction index), is obviously not as important as it is more of a client-side choice, rather something agreed upon by consensus.
In memory the transaction is used and manipulated as a uint64, where the first 50 bits (going from left to right), define the block height, which can have a maximum of about 1.126e+15 (2^50) blocks, and the last 14 bits (again going from left to right), define the transaction sequence ID, or in other words, its unique and shorted position within a given block. When serialized into a binary (byte slice) format, is done so using LittleEndian, as to correctly preserve the sorted property in all cases. Meaning that the ID can be represented in memory and in serialized form as follows:
[ blockHeight: 50 bits | txSequenceID: 14 bits ]
func NewTransactionShortID ¶ added in v0.6.0
func NewTransactionShortID(height BlockHeight, txSequenceID uint16) TransactionShortID
NewTransactionShortID creates a new Transaction ShortID, combining a blockheight together with a transaction index. See the TransactionShortID type for more information.
func (TransactionShortID) BlockHeight ¶ added in v0.6.0
func (txsid TransactionShortID) BlockHeight() BlockHeight
BlockHeight returns the block height part of the transacton short ID.
func (TransactionShortID) MarshalSia ¶ added in v0.6.0
func (txsid TransactionShortID) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.SiaMarshaler
func (TransactionShortID) TransactionSequenceIndex ¶ added in v0.6.0
func (txsid TransactionShortID) TransactionSequenceIndex() uint16
TransactionSequenceIndex returns the transaction sequence index, which is the local (sequence) index of the transaction within a block, of the transacton short ID.
func (*TransactionShortID) UnmarshalSia ¶ added in v0.6.0
func (txsid *TransactionShortID) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaMarshaler.UnmarshalSia
type TransactionVersion ¶ added in v0.6.0
type TransactionVersion byte
TransactionVersion defines the format version of a transaction. Currently only one format exists and it is identified by 0x01 (TransactionVersionOne). 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 ( // TransactionVersionOne defines the initial (and currently only) // version format. Any other version number is concidered invalid. TransactionVersionOne TransactionVersion = iota )
func (TransactionVersion) MarshalSia ¶ added in v0.6.0
func (v TransactionVersion) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.MarshalSia
func (*TransactionVersion) UnmarshalSia ¶ added in v0.6.0
func (v *TransactionVersion) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaUnmarshaler.UnmarshalSia
type UnknownInputLock ¶ added in v0.6.0
type UnknownInputLock struct {
Condition, Fulfillment []byte
}
UnknownInputLock is used for all types which are unknown, this allows soft-forks to define their own input lock types, without breaking our code.
Unknown types are always Locked and Unlocked, but do not pass the Strict Check.
func (*UnknownInputLock) Decode ¶ added in v0.6.0
func (u *UnknownInputLock) Decode(rf RawInputLockFormat) error
Decode implements InputLock.Decode
func (*UnknownInputLock) EncodeCondition ¶ added in v0.6.0
func (u *UnknownInputLock) EncodeCondition() []byte
EncodeCondition implements InputLock.EncodeCondition
func (*UnknownInputLock) EncodeFulfillment ¶ added in v0.6.0
func (u *UnknownInputLock) EncodeFulfillment() []byte
EncodeFulfillment implements InputLock.EncodeFulfillment
func (*UnknownInputLock) Lock ¶ added in v0.6.0
func (u *UnknownInputLock) Lock(_ uint64, _ Transaction, _ interface{}) error
Lock implements InputLock.Lock
func (*UnknownInputLock) StrictCheck ¶ added in v0.6.0
func (u *UnknownInputLock) StrictCheck() error
StrictCheck implements InputLock.StrictCheck
func (*UnknownInputLock) Unlock ¶ added in v0.6.0
func (u *UnknownInputLock) Unlock(_ uint64, _ Transaction) error
Unlock implements InputLock.Unlock
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.
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.2
func (uh UnlockHash) Cmp(other UnlockHash) int
Cmp compares returns an integer comparing two unlock hashes lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b. A nil argument is equivalent to an empty slice.
func (*UnlockHash) LoadString ¶
func (uh *UnlockHash) LoadString(strUH string) error
LoadString loads a hex representation (including checksum) of an unlock hash into an unlock hash object. An error is returned if the string is invalid or fails the checksum.
func (UnlockHash) MarshalJSON ¶
func (uh UnlockHash) MarshalJSON() ([]byte, error)
MarshalJSON is implemented on the unlock hash to always produce a hex string upon marshalling.
func (UnlockHash) MarshalSia ¶ added in v0.6.0
func (uh UnlockHash) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.MarshalSia
func (UnlockHash) String ¶
func (uh UnlockHash) String() string
String returns the hex representation of the unlock hash as a string - this includes a checksum.
func (*UnlockHash) UnmarshalJSON ¶
func (uh *UnlockHash) UnmarshalJSON(b []byte) error
UnmarshalJSON is implemented on the unlock hash to recover an unlock hash that has been encoded to a hex string.
func (*UnlockHash) UnmarshalSia ¶ added in v0.6.0
func (uh *UnlockHash) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaUnmarshaler.UnmarshalSia
type UnlockHashSlice ¶
type UnlockHashSlice []UnlockHash
UnlockHashSlice defines an optionally sorted slice of unlock hashes.
func (UnlockHashSlice) Len ¶
func (uhs UnlockHashSlice) Len() int
Len implements the Len method of sort.Interface.
func (UnlockHashSlice) Less ¶
func (uhs UnlockHashSlice) Less(i, j int) bool
Less implements the Less method of sort.Interface.
func (UnlockHashSlice) Swap ¶
func (uhs UnlockHashSlice) Swap(i, j int)
Swap implements the Swap method of sort.Interface.
type UnlockType ¶ added in v0.6.0
type UnlockType byte
UnlockType defines the type of an unlock condition-fulfillment pair.
const ( // UnlockTypeNil defines a nil (empty) Input Lock and is the default. UnlockTypeNil UnlockType = iota // UnlockTypeSingleSignature 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. UnlockTypeSingleSignature // UnlockTypeAtomicSwap provides a more advanced unlocker, // which allows for a more advanced InputLock, // 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 InputLock, // the output can only be claimed by the sender, with no deadline in this phas UnlockTypeAtomicSwap )
func (UnlockType) MarshalSia ¶ added in v0.6.0
func (t UnlockType) MarshalSia(w io.Writer) error
MarshalSia implements SiaMarshaler.MarshalSia
func (*UnlockType) UnmarshalSia ¶ added in v0.6.0
func (t *UnlockType) UnmarshalSia(r io.Reader) error
UnmarshalSia implements SiaUnmarshaler.UnmarshalSia
type UnspentBlockStakeOutput ¶ added in v0.1.0
type UnspentBlockStakeOutput struct { BlockStakeOutputID BlockStakeOutputID Indexes BlockStakeOutputIndexes Value Currency UnlockHash UnlockHash }
UnspentBlockStakeOutput groups the BlockStakeOutputID, the block height, the transaction index, the output index and the value