Documentation ¶
Index ¶
- Constants
- Variables
- func BlockIdsAsBytes(ids []BlockID) ([]byte, error)
- func BytesToInterface(buf []byte, i interface{}) error
- func InterfaceToBytes(i interface{}) ([]byte, error)
- func IsProcessingError(err error) bool
- func NIPSTChallengeAsBytes(challenge *NIPSTChallenge) ([]byte, error)
- func TxIdsAsBytes(ids []TransactionId) ([]byte, error)
- type ActivationTx
- type ActivationTxHeader
- func (atxh *ActivationTxHeader) Bytes() []byte
- func (atxh *ActivationTxHeader) Hash32() Hash32
- func (atxh *ActivationTxHeader) Id() AtxId
- func (atxh *ActivationTxHeader) SetId(id *AtxId)
- func (atxh *ActivationTxHeader) ShortString() string
- func (atxh *ActivationTxHeader) TargetEpoch(layersPerEpoch uint16) EpochId
- type Address
- type AtxId
- type Block
- type BlockEligibilityProof
- type BlockHeader
- type BlockID
- type DoubleCache
- type DoubleResultCache
- type EpochId
- type Hash12
- type Hash20
- func (h Hash20) Big() *big.Int
- func (h Hash20) Bytes() []byte
- func (h Hash20) Format(s fmt.State, c rune)
- func (h Hash20) Hex() string
- func (h Hash20) MarshalText() ([]byte, error)
- func (h *Hash20) SetBytes(b []byte)
- func (h Hash20) ShortString() string
- func (h Hash20) String() string
- func (h Hash20) ToHash32() Hash32
- func (h *Hash20) UnmarshalJSON(input []byte) error
- func (h *Hash20) UnmarshalText(input []byte) error
- type Hash32
- func BigToHash(b *big.Int) Hash32
- func BytesToHash(b []byte) Hash32
- func CalcAtxHash32(atx *ActivationTx) Hash32
- func CalcBlockHash32Presorted(sortedView []BlockID, additionalBytes []byte) Hash32
- func CalcBlocksHash32(view []BlockID, additionalBytes []byte) Hash32
- func CalcHash32(data []byte) Hash32
- func HexToHash32(s string) Hash32
- func (h Hash32) Big() *big.Int
- func (h Hash32) Bytes() []byte
- func (h Hash32) Format(s fmt.State, c rune)
- func (h Hash32) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash32) Hex() string
- func (h Hash32) MarshalText() ([]byte, error)
- func (h *Hash32) Scan(src interface{}) error
- func (h *Hash32) SetBytes(b []byte)
- func (h Hash32) ShortString() string
- func (h Hash32) String() string
- func (h Hash32) TerminalString() string
- func (h Hash32) ToHash20() Hash20
- func (h *Hash32) UnmarshalJSON(input []byte) error
- func (h *Hash32) UnmarshalText(input []byte) error
- type InnerActivationTx
- type InnerTransaction
- type Layer
- type LayerID
- type MiniBlock
- type NIPST
- type NIPSTChallenge
- type NodeId
- type PoetProof
- type PoetProofMessage
- type PoetRound
- type PostProof
- type ProcessingError
- type Reward
- type Signed
- type StorageSize
- type Transaction
- type TransactionId
- type Vrf
Constants ¶
const ( // HashLength is the expected length of the hash Hash32Length = 32 Hash20Length = 20 Hash12Length = 12 )
const (
// AddressLength is the expected length of the address
AddressLength = 20
)
Variables ¶
var ( Big1 = big.NewInt(1) Big2 = big.NewInt(2) Big3 = big.NewInt(3) Big0 = big.NewInt(0) Big32 = big.NewInt(32) Big256 = big.NewInt(256) Big257 = big.NewInt(257) )
Common big integers often used
var EmptyAtxId = &AtxId{}
var EmptyTransactionId = TransactionId{}
Functions ¶
func BlockIdsAsBytes ¶
func BytesToInterface ¶
⚠️ Pass the interface by reference
func InterfaceToBytes ¶
⚠️ Pass the interface by reference
func IsProcessingError ¶
func NIPSTChallengeAsBytes ¶
func NIPSTChallengeAsBytes(challenge *NIPSTChallenge) ([]byte, error)
func TxIdsAsBytes ¶
func TxIdsAsBytes(ids []TransactionId) ([]byte, error)
Types ¶
type ActivationTx ¶
type ActivationTx struct { *InnerActivationTx Sig []byte }
func BytesAsAtx ¶
func BytesAsAtx(b []byte) (*ActivationTx, error)
func NewActivationTx ¶
func NewActivationTx(nipstChallenge NIPSTChallenge, coinbase Address, activeSetSize uint32, view []BlockID, nipst *NIPST, commitment *PostProof) *ActivationTx
func NewActivationTxForTests ¶
func (*ActivationTx) AtxBytes ¶
func (atx *ActivationTx) AtxBytes() ([]byte, error)
func (*ActivationTx) CalcAndSetId ¶
func (atx *ActivationTx) CalcAndSetId()
func (*ActivationTx) GetPoetProofRef ¶
func (atx *ActivationTx) GetPoetProofRef() []byte
func (*ActivationTx) GetShortPoetProofRef ¶
func (atx *ActivationTx) GetShortPoetProofRef() []byte
type ActivationTxHeader ¶
type ActivationTxHeader struct { NIPSTChallenge Coinbase Address ActiveSetSize uint32 // contains filtered or unexported fields }
func (*ActivationTxHeader) Bytes ¶
func (atxh *ActivationTxHeader) Bytes() []byte
func (*ActivationTxHeader) Hash32 ¶
func (atxh *ActivationTxHeader) Hash32() Hash32
func (*ActivationTxHeader) Id ¶
func (atxh *ActivationTxHeader) Id() AtxId
func (*ActivationTxHeader) SetId ¶
func (atxh *ActivationTxHeader) SetId(id *AtxId)
func (*ActivationTxHeader) ShortString ¶
func (atxh *ActivationTxHeader) ShortString() string
func (*ActivationTxHeader) TargetEpoch ¶
func (atxh *ActivationTxHeader) TargetEpoch(layersPerEpoch uint16) EpochId
type Address ¶
type Address [AddressLength]byte
Address represents the 20 byte address of an spacemesh account.
func BigToAddress ¶
BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶
BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.
func HexToAddress ¶
HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.
func StringToAddress ¶
func (Address) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
type Block ¶
func NewExistingBlock ¶
func SortBlocks ¶
func (*Block) CalcAndSetId ¶
func (b *Block) CalcAndSetId()
should be used after all changed to a block are done
func (Block) ShortString ¶
type BlockEligibilityProof ¶
type BlockHeader ¶
type BlockHeader struct { LayerIndex LayerID ATXID AtxId EligibilityProof BlockEligibilityProof Data []byte Coin bool Timestamp int64 BlockVotes []BlockID ViewEdges []BlockID }
func (*BlockHeader) AddView ¶
func (b *BlockHeader) AddView(id BlockID)
func (*BlockHeader) AddVote ¶
func (b *BlockHeader) AddVote(id BlockID)
func (BlockHeader) Layer ¶
func (b BlockHeader) Layer() LayerID
type DoubleCache ¶
type DoubleCache struct {
// contains filtered or unexported fields
}
Thread safe
func NewDoubleCache ¶
func NewDoubleCache(size uint) *DoubleCache
func (*DoubleCache) Get ¶
func (a *DoubleCache) Get(key Hash12) bool
func (*DoubleCache) GetOrInsert ¶
func (a *DoubleCache) GetOrInsert(key Hash12) bool
Checks if a value is already in the cache, otherwise add it. Returns bool whether or not the value was found in the cache (true - already in cache, false - not in cache)
type DoubleResultCache ¶
type DoubleResultCache struct {
// contains filtered or unexported fields
}
Thread safe
func NewDoubleResultCache ¶
func NewDoubleResultCache(size uint) *DoubleResultCache
func (*DoubleResultCache) Get ¶
func (a *DoubleResultCache) Get(key Hash12) (result bool, exist bool)
Checks if a value is already in the cache. Returns 2 bools - result - (only) in case the key was found (exist == true), returns the value exist - saying whether or not the value was found in the cache (true - already in cache, false - not in cache)
func (*DoubleResultCache) GetOrInsert ¶
Checks if a value is already in the cache, otherwise add it. Returns 2 bools - result - (only) in case the key was found (exist == true), returns the value exist - saying whether or not the value was found in the cache (true - already in cache, false - not in cache) err - inconsistent state, other outputs should be ignored
type Hash12 ¶
type Hash12 [Hash12Length]byte
Hash represents the first 12 bytes of sha256, mostly used for internal caches
func CalcAtxsHash12 ¶
func CalcBlocksHash12 ¶
func CalcHash12 ¶
func CalcMessageHash12 ¶
func CalcTxsHash12 ¶
func CalcTxsHash12(ids []TransactionId) (Hash12, error)
type Hash20 ¶
type Hash20 [Hash20Length]byte
Hash represents the 20 byte Keccak256 hash of arbitrary data.
func (Hash20) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (Hash20) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash20) SetBytes ¶
SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.
func (Hash20) ShortString ¶
func (Hash20) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (*Hash20) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash20) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type Hash32 ¶
type Hash32 [Hash32Length]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func CalcAtxHash32 ¶
func CalcAtxHash32(atx *ActivationTx) Hash32
func CalcBlocksHash32 ¶
func CalcHash32 ¶
func HexToHash32 ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (Hash32) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (Hash32) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash32) SetBytes ¶
SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.
func (Hash32) ShortString ¶
func (Hash32) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash32) TerminalString ¶
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash32) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash32) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type InnerActivationTx ¶
type InnerActivationTx struct { *ActivationTxHeader Nipst *NIPST View []BlockID Commitment *PostProof }
type InnerTransaction ¶
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
func NewExistingLayer ¶
type MiniBlock ¶
type MiniBlock struct { BlockHeader TxIds []TransactionId AtxIds []AtxId }
type NIPST ¶
type NIPST struct { // space is the amount of storage which the prover // requires to dedicate for generating the NIPST. Space uint64 // nipstChallenge is the challenge for PoET which is // constructed from fields in the activation transaction. NipstChallenge *Hash32 // postProof is the proof that the prover data // is still stored (or was recomputed). PostProof *PostProof }
NIPST is Non-Interactive Proof of Space-Time. Given an id, a space parameter S, a duration D and a challenge C, it can convince a verifier that (1) the prover expended S * D space-time after learning the challenge C. (2) the prover did not know the NIPST until D time after the prover learned C.
type NIPSTChallenge ¶
type NIPSTChallenge struct { NodeId NodeId Sequence uint64 PrevATXId AtxId PubLayerIdx LayerID StartTick uint64 EndTick uint64 PositioningAtx AtxId CommitmentMerkleRoot []byte }
func (*NIPSTChallenge) Hash ¶
func (challenge *NIPSTChallenge) Hash() (*Hash32, error)
func (*NIPSTChallenge) String ¶
func (challenge *NIPSTChallenge) String() string
type NodeId ¶
func (NodeId) ShortString ¶
type PoetProofMessage ¶
func (PoetProofMessage) Ref ¶
func (proofMessage PoetProofMessage) Ref() ([]byte, error)
type ProcessingError ¶
type ProcessingError string
func (ProcessingError) Error ¶
func (s ProcessingError) Error() string
type StorageSize ¶
type StorageSize float64
StorageSize is a wrapper around a float value that supports user friendly formatting.
func (StorageSize) String ¶
func (s StorageSize) String() string
String implements the stringer interface.
func (StorageSize) TerminalString ¶
func (s StorageSize) TerminalString() string
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
type Transaction ¶
type Transaction struct { InnerTransaction Signature [64]byte // contains filtered or unexported fields }
func BytesAsTransaction ¶
func BytesAsTransaction(buf []byte) (*Transaction, error)
func (*Transaction) CalcAndSetOrigin ¶
func (t *Transaction) CalcAndSetOrigin() error
func (*Transaction) Hash32 ¶
func (t *Transaction) Hash32() Hash32
func (*Transaction) Id ¶
func (t *Transaction) Id() TransactionId
func (*Transaction) Origin ¶
func (t *Transaction) Origin() Address
func (*Transaction) SetOrigin ¶
func (t *Transaction) SetOrigin(origin Address)
func (*Transaction) ShortString ¶
func (t *Transaction) ShortString() string
func (*Transaction) String ¶
func (t *Transaction) String() string
type TransactionId ¶
type TransactionId Hash32
func (TransactionId) Bytes ¶
func (id TransactionId) Bytes() []byte
func (TransactionId) Hash32 ¶
func (id TransactionId) Hash32() Hash32
func (TransactionId) ShortString ¶
func (id TransactionId) ShortString() string
func (TransactionId) String ¶
func (id TransactionId) String() string