validator

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: 16 Imported by: 0

Documentation

Overview

Package validator implements sealing and broadcasting blocks to the network.

The block sealing process is to go through all the transactions in the mempool and order them by nounce and later on construct an uncommitted balance which will be used to check if a transaction has enough balance and allowed to change the state of the blockchain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NetworkMessagePublisher

type NetworkMessagePublisher interface {
	PublishMessageToNetwork(ctx context.Context, topicName string, data []byte) error
}

NetworkMessagePublisher is a pub sub message broadcaster.

type UncommitedBalance

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

UncommitedBalance represents an uncommitted balance of a user.

func NewUncommitedBalance

func NewUncommitedBalance() UncommitedBalance

NewUncommitedBalance creates a new uncommitted balance.

func (*UncommitedBalance) InitializeBalanceAndNounceFor

func (b *UncommitedBalance) InitializeBalanceAndNounceFor(address string, balance *big.Int, nounce uint64)

InitializeBalanceAndNounceFor sets the balance and nounce for an address.

func (*UncommitedBalance) IsInitialized

func (b *UncommitedBalance) IsInitialized(address string) bool

IsInitialized checks if balance is initialized for an address.

func (*UncommitedBalance) Subtract

func (b *UncommitedBalance) Subtract(address string, amount *big.Int, nounce uint64) bool

Subtract from balance.

type Validator

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

Validator struct.

func New

func New(node NetworkMessagePublisher, bchain blockchain.Interface, privateKeys []crypto.PrivKey) (*Validator, error)

New constructs a new validator.

func (*Validator) BroadcastBlock

func (m *Validator) BroadcastBlock(ctx context.Context, validBlock *block.Block) error

BroadcastBlock broadcasts a block to the network.

func (*Validator) SealBlock

func (m *Validator) SealBlock(timestamp int64) (*block.Block, string, error)

SealBlock seals a block.

Jump to

Keyboard shortcuts

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