generator

package
v0.0.0-...-6e04e41 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// If the generator id is NoGeneratorId, it means the generator is not saved in the peer
	NoGeneratorId = uint64(0xffffffffffffffff)
	MinerInterval = 40 * time.Second
)
View Source
const (
	HandOverTypeByEpochOrder = 0
	HandOverTypeByVote       = 1
)

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type Generator

type Generator struct {
	GeneratorId   uint64 // The validator id of generator
	Height        int32  // The block height for the generator
	Timestamp     int64  // The time of generator created
	Token         string // The token for the generator, it signed by generate
	Validatorinfo *validatorinfo.ValidatorInfo
	MinerTime     time.Time

	LocalMiner MinerInterface
}

func NewGenerator

func NewGenerator(validatorInfo *validatorinfo.ValidatorInfo, height int32, timestamp int64, token string) *Generator

func (*Generator) ContinueNextSlot

func (g *Generator) ContinueNextSlot() error

func (*Generator) GetTokenData

func (g *Generator) GetTokenData() []byte

func (*Generator) MinerNewBlock

func (g *Generator) MinerNewBlock()

func (*Generator) SetHandOverTime

func (g *Generator) SetHandOverTime(handOverTime time.Time) error

func (*Generator) SetLocalMiner

func (g *Generator) SetLocalMiner(localMiner MinerInterface)

func (*Generator) SetToken

func (g *Generator) SetToken(token string)

func (*Generator) VerifyToken

func (g *Generator) VerifyToken(pubKey []byte) bool

type GeneratorHandOver

type GeneratorHandOver struct {
	ValidatorId  uint64 // The current validator id (current generator, or voter)
	HandOverType int32  // HandOverType: 0: HandOver by current generator with Epoch member Order, 1: Vote by Epoch member
	Timestamp    int64  // The time of generator hand over
	Token        string // The token for generator handover, it sign by current generator (HandOver), if the type is vote, it is signed by voter
	GeneratorId  uint64 // The next validator id (next generator)
	Height       int32  // The next block height
}

func (*GeneratorHandOver) GetTokenData

func (gho *GeneratorHandOver) GetTokenData() []byte

func (*GeneratorHandOver) VerifyToken

func (gho *GeneratorHandOver) VerifyToken(pubKey []byte) bool

type MinerInterface

type MinerInterface interface {
	// OnTimeGenerateBlock is invoke when time to generate block.
	OnTimeGenerateBlock() (*chainhash.Hash, int32, error)
}

type MinerNewBlock

type MinerNewBlock struct {
	GeneratorId uint64                               // The validator id of generator
	PublicKey   [btcec.PubKeyBytesLenCompressed]byte // The public key of generator
	Height      int32                                // The block height for the generator
	MinerTime   int64                                // The time of generator created
	Hash        *chainhash.Hash                      // Block hash
	Token       string                               // The token for the generator, it signed by generate
}

func (*MinerNewBlock) GetTokenData

func (m *MinerNewBlock) GetTokenData() []byte

func (*MinerNewBlock) VerifyToken

func (g *MinerNewBlock) VerifyToken(pubKey []byte) bool

Jump to

Keyboard shortcuts

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