blockchain

package
v0.0.0-...-19c2005 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2022 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const CUSTOM_NET = byte(0x0f0)
View Source
const LIVE_NETWORK = byte(0x0af)
View Source
const STAKE_COST_PER_BLOCK = 10
View Source
const TEST_NETWORK = byte(0x0ba)

Variables

View Source
var GenesisID = hex.EncodeToString(hash.NewBlake3Hash([]byte("genesis_kp")))

Functions

func CheckIfGenesisFileExists

func CheckIfGenesisFileExists(networkID byte) bool

func NewBlockHash

func NewBlockHash(nb *pb.Block) string

func NewBlockchain

func NewBlockchain(networkId byte) *pb.Blockchain

func NewCustomGenesisBlock

func NewCustomGenesisBlock(b *pb.Blockchain)

func NewGenesisAccount

func NewGenesisAccount() *account.Account

func NewTestNetGenesisBlock

func NewTestNetGenesisBlock(b *pb.Blockchain)

func VerifyHash

func VerifyHash(currentHash string, prevHash string, ts string, valaddr string) error

func WriteGenesisBlock

func WriteGenesisBlock(networkID byte, genesis *GenesisBlock) error

Types

type BlockFactory

type BlockFactory interface {
	CreateEmpty() interface{}
	CreateGenesis() *GenesisBlock
	Set(key string, value interface{})
	Validate() bool
	Build() *pb.Block
}

func GetBlockFactory

func GetBlockFactory(bf BlockFactory) BlockFactory

type BlockHandler

type BlockHandler interface {
	Modify(*BlockV1, *VBlock)
	Parse(*BlockV1, *VBlock)
	Verify(*BlockV1, *VBlock)
	Apply(original *BlockV1, blockEdits *BlockV1)
}

type BlockHandlerFunc

type BlockHandlerFunc func(*BlockV1, *VBlock)

func (BlockHandlerFunc) Apply

func (b BlockHandlerFunc) Apply(original *BlockV1, blockEdits *BlockV1)

func (BlockHandlerFunc) Modify

func (b BlockHandlerFunc) Modify(original *BlockV1, proxy *VBlock)

func (BlockHandlerFunc) Parse

func (b BlockHandlerFunc) Parse(original *BlockV1, proxy *VBlock)

func (BlockHandlerFunc) Verify

func (b BlockHandlerFunc) Verify(original *BlockV1, proxy *VBlock)

type BlockProxy

type BlockProxy interface {
	Initialize(chainID string, callerAccount account.Account) error
	IsAllowed(aclType int, callerAccount account.Account) bool
	CreateBlankBLock() *pb.Block
	CopyBlock(b *pb.Block) *pb.Block
	FinalizeBlock(b *pb.Block) error
	GetRawBlock(height uint32) (*pb.Block, error)
	AddBlockToValidationQueue(b *pb.Block)
	ValidateAndSign(b *pb.Block) error
}

BlockProxy protects the existing block by filtering requests and avoiding unwanted tempering

type BlockProxyQueries

type BlockProxyQueries uint32
const (
	BPQ BlockProxyQueries = iota
	INIT
	CREATEBLANK
	COPY
	FINALIZE
	GETRAW
	ADDTOVALQUEUE
	VALANDSIGN
)

type BlockV1

type BlockV1 pb.Block

type BlockValidation

type BlockValidation struct {
	Invalid map[string]error
	Valid   map[string]bool
}

type Blockchain

type Blockchain struct {
	SemVer       version.SemVer
	GenesisBlock []byte

	ChainStates map[string]*fsm.FSM
	BlockVals   *BlockValidation
	*pb.Blockchain
	Bootnodes []interface{}
	// contains filtered or unexported fields
}

func (*Blockchain) CreateOrLoadGenesis

func (b *Blockchain) CreateOrLoadGenesis()

func (*Blockchain) GenerateID

func (b *Blockchain) GenerateID()

func (*Blockchain) GenerateNewBlock

func (b *Blockchain) GenerateNewBlock(validator *pb.Validator) ([]*pb.Block, *pb.Block, error)

func (*Blockchain) InitializeStateMachines

func (b *Blockchain) InitializeStateMachines(machineNames []string, events map[string][]fsm.EventDesc,
	cbs map[string]map[string]fsm.Callback)

