core

package
v0.0.0-...-169a2f2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBlockHash = errors.New("invalid block hash")
	ErrNilBlock         = errors.New("nil block")
)

errors

View Source
var (
	ErrNilQC            = errors.New("nil qc")
	ErrNilSig           = errors.New("nil signature")
	ErrNotEnoughSig     = errors.New("not enough signatures in qc")
	ErrDuplicateSig     = errors.New("duplicate signature in qc")
	ErrInvalidSig       = errors.New("invalid signature")
	ErrInvalidValidator = errors.New("voter is not a validator")
)

errors

View Source
var (
	ErrInvalidTxHash = errors.New("invalid tx hash")
	ErrNilTx         = errors.New("nil tx")
)

errors

View Source
var (
	ErrInvalidKeySize = errors.New("invalid key size")
)

errors

View Source
var (
	ErrNilVote = errors.New("nil vote")
)

errors

Functions

func MajorityCount

func MajorityCount(validatorCount int) int

MajorityCount returns 2f + 1 members

Types

type Block

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

Block type

func NewBlock

func NewBlock() *Block

func (*Block) ExecHeight

func (blk *Block) ExecHeight() uint64

func (*Block) Hash

func (blk *Block) Hash() []byte

func (*Block) Height

func (blk *Block) Height() uint64

func (*Block) IsGenesis

func (blk *Block) IsGenesis() bool

func (*Block) Marshal

func (blk *Block) Marshal() ([]byte, error)

Marshal encodes blk as bytes

func (*Block) MarshalJSON

func (blk *Block) MarshalJSON() ([]byte, error)

func (*Block) MerkleRoot

func (blk *Block) MerkleRoot() []byte

func (*Block) ParentHash

func (blk *Block) ParentHash() []byte

func (*Block) Proposer

func (blk *Block) Proposer() *PublicKey

func (*Block) ProposerVote

func (blk *Block) ProposerVote() *Vote

func (*Block) QuorumCert

func (blk *Block) QuorumCert() *QuorumCert

func (*Block) SetExecHeight

func (blk *Block) SetExecHeight(val uint64) *Block

func (*Block) SetHeight

func (blk *Block) SetHeight(val uint64) *Block

func (*Block) SetMerkleRoot

func (blk *Block) SetMerkleRoot(val []byte) *Block

func (*Block) SetParentHash

func (blk *Block) SetParentHash(val []byte) *Block

func (*Block) SetQuorumCert

func (blk *Block) SetQuorumCert(val *QuorumCert) *Block

func (*Block) SetTimestamp

func (blk *Block) SetTimestamp(val int64) *Block

func (*Block) SetTransactions

func (blk *Block) SetTransactions(val [][]byte) *Block

func (*Block) Sign

func (blk *Block) Sign(signer Signer) *Block

func (*Block) Sum

func (blk *Block) Sum() []byte

Sum returns sha3 sum of block

func (*Block) Timestamp

func (blk *Block) Timestamp() int64

func (*Block) Transactions

func (blk *Block) Transactions() [][]byte

func (*Block) Unmarshal

func (blk *Block) Unmarshal(b []byte) error

UnmarshalBlock decodes block from bytes

func (*Block) UnmarshalJSON

func (blk *Block) UnmarshalJSON(b []byte) error

func (*Block) Validate

func (blk *Block) Validate(vs ValidatorStore) error

Validate block

func (*Block) Vote

func (blk *Block) Vote(signer Signer) *Vote

Vote creates a vote for block

type BlockCommit

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

func NewBlockCommit

func NewBlockCommit() *BlockCommit

func (*BlockCommit) ElapsedExec

func (bcm *BlockCommit) ElapsedExec() float64

func (*BlockCommit) ElapsedMerkle

func (bcm *BlockCommit) ElapsedMerkle() float64

func (*BlockCommit) Hash

func (bcm *BlockCommit) Hash() []byte

func (*BlockCommit) LeafCount

func (bcm *BlockCommit) LeafCount() []byte

func (*BlockCommit) Marshal

func (bcm *BlockCommit) Marshal() ([]byte, error)

func (*BlockCommit) MerkleRoot

func (bcm *BlockCommit) MerkleRoot() []byte

func (*BlockCommit) OldBlockTxs

func (bcm *BlockCommit) OldBlockTxs() [][]byte

func (*BlockCommit) SetElapsedExec

func (bcm *BlockCommit) SetElapsedExec(val float64) *BlockCommit

func (*BlockCommit) SetElapsedMerkle

