types

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: MIT Imports: 20 Imported by: 27

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	Hash32Length = 32
	Hash20Length = 20
	Hash12Length = 12
)
View Source
const (
	// AddressLength is the expected length of the address
	AddressLength = 20
)

Variables

View Source
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

View Source
var EmptyAtxId = &AtxId{}
View Source
var EmptyTransactionId = TransactionId{}

Functions

func BlockIdsAsBytes

func BlockIdsAsBytes(ids []BlockID) ([]byte, error)

func BytesToInterface

func BytesToInterface(buf []byte, i interface{}) error

⚠️ Pass the interface by reference

func InterfaceToBytes

func InterfaceToBytes(i interface{}) ([]byte, error)

⚠️ Pass the interface by reference

func IsProcessingError

func IsProcessingError(err error) bool

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 NewActivationTxForTests(nodeId NodeId, sequence uint64, prevATX AtxId, pubLayerId LayerID, startTick uint64,
	positioningAtx AtxId, coinbase Address, activeSetSize uint32, view []BlockID, nipst *NIPST) *ActivationTx

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

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

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 StringToAddress(s string) (Address, error)

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Address) Hash

func (a Address) Hash() Hash32

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (Address) Short

func (a Address) Short() string

String implements fmt.Stringer.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

type AtxId

type AtxId Hash32

func (AtxId) Bytes

func (t AtxId) Bytes() []byte

func (AtxId) Field added in v0.1.2

func (t AtxId) Field() log.Field

func (*AtxId) Hash32

func (t *AtxId) Hash32() Hash32

func (*AtxId) ShortString

func (t *AtxId) ShortString() string

type Block

type Block struct {
	MiniBlock

	Signature []byte
	// contains filtered or unexported fields
}

func NewExistingBlock

func NewExistingBlock(layerIndex LayerID, data []byte) *Block

func SortBlocks

func SortBlocks(ids []*Block) []*Block

func (*Block) Bytes

func (b *Block) Bytes() []byte

func (*Block) Compare

func (b *Block) Compare(bl *Block) (bool, error)

func (*Block) Data

func (b *Block) Data() interface{}

func (Block) Hash32

func (b Block) Hash32() Hash32

func (*Block) Id

func (b *Block) Id() BlockID

func (*Block) Initialize added in v0.1.2

func (b *Block) Initialize()

should be used after all changed to a block are done

func (*Block) MinerId added in v0.1.2

func (b *Block) MinerId() *signing.PublicKey

func (Block) ShortString

func (b Block) ShortString() string

func (*Block) Sig

func (b *Block) Sig() []byte

type BlockEligibilityProof

type BlockEligibilityProof struct {
	J   uint32
	Sig []byte
}

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 BlockID

type BlockID Hash20

func BlockIds

func BlockIds(blocks []*Block) []BlockID

func BytesToBlockIds

func BytesToBlockIds(blockIds []byte) ([]BlockID, error)

func SortBlockIds

func SortBlockIds(ids []BlockID) []BlockID

func (BlockID) AsHash32

func (id BlockID) AsHash32() Hash32

func (BlockID) Compare

func (id BlockID) Compare(i BlockID) bool

func (BlockID) Field added in v0.1.2

func (id BlockID) Field() log.Field

func (BlockID) String

func (id BlockID) String() string

func (BlockID) ToBytes

func (id BlockID) ToBytes() []byte

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

func (a *DoubleResultCache) GetOrInsert(key Hash12, val bool) (result bool, exist bool, err error)

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 EpochId

type EpochId uint64

func (EpochId) Field added in v0.1.2

func (l EpochId) Field() log.Field

func (EpochId) FirstLayer

func (l EpochId) FirstLayer(layersPerEpoch uint16) LayerID

func (EpochId) IsGenesis

func (l EpochId) IsGenesis() bool

func (EpochId) ToBytes

func (l EpochId) ToBytes() []byte

type Hash12

type Hash12 [Hash12Length]byte

Hash represents the first 12 bytes of sha256, mostly used for internal caches

func CalcAtxsHash12

func CalcAtxsHash12(ids []AtxId) (Hash12, error)

func CalcBlocksHash12

func CalcBlocksHash12(view []BlockID) (Hash12, error)

func CalcHash12

func CalcHash12(data []byte) Hash12

func CalcMessageHash12

func CalcMessageHash12(msg []byte, prot string) Hash12

func CalcTxsHash12

func CalcTxsHash12(ids []TransactionId) (Hash12, error)

func (Hash12) Field added in v0.1.2

func (h Hash12) Field(name string) log.Field

type Hash20

type Hash20 [Hash20Length]byte

Hash represents the 20 byte Keccak256 hash of arbitrary data.

func (Hash20) Big

func (h Hash20) Big() *big.Int

Big converts a hash to a big integer.

func (Hash20) Bytes

func (h Hash20) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash20) Field added in v0.1.2

func (h Hash20) Field(name string) log.Field

func (Hash20) Format

func (h Hash20) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash20) Hex

func (h Hash20) Hex() string

Hex converts a hash to a hex string.

func (Hash20) MarshalText

func (h Hash20) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash20) SetBytes

