Documentation
¶
Overview ¶
Package types defines the types used by go-libonomy consensus algorithms and structs
Index ¶
- Constants
- Variables
- func BlockIdsAsBytes(ids []BlockID) ([]byte, error)
- func BytesToInterface(buf []byte, i interface{}) error
- func InterfaceToBytes(i interface{}) ([]byte, error)
- type Address
- type Block
- type BlockEligibilityProof
- type BlockHeader
- type BlockID
- type DoubleCache
- type Hash12
- type Hash20
- func (h Hash20) Big() *big.Int
- func (h Hash20) Bytes() []byte
- func (h Hash20) Field(name string) log.Field
- 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() (h32 Hash32)
- func (h *Hash20) UnmarshalJSON(input []byte) error
- func (h *Hash20) UnmarshalText(input []byte) error
- type Hash32
- func (h Hash32) Bytes() []byte
- func (h Hash32) Field(name string) log.Field
- func (h Hash32) Format(s fmt.State, c rune)
- func (h Hash32) Generate(rand *rand.Rand, _ 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) ToHash20() (h20 Hash20)
- func (h *Hash32) UnmarshalJSON(input []byte) error
- func (h *Hash32) UnmarshalText(input []byte) error
- type InnerTransaction
- type Layer
- type LayerID
- type MiniBlock
- type NodeID
- type Reward
- type StorageSize
- type Transaction
- type TransactionID
- type TryMutex
Constants ¶
const (
// AddressLength is the expected length of the address
AddressLength = 20
)
const (
// Hash32Length is 32, the expected length of the hash
Hash32Length = 32
)
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 EmptyTransactionID = TransactionID{}
EmptyTransactionID is a canonical empty TransactionID.
Functions ¶
func BlockIdsAsBytes ¶
BlockIdsAsBytes serializes a slice of BlockIDs.
func BytesToInterface ¶
BytesToInterface deserializes any type. ⚠️ Pass the interface by reference
func InterfaceToBytes ¶
InterfaceToBytes serializes any type. ⚠️ Pass the interface by reference
Types ¶
type Address ¶
type Address [AddressLength]byte
Address represents the 20 byte address of an libonomy 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 ¶
StringToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left. It is identical to HexToAddress, except decoding errors are returned instead of swallowed.
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.
func (*Address) SetBytes ¶
SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.
type Block ¶
Block includes all of a block's fields, including signature and a cache of the BlockID and MinerID.
func NewExistingBlock ¶
NewExistingBlock returns a block in the given layer with the given arbitrary data. The block is signed with a random keypair that isn't stored anywhere. This method should be phased out of use in production code (it's currently used in tests and the temporary genesis flow).
func SortBlocks ¶
SortBlocks sorts a list of Blocks in lexicographic order of their IDs, in-place.
func (Block) Hash32 ¶
Hash32 returns a Hash32 whose first 20 bytes are the bytes of this BlockID, it is right-padded with zeros. This implements the sync.item interface.
func (*Block) Initialize ¶
func (b *Block) Initialize()
Initialize calculates and sets the block's cached ID and MinerID. This should be called once all the other fields of the block are set.
func (Block) ShortString ¶
ShortString returns a the first 5 characters of the ID, for logging purposes.
type BlockEligibilityProof ¶
type BlockEligibilityProof struct { // J is the counter value used to generate this eligibility proof. Each value of J must only be used once. J uint32 // Sig is the VRF signature from which the block's LayerID is derived. Sig []byte }
BlockEligibilityProof includes the required values that, along with the miner's VRF public key, allow non-interactive block eligibility validation.
type BlockHeader ¶
type BlockHeader struct { LayerIndex LayerID // ATXID ATXID EligibilityProof BlockEligibilityProof Data []byte Coin bool Timestamp int64 BlockVotes []BlockID ViewEdges []BlockID }
BlockHeader includes all of a block's fields, except the list of transaction IDs, activation transaction IDs and the signature. TODO: consider combining this with MiniBlock, since this type isn't used independently anywhere.
func (*BlockHeader) AddView ¶
func (b *BlockHeader) AddView(id BlockID)
AddView adds a block to this block's view.
func (*BlockHeader) AddVote ¶
func (b *BlockHeader) AddVote(id BlockID)
AddVote adds a vote to the list of block votes.
type BlockID ¶
type BlockID Hash20
BlockID is a 20-byte sha256 sum of the serialized block, used to identify it.
func BytesToBlockIds ¶
BytesToBlockIds deserializes a slice of BlockIDs.
func SortBlockIDs ¶
SortBlockIDs sorts a list of BlockIDs in lexicographic order, in-place.
func (BlockID) AsHash32 ¶
AsHash32 returns a Hash32 whose first 20 bytes are the bytes of this BlockID, it is right-padded with zeros.
func (BlockID) Compare ¶
Compare returns true if other (the given BlockID) is less than this BlockID, by lexicographic comparison.
type DoubleCache ¶
type DoubleCache struct {
// contains filtered or unexported fields
}
DoubleCache is a structure for storing which keys have been encountered before. It's initialized with a size and it stores between size and 2*size keys. Every time the cache size reaches 2*size and a new value is added, the oldest size keys are discarded and the size drops back to size. DoubleCache is thread safe.
func NewDoubleCache ¶
func NewDoubleCache(size uint) *DoubleCache
NewDoubleCache returns a new DoubleCache.
func (*DoubleCache) GetOrInsert ¶
func (a *DoubleCache) GetOrInsert(key Hash12) bool
GetOrInsert checks if a value is already in the cache, otherwise it adds it. Returns bool whether or not the value was found in the cache (true - already in cache, false - wasn't in cache before this was called).
type Hash12 ¶
type Hash12 [hash12Length]byte
Hash12 represents the first 12 bytes of sha256, mostly used for internal caches
func CalcBlocksHash12 ¶
CalcBlocksHash12 returns the 12-byte sha256 sum of the block IDs, sorted in lexicographic order.
func CalcHash12 ¶
CalcHash12 returns the 12-byte prefix of the sha256 sum of the given byte slice.
func CalcMessageHash12 ¶
CalcMessageHash12 returns the 12-byte sha256 sum of the given msg suffixed with protocol.
type Hash20 ¶
type Hash20 [hash20Length]byte
Hash20 represents the 20-byte sha256 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 ¶
ShortString returns a the first 5 characters of the hash, for logging purposes.
func (Hash20) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash20) ToHash32 ¶
ToHash32 returns a Hash32 whose first 20 bytes are the bytes of this Hash20, it is right-padded with zeros.
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
Hash32 represents the 32-byte sha256 hash of arbitrary data.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func CalcBlockHash32Presorted ¶
CalcBlockHash32Presorted returns the 32-byte sha256 sum of the block IDs, in the order given. The pre-image is prefixed with additionalBytes.
func CalcBlocksHash32 ¶
CalcBlocksHash32 returns the 32-byte sha256 sum of the block IDs, sorted in lexicographic order. The pre-image is prefixed with additionalBytes.
func CalcHash32 ¶
CalcHash32 returns the 32-byte sha256 sum of the given data.
func HexToHash32 ¶
HexToHash32 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 ¶
ShortString returns a the first 5 characters of the hash, for logging purposes.
func (Hash32) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (*Hash32) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash32) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type InnerTransaction ¶
type InnerTransaction struct { AccountNonce uint64 Recipient Address GasLimit uint64 Fee uint64 Amount uint64 }
InnerTransaction includes all of a transaction's fields, except the signature (origin and id aren't stored).
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer contains a list of blocks and their corresponding LayerID.
func NewExistingLayer ¶
NewExistingLayer returns a new layer with the given list of blocks without validation.
func (*Layer) AddBlock ¶
AddBlock adds a block to this layer. Panics if the block's index doesn't match the layer.
type LayerID ¶
type LayerID uint64
LayerID is a uint64 representing a layer number. It is zero-based.
func (LayerID) Add ¶
Add returns the LayerID that's layers (the param passed into this method) after l (this LayerID).
type MiniBlock ¶
type MiniBlock struct { BlockHeader TxIDs []TransactionID }
MiniBlock includes all of a block's fields, except for the signature. This structure is serialized and signed to produce the block signature.
type NodeID ¶
type NodeID struct { // Key is the miner's Edwards public key Key string // VRFPublicKey is the miner's public key used for VRF. The VRF scheme used is BLS. VRFPublicKey []byte }
NodeID contains a miner's two public keys.
func (NodeID) ShortString ¶
ShortString returns a the first 5 characters of the ID, for logging purposes.
type Reward ¶
Reward is a virtual reward transaction, which the node keeps track of for the gRPC api.
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 }
Transaction contains all transaction fields, including the signature and cached origin address and transaction ID.
func BytesAsTransaction ¶
func BytesAsTransaction(buf []byte) (*Transaction, error)
BytesAsTransaction deserializes a Transaction.
func (*Transaction) CalcAndSetOrigin ¶
func (t *Transaction) CalcAndSetOrigin() error
CalcAndSetOrigin extracts the public key from the transaction's signature and caches it as the transaction's origin address.
func (*Transaction) Hash32 ¶
func (t *Transaction) Hash32() Hash32
Hash32 returns the TransactionID as a Hash32.
func (*Transaction) ID ¶
func (t *Transaction) ID() TransactionID
ID returns the transaction's ID. If it's not cached, it's calculated, cached and returned.
func (*Transaction) Origin ¶
func (t *Transaction) Origin() Address
Origin returns the transaction's origin address: the public key extracted from the transaction signature.
func (*Transaction) SetOrigin ¶
func (t *Transaction) SetOrigin(origin Address)
SetOrigin sets the cache of the transaction's origin address.
func (*Transaction) ShortString ¶
func (t *Transaction) ShortString() string
ShortString returns a the first 5 characters of the ID, for logging purposes.
func (*Transaction) String ¶
func (t *Transaction) String() string
String returns a string representation of the Transaction, for logging purposes. It implements the fmt.Stringer interface.
type TransactionID ¶
type TransactionID Hash32
TransactionID is a 32-byte sha256 sum of the transaction, used as an identifier.
func (TransactionID) Bytes ¶
func (id TransactionID) Bytes() []byte
Bytes returns the TransactionID as a byte slice.
func (TransactionID) Field ¶
func (id TransactionID) Field() log.Field
Field returns a log field. Implements the LoggableField interface.
func (TransactionID) Hash32 ¶
func (id TransactionID) Hash32() Hash32
Hash32 returns the TransactionID as a Hash32.
func (TransactionID) ShortString ¶
func (id TransactionID) ShortString() string
ShortString returns a the first 5 characters of the ID, for logging purposes.
func (TransactionID) String ¶
func (id TransactionID) String() string
String returns a hexadecimal representation of the TransactionID with "0x" prepended, for logging purposes. It implements the fmt.Stringer interface.