types

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 20 Imported by: 27

Documentation

Overview

Package types defines the types used by go-spacemesh consensus algorithms and structs

Index

Constants

View Source
const (
	// AddressLength is the expected length of the address
	AddressLength = 20
)
View Source
const (
	// Hash32Length is 32, the expected length of the hash
	Hash32Length = 32
)

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{}

EmptyATXID is a canonical empty ATXID.

View Source
var EmptyTransactionID = TransactionID{}

EmptyTransactionID is a canonical empty TransactionID.

Functions

func BlockIdsAsBytes

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

BlockIdsAsBytes serializes a slice of BlockIDs.

func BytesToInterface

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

BytesToInterface deserializes any type. ⚠️ Pass the interface by reference

func InterfaceToBytes

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

InterfaceToBytes serializes any type. ⚠️ Pass the interface by reference

func IsProcessingError

func IsProcessingError(err error) bool

IsProcessingError returns true if the given error is a processing error.

func NIPSTChallengeAsBytes

func NIPSTChallengeAsBytes(challenge *NIPSTChallenge) ([]byte, error)

NIPSTChallengeAsBytes serializes a NIPSTChallenge.

Types

type ATXID added in v0.1.11

type ATXID Hash32

ATXID is a 32-bit hash used to identify an activation transaction.

func (ATXID) Bytes added in v0.1.11

func (t ATXID) Bytes() []byte

Bytes returns the ATXID as a byte slice.

func (ATXID) Field added in v0.1.11

func (t ATXID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (ATXID) Hash32 added in v0.1.11

func (t ATXID) Hash32() Hash32

Hash32 returns the ATXID as a Hash32.

func (ATXID) ShortString added in v0.1.11

func (t ATXID) ShortString() string

ShortString returns a the first 5 characters of the ID, for logging purposes.

type ActivationTx

type ActivationTx struct {
	*InnerActivationTx
	Sig []byte
}

ActivationTx is a full, signed activation transaction. It includes (or references) everything a miner needs to prove they are eligible to actively participate in the Spacemesh protocol in the next epoch.

func BytesAsAtx

func BytesAsAtx(b []byte) (*ActivationTx, error)

BytesAsAtx deserializes an ActivationTx.

func NewActivationTx

func NewActivationTx(nipstChallenge NIPSTChallenge, coinbase Address, activeSetSize uint32, view []BlockID,
	nipst *NIPST, commitment *PostProof) *ActivationTx

NewActivationTx returns a new activation transaction. The ATXID is calculated and cached.

func (*ActivationTx) CalcAndSetID added in v0.1.11

func (atx *ActivationTx) CalcAndSetID()

CalcAndSetID calculates and sets the cached ID field. This field must be set before calling the ID() method.

func (*ActivationTx) GetPoetProofRef

func (atx *ActivationTx) GetPoetProofRef() []byte

GetPoetProofRef returns the reference to the PoET proof.

func (*ActivationTx) GetShortPoetProofRef

func (atx *ActivationTx) GetShortPoetProofRef() []byte

GetShortPoetProofRef returns the first 5 characters of the PoET proof reference, for logging purposes.

func (*ActivationTx) InnerBytes added in v0.1.11

func (atx *ActivationTx) InnerBytes() ([]byte, error)

InnerBytes returns a byte slice of the serialization of the inner ATX (excluding the signature field).

type ActivationTxHeader

type ActivationTxHeader struct {
	NIPSTChallenge

	Coinbase      Address
	ActiveSetSize uint32
	// contains filtered or unexported fields
}

ActivationTxHeader is the header of an activation transaction. It includes all fields from the NIPSTChallenge, as well as the coinbase address and active set size.

func (*ActivationTxHeader) Hash32

func (atxh *ActivationTxHeader) Hash32() Hash32

Hash32 returns the ATX's ID as a Hash32.

func (*ActivationTxHeader) ID added in v0.1.11

func (atxh *ActivationTxHeader) ID() ATXID

ID returns the ATX's ID.

func (*ActivationTxHeader) SetID added in v0.1.11

func (atxh *ActivationTxHeader) SetID(id *ATXID)

SetID sets the ATXID in this ATX's cache.

func (*ActivationTxHeader) ShortString

func (atxh *ActivationTxHeader) ShortString() string

ShortString returns a the first 5 characters of the ID, for logging purposes.

func (*ActivationTxHeader) TargetEpoch

func (atxh *ActivationTxHeader) TargetEpoch(layersPerEpoch uint16) EpochID

TargetEpoch returns the target epoch of the activation transaction. This is the epoch in which the miner is eligible to participate thanks to the ATX.

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)

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

Short returns the first 7 characters of the address hex representation (incl. "0x"), for logging purposes.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

type Block

type Block struct {
	MiniBlock

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

Block includes all of a block's fields, including signature and a cache of the BlockID and MinerID.

func NewExistingBlock

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

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

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

SortBlocks sorts a list of Blocks in lexicographic order of their IDs, in-place.

func (*Block) Bytes

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

Bytes returns the serialization of the MiniBlock.

func (Block) Hash32

func (b Block) Hash32() 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) ID added in v0.1.11

