block

package
v0.0.0-...-7bd4979 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: MIT Imports: 17 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockRewardCalc = func(blockNumber uint64, config *c.Config) uint64 {
	if blockNumber == 0 {
		return config.Dev.Genesis.SuppliedCoins
	}
	return formulas.BlockReward(config.Dev.Genesis.MaxCoinSupply-config.Dev.Genesis.SuppliedCoins, blockNumber)
}

Functions

func MockNTP

func MockNTP(n ntp.NTPInterface) func(*BlockHeader)

Types

type Block

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

func BlockFromPBData

func BlockFromPBData(block *generated.Block) *Block

func CreateBlock

func CreateBlock(minerAddress []byte, blockNumber uint64, prevBlockHeaderhash []byte, prevBlockTimestamp uint64, txs []transactions.TransactionInterface, timestamp uint64) *Block

func DeSerializeBlock

func DeSerializeBlock(data []byte) (*Block, error)

func (*Block) ApplyStateChanges

func (b *Block) ApplyStateChanges(addressesState map[string]*addressstate.AddressState) bool

func (*Block) BlockHeader

func (b *Block) BlockHeader() BlockHeader

func (*Block) BlockNumber

func (b *Block) BlockNumber() uint64

func (*Block) BlockReward

func (b *Block) BlockReward() uint64

func (*Block) Epoch

func (b *Block) Epoch() uint64

func (*Block) FromJSON

func (b *Block) FromJSON(jsonData string) *Block

func (*Block) GenerateHeaderHash

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

func (*Block) GenesisBalance

func (b *Block) GenesisBalance() []*generated.GenesisBalance

func (*Block) HeaderHash

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

func (*Block) IsEqual

func (b *Block) IsEqual(b2 *Block) bool

func (*Block) JSON

func (b *Block) JSON() (string, error)

func (*Block) MiningBlob

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

func (*Block) MiningNonce

func (b *Block) MiningNonce() uint32

func (*Block) PBData

func (b *Block) PBData() *generated.Block

func (*Block) PrepareAddressesList

func (b *Block) PrepareAddressesList() map[string]*addressstate.AddressState

func (*Block) PrevHeaderHash

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

func (*Block) Serialize

func (b *Block) Serialize() ([]byte, error)

func (*Block) SetDifficultyTracker

func (b *Block) SetDifficultyTracker(dt pow.DifficultyTrackerInterface)

func (*Block) SetNTP

func (b *Block) SetNTP(n ntp.NTPInterface)

func (*Block) SetNonces

func (b *Block) SetNonces(miningNonce uint32, extraNonce uint64)

func (*Block) Size

func (b *Block) Size() int

func (*Block) Timestamp

func (b *Block) Timestamp() uint64

func (*Block) Transactions

func (b *Block) Transactions() []*generated.Transaction

func (*Block) UpdateMiningAddress

func (b *Block) UpdateMiningAddress(miningAddress []byte)

func (*Block) Validate

func (b *Block) Validate(blockFromState *Block, parentBlock *Block, parentMetadata *metadata.BlockMetaData, measurement uint64, futureBlocks map[string]*Block) bool

func (*Block) ValidateMiningNonce

func (b *Block) ValidateMiningNonce(bh *BlockHeader, parentBlock *Block, parentMetadata *metadata.BlockMetaData, measurement uint64, enableLogging bool) bool

func (*Block) VerifyBlob

func (b *Block) VerifyBlob(blob []byte) bool

type BlockBareInterface

type BlockBareInterface interface {
	BlockNumber() uint64
	HeaderHash() []byte
	Timestamp() uint64
}

BlockBareInterface only includes the basics which other components working with Block might need to use. Use it when you're too lazy to make a real Block.

type BlockHeader

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

func BlockHeaderFromPBData

func BlockHeaderFromPBData(header *generated.BlockHeader) *BlockHeader

func CreateBlockHeader

func CreateBlockHeader(blockNumber uint64, prevBlockHeaderHash []byte, prevBlockTimestamp uint64, merkleRoot []byte, feeReward uint64, timestamp uint64, options ...func(*BlockHeader)) *BlockHeader

func (*BlockHeader) BlockNumber

func (bh *BlockHeader) BlockNumber() uint64

func (*BlockHeader) BlockReward

func (bh *BlockHeader) BlockReward() uint64

func (*BlockHeader) Epoch

func (bh *BlockHeader) Epoch() uint64

func (*BlockHeader) ExtraNonce

func (bh *BlockHeader) ExtraNonce() uint64

func (*BlockHeader) ExtraNonceOffset

func (bh *BlockHeader) ExtraNonceOffset() uint16

func (*BlockHeader) FeeReward

func (bh *BlockHeader) FeeReward() uint64

func (*BlockHeader) FromJSON

func (bh *BlockHeader) FromJSON(jsonData string) *BlockHeader

func (*BlockHeader) GenerateHeaderHash

func (bh *BlockHeader) GenerateHeaderHash() []byte

func (*BlockHeader) HeaderHash

func (bh *BlockHeader) HeaderHash() []byte

func (*BlockHeader) JSON

func (bh *BlockHeader) JSON() (string, error)

func (*BlockHeader) MiningBlob

func (bh *BlockHeader) MiningBlob() []byte

func (*BlockHeader) MiningNonce

