core

package
v0.0.0-...-dd0ed3b Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: GPL-3.0 Imports: 13 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("invalid 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")
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) Marshal

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

Marshal encodes block 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) 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) SetView

func (blk *Block) SetView(val uint32) *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

Unmarshal decodes block from bytes

func (*Block) UnmarshalJSON

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

func (*Block) Validate

func (blk *Block) Validate(rs RoleStore) error

Validate block

func (*Block) View

func (blk *Block) View() uint32

func (*Block) Vote

func (blk *Block) Vote(signer Signer, quota uint64) *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 StringToPubKey

func StringToPubKey(v string) *PublicKey

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(signer Signer, votes []*Vote) *QuorumCert

func (*QuorumCert) FindVote

func (qc *QuorumCert) FindVote(signer Signer) uint64

func (*QuorumCert) Marshal

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

Marshal encodes quorum cert as bytes

func (*QuorumCert) Proposer

func (qc *QuorumCert) Proposer() *PublicKey

func (*QuorumCert) Quotas

func (qc *QuorumCert) Quotas() []uint64

func (*QuorumCert) Signatures

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

func (*QuorumCert) SumQuota

func (qc *QuorumCert) SumQuota() uint64

func (*QuorumCert) Unmarshal

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

Unmarshal decodes quorum cert from bytes

func (*QuorumCert) Validate

func (qc *QuorumCert) Validate(rs RoleStore) error

func (*QuorumCert) View

func (qc *QuorumCert) View() uint32

type RoleStore

type RoleStore interface {
	ValidatorCount() int
	MajorityValidatorCount() int
	MajorityQuotaCount() uint64
	IsValidator(pubKey *PublicKey) bool
	GetWindowSize() int
	GetValidator(idx int) *PublicKey
	GetValidatorIndex(pubKey *PublicKey) int
	GetValidatorQuota(pubKey *PublicKey) uint64
}

func NewRoleStore

func NewRoleStore(validators []string, quotas []uint64, size int) RoleStore

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

Unmarshal 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

Unmarshal decodes tx list from bytes

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

func (vote *Vote) Quota() uint64

func (*Vote) Unmarshal

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

Unmarshal decodes vote from bytes

func (*Vote) Validate

func (vote *Vote) Validate(rs RoleStore) error

Validate vote

func (*Vote) View

func (vote *Vote) View() uint32

func (*Vote) Voter

func (vote *Vote) Voter() *PublicKey

Jump to

Keyboard shortcuts

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