func (h *Hash20) SetBytes(b []byte)

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 (h Hash20) ShortString() string

func (Hash20) String

func (h Hash20) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash20) ToHash32

func (h Hash20) ToHash32() Hash32

func (*Hash20) UnmarshalJSON

func (h *Hash20) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash20) UnmarshalText

func (h *Hash20) UnmarshalText(input []byte) error

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

func BigToHash(b *big.Int) Hash32

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash32

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 CalcBlockHash32Presorted

func CalcBlockHash32Presorted(sortedView []BlockID, additionalBytes []byte) Hash32

func CalcBlocksHash32

func CalcBlocksHash32(view []BlockID, additionalBytes []byte) Hash32

func CalcHash32

func CalcHash32(data []byte) Hash32

func HexToHash32

func HexToHash32(s string) Hash32

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash32) Big

func (h Hash32) Big() *big.Int

Big converts a hash to a big integer.

func (Hash32) Bytes

func (h Hash32) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash32) Field added in v0.1.2

func (h Hash32) Field(name string) log.Field

func (Hash32) Format

func (h Hash32) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash32) Generate

func (h Hash32) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash32) Hex

func (h Hash32) Hex() string

Hex converts a hash to a hex string.

func (Hash32) MarshalText

func (h Hash32) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash32) Scan

func (h *Hash32) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash32) SetBytes

func (h *Hash32) SetBytes(b []byte)

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 (h Hash32) ShortString() string

func (Hash32) String

func (h Hash32) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash32) TerminalString

func (h Hash32) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (Hash32) ToHash20

func (h Hash32) ToHash20() Hash20

func (*Hash32) UnmarshalJSON

func (h *Hash32) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash32) UnmarshalText

func (h *Hash32) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type InnerActivationTx

type InnerActivationTx struct {
	*ActivationTxHeader
	Nipst      *NIPST
	View       []BlockID
	Commitment *PostProof
}

type InnerTransaction

type InnerTransaction struct {
	AccountNonce uint64
	Recipient    Address
	GasLimit     uint64
	Fee          uint64
	Amount       uint64
}

type Layer

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

func NewExistingLayer

func NewExistingLayer(idx LayerID, blocks []*Block) *Layer

func NewLayer

func NewLayer(layerIndex LayerID) *Layer

func (*Layer) AddBlock

func (l *Layer) AddBlock(block *Block)

func (*Layer) Blocks

func (l *Layer) Blocks() []*Block

func (*Layer) Hash

func (l *Layer) Hash() Hash32

func (*Layer) Index

func (l *Layer) Index() LayerID

func (*Layer) SetBlocks

func (l *Layer) SetBlocks(blocks []*Block)

func (*Layer) SetIndex

func (l *Layer) SetIndex() LayerID

type LayerID

type LayerID uint64

func (LayerID) Add

func (l LayerID) Add(layers uint16) LayerID

func (LayerID) Field added in v0.1.2

func (l LayerID) Field() log.Field

func (LayerID) GetEpoch

func (l LayerID) GetEpoch(layersPerEpoch uint16) EpochId

func (LayerID) ToBytes

func (l LayerID) ToBytes() []byte

func (LayerID) Uint64

func (l LayerID) Uint64() uint64

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

type NodeId struct {
	Key          string
	VRFPublicKey []byte
}

func (NodeId) Field added in v0.1.2

func (id NodeId) Field() log.Field

func (NodeId) ShortString

func (id NodeId) ShortString() string

func (NodeId) String

func (id NodeId) String() string

func (NodeId) ToBytes

func (id NodeId) ToBytes() []byte

type PoetProof

type PoetProof struct {
	shared.MerkleProof
	Members   [][]byte
	LeafCount uint64
}

type PoetProofMessage

type PoetProofMessage struct {
	PoetProof
	PoetServiceId []byte
	RoundId       string
	Signature     []byte
}

func (PoetProofMessage) Ref

func (proofMessage PoetProofMessage) Ref() ([]byte, error)

type PoetRound

type PoetRound struct {
	Id string
}

type PostProof

type PostProof proving.Proof

func (*PostProof) String

func (p *PostProof) String() string

type ProcessingError

type ProcessingError string

func (ProcessingError) Error

func (s ProcessingError) Error() string

type Reward

type Reward struct {
	Layer               LayerID
	TotalReward         uint64
	LayerRewardEstimate uint64
}

type Signed

type Signed interface {
	Sig() []byte
	Bytes() []byte
	Data() interface{}
}

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) Field added in v0.1.2

func (id TransactionId) Field() log.Field

func (TransactionId) Hash32

func (id TransactionId) Hash32() Hash32

func (TransactionId) ShortString

func (id TransactionId) ShortString() string

func (TransactionId) String

func (id TransactionId) String() string

type TryMutex added in v0.1.2

type TryMutex struct {
	sync.Mutex
}

Mutex is simple sync.Mutex + ability to try to Lock.

func (*TryMutex) TryLock added in v0.1.2

func (m *TryMutex) TryLock() bool

TryLock tries to lock m. It returns true in case of success, false otherwise.

type Vrf

type Vrf string

todo: choose which type is VRF

Jump to

Keyboard shortcuts

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