chain

package
v0.0.8-beta Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Difficulty = int64(21)

Difficulty Implementation of the difficulty rate

View Source
const (
	KeyLastHash = "last_hash"
)

Variables

This section is empty.

Functions

func IsValidPoS

func IsValidPoS(block *Block, stake *big.Int) bool

Types

type Block

type Block struct {
	Data  []byte //	this block's data
	Hash  []byte //	this block's hash
	Link  []byte //	the hash of the last block in the chain. this is the key part that links the blocks together
	Nonce int64  //	the nonce used to sing the block. useful for verification
}

func (*Block) Build

func (b *Block) Build(data []byte, link []byte, stake *big.Int)

func (*Block) Deserialize

func (b *Block) Deserialize(data []byte) error

func (*Block) Print

func (b *Block) Print()

func (*Block) Serialize

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

type Chain

type Chain struct {
	LastHash []byte
	// contains filtered or unexported fields
}

func (*Chain) AddBlock

func (c *Chain) AddBlock(data []byte) error

func (*Chain) GetBlock

func (c *Chain) GetBlock(hash []byte) (*Block, error)

func (*Chain) GetLastBlock

func (c *Chain) GetLastBlock() (*Block, error)

func (*Chain) Init

func (c *Chain) Init() error
func (c *Chain) IterateLink(each func(b *Block), pre, post func()) error

func (*Chain) UpdateLastHash

func (c *Chain) UpdateLastHash() error

type Persistance

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

func (*Persistance) Get

func (p *Persistance) Get(key []byte) ([]byte, error)

func (*Persistance) GetLastHash

func (p *Persistance) GetLastHash() ([]byte, error)

func (*Persistance) Init

func (p *Persistance) Init(path string, genesisFn func() (Serializable, []byte)) ([]byte, error)

func (*Persistance) Iterate

func (p *Persistance) Iterate(prefix []byte, block Serializable, callback func(value []byte) error) error

func (*Persistance) SaveBlock

func (p *Persistance) SaveBlock(hash []byte, block Serializable) error

type ProofOfStake

type ProofOfStake struct {
	Block  *Block
	Target *big.Int
	Stake  *big.Int
}

func (*ProofOfStake) Run

func (pos *ProofOfStake) Run() (int64, []byte)

type Serializable

type Serializable interface {
	Serialize() ([]byte, error)
	Deserialize(data []byte) error
}

Jump to

Keyboard shortcuts

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