func (b *Block) ID() BlockID

ID returns the BlockID.

func (*Block) Initialize added in v0.1.2

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) MinerID added in v0.1.11

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

MinerID returns this block's miner's Edwards public key.

func (Block) ShortString

func (b Block) ShortString() string

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.

func (BlockHeader) Layer

func (b BlockHeader) Layer() LayerID

Layer returns the block's LayerID.

type BlockID

type BlockID Hash20

BlockID is a 20-byte sha256 sum of the serialized block, used to identify it.

func BlockIDs added in v0.1.11

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

BlockIDs returns a slice of BlockIDs corresponding to the given blocks.

func BytesToBlockIds

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

BytesToBlockIds deserializes a slice of BlockIDs.

func SortBlockIDs added in v0.1.11

func SortBlockIDs(ids []BlockID) []BlockID

SortBlockIDs sorts a list of BlockIDs in lexicographic order, in-place.

func (BlockID) AsHash32

func (id BlockID) AsHash32() Hash32

AsHash32 returns a Hash32 whose first 20 bytes are the bytes of this BlockID, it is right-padded with zeros.

func (BlockID) Compare

func (id BlockID) Compare(other BlockID) bool

Compare returns true if other (the given BlockID) is less than this BlockID, by lexicographic comparison.

func (BlockID) Field added in v0.1.2

func (id BlockID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (BlockID) String

func (id BlockID) String() string

String returns the 5-character prefix of the hex representation of the ID.

func (BlockID) ToBytes

func (id BlockID) ToBytes() []byte

ToBytes returns the BlockID as a byte slice.

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 EpochID added in v0.1.11

type EpochID uint64

EpochID is the running epoch number. It's zero-based, so the genesis epoch has EpochID == 0.

func (EpochID) Field added in v0.1.11

func (l EpochID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (EpochID) FirstLayer added in v0.1.11

func (l EpochID) FirstLayer(layersPerEpoch uint16) LayerID

FirstLayer returns the layer ID of the first layer in the epoch.

func (EpochID) IsGenesis added in v0.1.11

func (l EpochID) IsGenesis() bool

IsGenesis returns true if this epoch is in genesis. The first two epochs are considered genesis epochs.

func (EpochID) ToBytes added in v0.1.11

func (l EpochID) ToBytes() []byte

ToBytes returns a byte-slice representation of the EpochID, using little endian encoding.

type Hash12

type Hash12 [hash12Length]byte

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

func CalcBlocksHash12

func CalcBlocksHash12(view []BlockID) (h Hash12)

CalcBlocksHash12 returns the 12-byte sha256 sum of the block IDs, sorted in lexicographic order.

func CalcHash12

func CalcHash12(data []byte) (h Hash12)

CalcHash12 returns the 12-byte prefix of the sha256 sum of the given byte slice.

func CalcMessageHash12

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

CalcMessageHash12 returns the 12-byte sha256 sum of the given msg suffixed with protocol.

func (Hash12) Field added in v0.1.2

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

Field returns a log field. Implements the LoggableField interface.

type Hash20

type Hash20 [hash20Length]byte

Hash20 represents the 20-byte sha256 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

Field returns a log field. Implements the LoggableField interface.

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

ShortString returns a the first 5 characters of the hash, for logging purposes.

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() (h32 Hash32)

ToHash32 returns a Hash32 whose first 20 bytes are the bytes of this Hash20, it is right-padded with zeros.

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

Hash32 represents the 32-byte sha256 hash of arbitrary data.

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 added in v0.1.11

func CalcATXHash32(atx *ActivationTx) Hash32

CalcATXHash32 returns the 32-byte sha256 sum of serialization of the given ATX.

func CalcBlockHash32Presorted

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

CalcBlockHash32Presorted returns the 32-byte sha256 sum of the block IDs, in the order given. The pre-image is prefixed with additionalBytes.

func CalcBlocksHash32

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

CalcBlocksHash32 returns the 32-byte sha256 sum of the block IDs, sorted in lexicographic order. The pre-image is prefixed with additionalBytes.

func CalcHash32

func CalcHash32(data []byte) Hash32

CalcHash32 returns the 32-byte sha256 sum of the given data.

func HexToHash32

func HexToHash32(s string) Hash32

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

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

Field returns a log field. Implements the LoggableField interface.

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, _ 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

ShortString returns a the first 5 characters of the hash, for logging purposes.

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) ToHash20

func (h Hash32) ToHash20() (h20 Hash20)

ToHash20 returns a Hash20, whose the 20-byte prefix of this Hash32.

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
}

InnerActivationTx is a set of all of an ATX's fields, except the signature. To generate the ATX signature, this structure is serialized and signed. It includes the header fields, as well as the larger fields that are only used for validation: the NIPST, view and PoST proof.

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

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

NewExistingLayer returns a new layer with the given list of blocks without validation.

func NewLayer

func NewLayer(layerIndex LayerID) *Layer

NewLayer returns a layer with no blocks.

func (*Layer) AddBlock

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

