blockchain

package
v0.0.0-...-97f3c37 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BLOCKCHAIN_PATH string        = "./.blockchain"
	SAVE_FREQ       time.Duration = 800 * time.Millisecond
)

Functions

This section is empty.

Types

type Blockchain

type Blockchain struct {
	Chain []*data.Block
	Mux   sync.Mutex
}

handle fork (appropriate data structure)

func NewBlockchain

func NewBlockchain(dist map[string]float64) *Blockchain

func (*Blockchain) GetBlockchain

func (bc *Blockchain) GetBlockchain() []*data.Block

returns a copy of the blockchain

func (*Blockchain) GetPrevHash

func (bc *Blockchain) GetPrevHash() string

func (*Blockchain) GetSlot

func (bc *Blockchain) GetSlot() int

func (*Blockchain) Update

func (bc *Blockchain) Update(block *data.Block)

block paramater has already been validated, add to blockchain and handle forks (keeping track of side chains and longest one in them)

type StakeDistribution

type StakeDistribution struct {
	TotalCoins   uint64
	Distribution map[string]float64
	Mux          sync.Mutex
}

func NewStakeDist

func NewStakeDist(total uint64, dist map[string]float64) StakeDistribution

func (*StakeDistribution) Get

func (sd *StakeDistribution) Get(key string) float64

func (*StakeDistribution) Update

func (sd *StakeDistribution) Update(trans data.Transaction) error

func (*StakeDistribution) Valid

func (sd *StakeDistribution) Valid(trans data.Transaction) (bool, error)

type TransPool

type TransPool struct {
	Pool map[string]*data.Transaction //key is transaction signature
	Mux  sync.Mutex
}

func NewTransPool

func NewTransPool() *TransPool

func (*TransPool) Add

func (tp *TransPool) Add(t *data.Transaction)

func (*TransPool) Remove

func (tp *TransPool) Remove(val string)

func (*TransPool) Update

func (tp *TransPool) Update(trans []data.Transaction)

type UserMoney

type UserMoney struct {
	Money map[string]float64
	Mux   sync.Mutex
}

func NewUserMoney

func NewUserMoney(stakeDist *StakeDistribution) *UserMoney

func (*UserMoney) HasEnoughMoney

func (u *UserMoney) HasEnoughMoney(user string, amount float64) bool

Jump to

Keyboard shortcuts

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