func (bh *BlockHeader) MiningNonce() uint32

func (*BlockHeader) NonceOffset

func (bh *BlockHeader) NonceOffset() int64

func (*BlockHeader) Option

func (bh *BlockHeader) Option(options ...func(*BlockHeader))

func (*BlockHeader) PrevHeaderHash

func (bh *BlockHeader) PrevHeaderHash() []byte

func (*BlockHeader) SetMiningNonceFromBlob

func (bh *BlockHeader) SetMiningNonceFromBlob(blob []byte)

func (*BlockHeader) SetNonces

func (bh *BlockHeader) SetNonces(miningNonce uint32, extraNonce uint64)

func (*BlockHeader) SetPBData

func (bh *BlockHeader) SetPBData(blockHeader *generated.BlockHeader)

func (*BlockHeader) Timestamp

func (bh *BlockHeader) Timestamp() uint64

func (*BlockHeader) TxMerkleRoot

func (bh *BlockHeader) TxMerkleRoot() []byte

func (*BlockHeader) UpdateMerkleRoot

func (bh *BlockHeader) UpdateMerkleRoot(hashedtransactions []byte)

func (*BlockHeader) Validate

func (bh *BlockHeader) Validate(feeReward uint64, coinbaseAmount uint64, txMerkleRoot []byte) bool

func (*BlockHeader) ValidateParentChildRelation

func (bh *BlockHeader) ValidateParentChildRelation(parentBlock BlockBareInterface) bool

func (*BlockHeader) VerifyBlob

func (bh *BlockHeader) VerifyBlob(blob []byte) bool

type BlockHeaderInterface

type BlockHeaderInterface interface {
	BlockNumber() uint64

	Epoch() uint64

	Timestamp() uint64

	HeaderHash() []byte

	PrevHeaderHash() []byte

	BlockReward() uint64

	FeeReward() uint64

	TxMerkleRoot() []byte

	ExtraNonce() uint64

	MiningNonce() uint32

	NonceOffset() uint16

	ExtraNonceOffset() uint16

	MiningBlob() []byte

	GenerateHeaderHash() []byte

	UpdateMerkleRoot([]byte)

	SetNonces(uint32, uint64)

	SetMiningNonceFromBlob([]byte)

	Validate(uint64, uint64, []byte) bool

	ValidateParentChildRelation(BlockBareInterface) bool

	VerifyBlob([]byte) bool

	SetPBData(*generated.BlockHeader)

	FromJSON(string) *BlockHeader

	JSON() (string, error)
}

TODO: this Interface is outdated and does not correspond to BlockHeader method signatures

type BlockInterface

type BlockInterface interface {
	PBData() *generated.Block

	Size() int

	GenesisBalance() []*generated.GenesisBalance

	BlockNumber() uint64

	Epoch() uint64

	HeaderHash() []byte

	PrevHeaderHash() []byte

	Transactions() []*generated.Transaction

	MiningNonce() uint32

	BlockReward() []uint64

	FeeReward() []uint64

	Timestamp() []uint64

	MiningBlob() []byte

	MiningNonceOffset() []byte

	VerifyBlob([]byte) bool

	SetNonces(uint32, uint64)

	FromJSON(string) Block

	JSON() (string, error)

	Serialize() ([]byte, error)

	Create(blockNumber uint64,
		prevHeaderHash []byte,
		prevBlockTimestamp uint64,
		transactions generated.Transaction,
		minerAddress []byte)

	UpdateMiningAddress(miningAddress []byte)

	Validate(futureBlocks map[string]*generated.Block)

	ValidateMiningNonce(bh *BlockHeader, parentBlock *Block, parentMetadata metadata.BlockMetaData, measurement uint64, enableLogging bool) bool

	IsFutureBlock() bool

	ValidateParentChildRelation(block generated.Block) bool

	ApplyStateChanges(addressesState map[string]*addressstate.AddressState)
}

type PlainBlock

type PlainBlock struct {
	Header       *PlainBlockHeader                        `json:"header" bson:"header"`
	Transactions []transactions.PlainTransactionInterface `json:"transactions" bson:"transactions"`
}

func (*PlainBlock) BlockFromPBData

func (b *PlainBlock) BlockFromPBData(b2 *generated.Block)

type PlainBlockHeader

type PlainBlockHeader struct {
	HeaderHash     string `json:"headerHash" bson:"headerHash"`
	BlockNumber    uint64 `json:"blockNumber" bson:"blockNumber"`
	Timestamp      uint64 `json:"timestamp" bson:"timestamp"`
	PrevHeaderHash string `json:"prevHeaderHash" bson:"prevHeaderHash"`
	BlockReward    uint64 `json:"blockReward" bson:"blockReward"`
	FeeReward      uint64 `json:"feeReward" bson:"feeReward"`
	MerkleRoot     string `json:"merkleRoot" bson:"merkleRoot"`

	MiningNonce uint32 `json:"miningNonce" bson:"miningNonce"`
	ExtraNonce  uint64 `json:"extraNonce" bson:"extraNonce"`
}

func (*PlainBlockHeader) BlockHeaderFromPBData

func (bh *PlainBlockHeader) BlockHeaderFromPBData(bh2 *generated.BlockHeader)

Jump to

Keyboard shortcuts

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