blockchain

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Difficulty uint64 `json:"difficultyStart"`
	Height     uint64 `json:"height"`
	Coinbase   string `json:"coinbase"`
	Time       uint64 `json:"time"`
	Nonce      uint64 `json:"nonce"`
}

Block represents each block in the blockchain

type Blockchain

type Blockchain struct {
	Locker *sync.Mutex
	Chain  []Block

	// time function
	Now func() uint64
}

Blockchain represents current state of the chain

func CreateBlockchain

func CreateBlockchain() *Blockchain

CreateBlockchain creates initial blockchain state

func (*Blockchain) CalcTimeTargetV1

func (chain *Blockchain) CalcTimeTargetV1(parent *Block) *calculus.TimeTarget

*

  • Implements block time consensus *
  • POS-11: Block time restrictions
  • POS-12: Block interval enforcement

func (*Blockchain) CalcTimeTargetV2

func (chain *Blockchain) CalcTimeTargetV2(parent *Block) *calculus.TimeTarget

CalcTimeTargetV2 calculates asgard time target

func (*Blockchain) GetBlock

func (chain *Blockchain) GetBlock(height uint64) *Block

GetBlock return height corresponding mined block

func (*Blockchain) LastBlock

func (chain *Blockchain) LastBlock() *Block

LastBlock returns last mined block in chain (the blockchain has genesis block)

func (*Blockchain) NewBlock

func (chain *Blockchain) NewBlock(block *Block)

NewBlock appends new mined block into the chain

Jump to

Keyboard shortcuts

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