AddBlock adds a block to this layer. Panics if the block's index doesn't match the layer.

func (*Layer) Blocks

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

Blocks returns the list of blocks in this layer.

func (Layer) Hash

func (l Layer) Hash() Hash32

Hash returns the 32-byte sha256 sum of the block IDs in this layer, sorted in lexicographic order.

func (*Layer) Index

func (l *Layer) Index() LayerID

Index returns the layer's ID.

func (*Layer) SetBlocks

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

SetBlocks sets the list of blocks for the layer without validation.

type LayerID

type LayerID uint64

LayerID is a uint64 representing a layer number. It is zero-based.

func (LayerID) Add

func (l LayerID) Add(layers uint16) LayerID

Add returns the LayerID that's layers (the param passed into this method) after l (this LayerID).

func (LayerID) Field added in v0.1.2

func (l LayerID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (LayerID) GetEpoch

func (l LayerID) GetEpoch(layersPerEpoch uint16) EpochID

GetEpoch returns the epoch number of this LayerID.

func (LayerID) ToBytes

func (l LayerID) ToBytes() []byte

ToBytes returns the byte representation of the LayerID, using little endian encoding.

func (LayerID) Uint64

func (l LayerID) Uint64() uint64

Uint64 returns the LayerID as a uint64.

type MiniBlock

type MiniBlock struct {
	BlockHeader
	TxIDs  []TransactionID
	ATXIDs []ATXID
}

MiniBlock includes all of a block's fields, except for the signature. This structure is serialized and signed to produce the block signature.

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
	PubLayerID           LayerID
	StartTick            uint64
	EndTick              uint64
	PositioningATX       ATXID
	CommitmentMerkleRoot []byte
}

NIPSTChallenge is the set of fields that's serialized, hashed and submitted to the PoET service to be included in the PoET membership proof. It includes the node ID, ATX sequence number, the previous ATX's ID (for all but the first in the sequence), the intended publication layer ID, the PoET's start and end ticks, the positioning ATX's ID and for the first ATX in the sequence also the commitment Merkle root.

func (*NIPSTChallenge) Hash

func (challenge *NIPSTChallenge) Hash() (*Hash32, error)

Hash serializes the NIPSTChallenge and returns its hash.

func (*NIPSTChallenge) String

func (challenge *NIPSTChallenge) String() string

String returns a string representation of the NIPSTChallenge, for logging purposes. It implements the Stringer interface.

type NodeID added in v0.1.11

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

func (id NodeID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (NodeID) ShortString added in v0.1.11

func (id NodeID) ShortString() string

ShortString returns a the first 5 characters of the ID, for logging purposes.

func (NodeID) String added in v0.1.11

func (id NodeID) String() string

String returns a string representation of the NodeID, for logging purposes. It implements the Stringer interface.

func (NodeID) ToBytes added in v0.1.11

func (id NodeID) ToBytes() []byte

ToBytes returns the byte representation of the Edwards public key.

type PoetProof

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

PoetProof is the full PoET service proof of elapsed time. It includes the list of members, a leaf count declaration and the actual PoET Merkle proof.

type PoetProofMessage

type PoetProofMessage struct {
	PoetProof
	PoetServiceID []byte
	RoundID       string
	Signature     []byte
}

PoetProofMessage is the envelope which includes the PoetProof, service ID, round ID and signature.

func (PoetProofMessage) Ref

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

Ref returns the reference to the PoET proof message. It's the sha256 sum of the entire proof message.

type PoetRound

type PoetRound struct {
	ID string
}

PoetRound includes the PoET's round ID.

type PostProof

type PostProof proving.Proof

PostProof is an alias to the PoST proof.

func (PostProof) String

func (p PostProof) String() string

String returns a string representation of the PostProof, for logging purposes. It implements the Stringer interface.

type ProcessingError

type ProcessingError string

ProcessingError is a type of error (implements the error interface) that is used to differentiate processing errors from validation errors.

func (ProcessingError) Error

func (s ProcessingError) Error() string

Error returns the processing error as a string. It implements the error interface.

type Reward

type Reward struct {
	Layer               LayerID
	TotalReward         uint64
	LayerRewardEstimate uint64
}

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 added in v0.1.11

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 added in v0.1.11

type TransactionID Hash32

TransactionID is a 32-byte sha256 sum of the transaction, used as an identifier.

func (TransactionID) Bytes added in v0.1.11

func (id TransactionID) Bytes() []byte

Bytes returns the TransactionID as a byte slice.

func (TransactionID) Field added in v0.1.11

func (id TransactionID) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

func (TransactionID) Hash32 added in v0.1.11

func (id TransactionID) Hash32() Hash32

Hash32 returns the TransactionID as a Hash32.

func (TransactionID) ShortString added in v0.1.11

func (id TransactionID) ShortString() string

ShortString returns a the first 5 characters of the ID, for logging purposes.

func (TransactionID) String added in v0.1.11

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.

type TryMutex added in v0.1.2

type TryMutex struct {
	sync.Mutex
}

TryMutex is a simple sync.Mutex with the 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.

Jump to

Keyboard shortcuts

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