func (bcm *BlockCommit) SetElapsedMerkle(val float64) *BlockCommit

func (*BlockCommit) SetHash

func (bcm *BlockCommit) SetHash(val []byte) *BlockCommit

func (*BlockCommit) SetLeafCount

func (bcm *BlockCommit) SetLeafCount(val []byte) *BlockCommit

func (*BlockCommit) SetMerkleRoot

func (bcm *BlockCommit) SetMerkleRoot(val []byte) *BlockCommit

func (*BlockCommit) SetOldBlockTxs

func (bcm *BlockCommit) SetOldBlockTxs(val [][]byte) *BlockCommit

func (*BlockCommit) SetStateChanges

func (bcm *BlockCommit) SetStateChanges(val []*StateChange) *BlockCommit

func (*BlockCommit) StateChanges

func (bcm *BlockCommit) StateChanges() []*StateChange

func (*BlockCommit) Unmarshal

func (bcm *BlockCommit) Unmarshal(b []byte) error

type PrivateKey

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

PrivateKey type

func GenerateKey

func GenerateKey(rand io.Reader) *PrivateKey

func NewPrivateKey

func NewPrivateKey(b []byte) (*PrivateKey, error)

NewPrivateKey creates PrivateKey from bytes

func (*PrivateKey) Bytes

func (priv *PrivateKey) Bytes() []byte

Bytes return raw bytes

func (*PrivateKey) PublicKey

func (priv *PrivateKey) PublicKey() *PublicKey

PublicKey returns corresponding public key

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(msg []byte) *Signature

Sign signs the message

type PublicKey

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

PublicKey type

func NewPublicKey

func NewPublicKey(b []byte) (*PublicKey, error)

NewPublicKey creates PublicKey from bytes

func (*PublicKey) Bytes

func (pub *PublicKey) Bytes() []byte

Bytes return raw bytes

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x *PublicKey) bool

Equal checks whether pub and x has the same value

func (*PublicKey) String

func (pub *PublicKey) String() string

type QuorumCert

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

QuorumCert type

func NewQuorumCert

func NewQuorumCert() *QuorumCert

func (*QuorumCert) BlockHash

func (qc *QuorumCert) BlockHash() []byte

func (*QuorumCert) Build

func (qc *QuorumCert) Build(votes []*Vote) *QuorumCert

func (*QuorumCert) Marshal

func (qc *QuorumCert) Marshal() ([]byte, error)

Marshal encodes quorum cert as bytes

func (*QuorumCert) Signatures

func (qc *QuorumCert) Signatures() []*Signature

func (*QuorumCert) Unmarshal

func (qc *QuorumCert) Unmarshal(b []byte) error

Unmarshal decodes quorum cert from bytes

func (*QuorumCert) Validate

func (qc *QuorumCert) Validate(vs ValidatorStore) error

Validate godoc

type Signature

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

Signature type

func (*Signature) PublicKey

func (sig *Signature) PublicKey() *PublicKey

PublicKey returns corresponding public key

func (*Signature) Verify

func (sig *Signature) Verify(msg []byte) bool

Verify verifies the signature

type Signer

type Signer interface {
	Sign(msg []byte) *Signature
	PublicKey() *PublicKey
}

type StateChange

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

func NewStateChange

func NewStateChange() *StateChange

func (*StateChange) Key

func (sc *StateChange) Key() []byte

func (*StateChange) Marshal

func (sc *StateChange) Marshal() ([]byte, error)

func (*StateChange) PrevTreeIndex

func (sc *StateChange) PrevTreeIndex() []byte

func (*StateChange) PrevValue

func (sc *StateChange) PrevValue() []byte

func (*StateChange) SetKey

func (sc *StateChange) SetKey(val []byte) *StateChange

func (*StateChange) SetPrevTreeIndex

func (sc *StateChange) SetPrevTreeIndex(val []byte) *StateChange

func (*StateChange) SetPrevValue

func (sc *StateChange) SetPrevValue(val []byte) *StateChange

func (*StateChange) SetTreeIndex

func (sc *StateChange) SetTreeIndex(val []byte) *StateChange

func (*StateChange) SetValue

func (sc *StateChange) SetValue(val []byte) *StateChange

func (*StateChange) TreeIndex

func (sc *StateChange) TreeIndex() []byte

func (*StateChange) Unmarshal

func (sc *StateChange) Unmarshal(b []byte) error

func (*StateChange) Value

func (sc *StateChange) Value() []byte

