block

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_block_block_proto protoreflect.FileDescriptor

Functions

func GetBlockVerifiersPeerIDs added in v1.4.0

func GetBlockVerifiersPeerIDs() []peer.ID

func GetReward

func GetReward(blockNumber uint64) (*big.Int, error)

GetReward returns the correct reward for a given block number.

func IsValidVerifier

func IsValidVerifier(address string) bool

IsValidVerifier verifies if an address is a validator

func MarshalProtoBlock

func MarshalProtoBlock(b *ProtoBlock) ([]byte, error)

MarshalProtoTransaction serializes a block to a protobuf message.

func SetBlockVerifiers

func SetBlockVerifiers(v Verifier)

SetBlockVerifiers adds a verifier to the block verifiers.

Types

type Block

type Block struct {
	Hash       []byte
	MerkleHash []byte
	Signature  []byte

	Timestamp         int64
	Data              []byte
	PreviousBlockHash []byte
	Transactions      []transaction.Transaction
	Number            uint64
}

Block represents a block.

func GetGenesisBlock

func GetGenesisBlock() (*Block, error)

GetGenesisBlock returns the genesis block.

func ProtoBlockToBlock

func ProtoBlockToBlock(pblock *ProtoBlock) Block

ProtoBlockToBlock returns a domain block.

func (Block) GetAndValidateCoinbaseTransaction

func (b Block) GetAndValidateCoinbaseTransaction() (transaction.Transaction, error)

GetCoinbaseTransaction gets the coinbase transaction. A coinbase transaction is the first transaction and the public key of the transaction should match the block signer. coinbase should have zero fees in transaction fees.

func (Block) GetBlockHash

func (b Block) GetBlockHash() ([]byte, error)

GetBlockHash hashes the block.

func (Block) GetMerkleHash

func (b Block) GetMerkleHash() ([]byte, error)

GetMerkleHash gets the merkle tree hash of all transactions.

func (*Block) Sign

func (b *Block) Sign(key crypto.PrivKey) error

Sign signs a block with a private key.

func (Block) Validate

func (b Block) Validate() (bool, error)

Validate validates a block.

func (Block) VerifyWithPublicKey

func (b Block) VerifyWithPublicKey(key crypto.PubKey) error

VerifyWithPublicKey verifies a block with a public key. The coinbase transaction always includes the public Key of the verifier. This public key is used to verify the block.

type ProtoBlock

type ProtoBlock struct {

	// hash represents the block hash.
	Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
	// merkle_hash represents the block merkle hash.
	MerkleHash []byte `protobuf:"bytes,2,opt,name=merkle_hash,json=merkleHash,proto3" json:"merkle_hash,omitempty"`
	// signature of the block.
	Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"`
	// timestamp represents the block time.
	Timestamp int64 `protobuf:"varint,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// data includes arbitrary data from the sealer.
	Data []byte `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"`
	// previous_block_hash is the hash of the previous block.
	PreviousBlockHash []byte `protobuf:"bytes,6,opt,name=previous_block_hash,json=previousBlockHash,proto3" json:"previous_block_hash,omitempty"`
	// transactions contain a list of transactions in the block.
	Transactions []*transaction.ProtoTransaction `protobuf:"bytes,7,rep,name=transactions,proto3" json:"transactions,omitempty"`
	// number represents the block number.
	Number uint64 `protobuf:"varint,8,opt,name=number,proto3" json:"number,omitempty"`
	// contains filtered or unexported fields
}

ProtoBlock is the proto representation of a block.

func ToProtoBlock

func ToProtoBlock(block Block) *ProtoBlock

ToProtoBlock returns a proto representation of a block.

func UnmarshalProtoBlock

func UnmarshalProtoBlock(data []byte) (*ProtoBlock, error)

UnmarshalProtoBlock unserializes a byte array to a protobuf block.

func (*ProtoBlock) Descriptor deprecated

func (*ProtoBlock) Descriptor() ([]byte, []int)

Deprecated: Use ProtoBlock.ProtoReflect.Descriptor instead.

func (*ProtoBlock) GetData

func (x *ProtoBlock) GetData() []byte

func (*ProtoBlock) GetHash

func (x *ProtoBlock) GetHash() []byte

func (*ProtoBlock) GetMerkleHash

func (x *ProtoBlock) GetMerkleHash() []byte

func (*ProtoBlock) GetNumber

func (x *ProtoBlock) GetNumber() uint64

func (*ProtoBlock) GetPreviousBlockHash

func (x *ProtoBlock) GetPreviousBlockHash() []byte

func (*ProtoBlock) GetSignature

func (x *ProtoBlock) GetSignature() []byte

func (*ProtoBlock) GetTimestamp

func (x *ProtoBlock) GetTimestamp() int64

func (*ProtoBlock) GetTransactions

func (x *ProtoBlock) GetTransactions() []*transaction.ProtoTransaction

func (*ProtoBlock) ProtoMessage

func (*ProtoBlock) ProtoMessage()

func (*ProtoBlock) ProtoReflect

func (x *ProtoBlock) ProtoReflect() protoreflect.Message

func (*ProtoBlock) Reset

func (x *ProtoBlock) Reset()

func (*ProtoBlock) String

func (x *ProtoBlock) String() string

type Verifier

type Verifier struct {
	Address         string `json:"address"`
	PublicKey       string `json:"public_key"`
	DataVerifier    bool   `json:"data_verifier"`
	PublicKeyCrypto crypto.PubKey
}

Verifier represents a block verifier/sealer

func GetBlockVerifiers

func GetBlockVerifiers() []Verifier

GetBlockVerifiers returns a list of verifiers.

func (*Verifier) PeerID added in v1.4.0

func (v *Verifier) PeerID() (peer.ID, error)

PeerID get peer id from block verifier.

Jump to

Keyboard shortcuts

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