func (*Blockchain) SetVersion

func (b *Blockchain) SetVersion()

func (*Blockchain) TriggerStateEvent

func (b *Blockchain) TriggerStateEvent(stateType string, evt string, args ...any) error

func (*Blockchain) ValidateBlock

func (b *Blockchain) ValidateBlock(nb *pb.Block) bool

func (*Blockchain) ValidateBlockCandidate

func (b *Blockchain) ValidateBlockCandidate(newBlock *pb.Block) error

func (*Blockchain) ValidateBlockchain

func (b *Blockchain) ValidateBlockchain() error

type ConsensusConfig

type ConsensusConfig struct {
	MinValidators int
	MaxValidators int
	MinStake      *big.Int
	MinRounds     int
	MaxRounds     int
	Quorum        int
	Reward        *big.Int
}

type GKey

type GKey string

type GenKeys

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

type GenesisBlock

type GenesisBlock struct {
	NetworkID         byte
	Account           *account.Account `json:"-"`
	Address           string
	CreationDate      int64
	Epoch             uint32
	GenesisValidators []*pb.Validator
	Block             *pb.Block
	// contains filtered or unexported fields
}

func NewLiveGenesisBlock

func NewLiveGenesisBlock() *GenesisBlock

func (*GenesisBlock) Coinbase

func (g *GenesisBlock) Coinbase() string

func (*GenesisBlock) Config

func (g *GenesisBlock) Config() *any

func (*GenesisBlock) DNAProof

func (g *GenesisBlock) DNAProof() string

func (*GenesisBlock) Hash

func (g *GenesisBlock) Hash() any

func (*GenesisBlock) Hex

func (g *GenesisBlock) Hex() string

func (*GenesisBlock) Metadata

func (g *GenesisBlock) Metadata() map[string]any

func (*GenesisBlock) NewKyberKeys

func (g *GenesisBlock) NewKyberKeys() (p2p.P2PPrivateKey, p2p.P2PPublicKey)

func (*GenesisBlock) Nonce

func (g *GenesisBlock) Nonce() [8]byte

func (*GenesisBlock) Pb

func (g *GenesisBlock) Pb() *pb.Block

func (*GenesisBlock) Raw

func (g *GenesisBlock) Raw() []byte

func (*GenesisBlock) SaveContext

func (g *GenesisBlock) SaveContext() error

func (*GenesisBlock) Sign

func (g *GenesisBlock) Sign(msg string) []byte

func (*GenesisBlock) String

func (g *GenesisBlock) String() string

func (*GenesisBlock) Timestamp

func (g *GenesisBlock) Timestamp() timestamppb.Timestamp

type GenesisContext

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

type GuardFunc

type GuardFunc = func(caller account.Account, query BlockProxyQueries) error

type Proxy

type Proxy struct {
	BlockProxy
	// contains filtered or unexported fields
}

func (*Proxy) Initialize

func (bp *Proxy) Initialize(chainID string, callerAccount account.Account) error

type ProxyContextKey

type ProxyContextKey string

type QuantosConsensus

type QuantosConsensus struct {
	Round         int
	Validators    []*pb.Validator
	NumValidators int
	TotalStakes   *big.Int
	Config        *ConsensusConfig
}

func (*QuantosConsensus) AddValidator

func (c *QuantosConsensus) AddValidator(v *pb.Validator)

func (*QuantosConsensus) GetNumValidators

func (c *QuantosConsensus) GetNumValidators() int

func (*QuantosConsensus) GetTotalStakes

func (c *QuantosConsensus) GetTotalStakes() *big.Int

func (*QuantosConsensus) NewRound

func (c *QuantosConsensus) NewRound() (*Round, error)

func (*QuantosConsensus) SetConfig

func (c *QuantosConsensus) SetConfig()

func (*QuantosConsensus) Start

func (c *QuantosConsensus) Start(r *Round) (*pb.Validator, error)

type Round

type Round struct {
	ID         int
	Validators []*pb.Validator

	WinnerPool []*pb.Validator
	// contains filtered or unexported fields
}

type RunFunc

type RunFunc = func(g GuardFunc, query BlockProxyQueries, data ...any) (any, error)

type VBlock

type VBlock pb.Block

Jump to

Keyboard shortcuts

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