type Transaction

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

Transaction type

func NewTransaction

func NewTransaction() *Transaction

func (*Transaction) CodeAddr

func (tx *Transaction) CodeAddr() []byte

func (*Transaction) Expiry

func (tx *Transaction) Expiry() uint64

func (*Transaction) Hash

func (tx *Transaction) Hash() []byte

func (*Transaction) Input

func (tx *Transaction) Input() []byte

func (*Transaction) Marshal

func (tx *Transaction) Marshal() ([]byte, error)

Marshal encodes transaction as bytes

func (*Transaction) MarshalJSON

func (tx *Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) Nonce

func (tx *Transaction) Nonce() int64

func (*Transaction) Sender

func (tx *Transaction) Sender() *PublicKey

func (*Transaction) SetCodeAddr

func (tx *Transaction) SetCodeAddr(val []byte) *Transaction

func (*Transaction) SetExpiry

func (tx *Transaction) SetExpiry(val uint64) *Transaction

func (*Transaction) SetInput

func (tx *Transaction) SetInput(val []byte) *Transaction

func (*Transaction) SetNonce

func (tx *Transaction) SetNonce(val int64) *Transaction

func (*Transaction) Sign

func (tx *Transaction) Sign(signer Signer) *Transaction

func (*Transaction) Sum

func (tx *Transaction) Sum() []byte

Sum returns sha3 sum of transaction

func (*Transaction) Unmarshal

func (tx *Transaction) Unmarshal(b []byte) error

UnmarshalTransaction decodes transaction from bytes

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(b []byte) error

func (*Transaction) Validate

func (tx *Transaction) Validate() error

Validate transaction

type TxCommit

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

func NewTxCommit

func NewTxCommit() *TxCommit

func (*TxCommit) BlockHash

func (txc *TxCommit) BlockHash() []byte

func (*TxCommit) BlockHeight

func (txc *TxCommit) BlockHeight() uint64

func (*TxCommit) Elapsed

func (txc *TxCommit) Elapsed() float64

func (*TxCommit) Error

func (txc *TxCommit) Error() string

func (*TxCommit) Hash

func (txc *TxCommit) Hash() []byte

func (*TxCommit) Marshal

func (txc *TxCommit) Marshal() ([]byte, error)

func (*TxCommit) MarshalJSON

func (txc *TxCommit) MarshalJSON() ([]byte, error)

func (*TxCommit) SetBlockHash

func (txc *TxCommit) SetBlockHash(val []byte) *TxCommit

func (*TxCommit) SetBlockHeight

func (txc *TxCommit) SetBlockHeight(val uint64) *TxCommit

func (*TxCommit) SetElapsed

func (txc *TxCommit) SetElapsed(val float64) *TxCommit

func (*TxCommit) SetError

func (txc *TxCommit) SetError(val string) *TxCommit

func (*TxCommit) SetHash

func (txc *TxCommit) SetHash(val []byte) *TxCommit

func (*TxCommit) Unmarshal

func (txc *TxCommit) Unmarshal(b []byte) error

func (*TxCommit) UnmarshalJSON

func (txc *TxCommit) UnmarshalJSON(b []byte) error

type TxList

type TxList []*Transaction

func NewTxList

func NewTxList() *TxList

func (*TxList) Marshal

func (txs *TxList) Marshal() ([]byte, error)

Marshal encodes tx list as bytes

func (*TxList) Unmarshal

func (txs *TxList) Unmarshal(b []byte) error

UnmarshalTxList decodes tx list from bytes

type ValidatorStore

type ValidatorStore interface {
	ValidatorCount() int
	MajorityCount() int
	IsValidator(pubKey *PublicKey) bool
	GetValidator(idx int) *PublicKey
	GetValidatorIndex(pubKey *PublicKey) int
}

ValidatorStore godoc

func NewValidatorStore

func NewValidatorStore(validators []*PublicKey) ValidatorStore

type Vote

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

Vote type

func NewVote

func NewVote() *Vote

func (*Vote) BlockHash

func (vote *Vote) BlockHash() []byte

func (*Vote) Marshal

func (vote *Vote) Marshal() ([]byte, error)

Marshal encodes vote as bytes

func (*Vote) Unmarshal

func (vote *Vote) Unmarshal(b []byte) error

Unmarshal decodes vote from bytes

func (*Vote) Validate

func (vote *Vote) Validate(vs ValidatorStore) error

Validate vote

func (*Vote) Voter

func (vote *Vote) Voter() *PublicKey

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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