mining

package
v0.0.0-...-1cfbcab Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// BlockProcessedChan is a channel for indicating blocks have been processed
	BlockProcessedChan = make(chan int)
)

Functions

func EnqueueTransactionData

func EnqueueTransactionData(data *BlockData)

EnqueueTransactionData enqueues the latest transaction data

func IsBlockDataQueued

func IsBlockDataQueued(data *BlockData) bool

IsBlockDataQueued returns true if block data is queued

func NewTransactionDataExists

func NewTransactionDataExists() bool

NewTransactionDataExists returns true if there is enqueued transaction data

func RemoveTransactionData

func RemoveTransactionData(data *BlockData) (err error)

RemoveTransactionData removes the specified transaction data TODO: may want to be more efficient here

func StringToTime

func StringToTime(s string) (t time.Time, err error)

StringToTime returns the time representation of a string

func TimeToString

func TimeToString(t time.Time) string

TimeToString returns the string representation of a time

Types

type Block

type Block struct {
	Data          BlockData
	PrevBlockHash string
	Hash          string
}

Block keeps block headers

func NewBlock

func NewBlock(data BlockData, prevBlockHash string) *Block

NewBlock creates and returns Block

func NewGenesisBlock

func NewGenesisBlock() *Block

NewGenesisBlock creates and returns genesis Block

func (*Block) ComputeHash

func (b *Block) ComputeHash() string

ComputeHash calculates the block hash

type BlockData

type BlockData struct {
	Timestamp  string
	PublicKey  string
	Signature  string
	ProjectID  string
	CommitHash string
	FileHashes map[string]string
	MetaData   map[string]string
}

BlockData is the data for a block

func PeekLatestTransactionData

func PeekLatestTransactionData() (data *BlockData, err error)

PeekLatestTransactionData returns the latest transaction data

type Blockchain

type Blockchain struct {
	Blocks      []*Block
	StagedBlock *Block
}

Blockchain keeps a sequence of Blocks

func NewBlockchain

func NewBlockchain() *Blockchain

NewBlockchain creates a new Blockchain with genesis Block

func (*Blockchain) Commit

func (bc *Blockchain) Commit() (err error)

Commit commits a staged block to the blockchain

func (*Blockchain) IsBlockValid

func (bc *Blockchain) IsBlockValid(block *Block) error

IsBlockValid determines if the newBlock is a valid successor to oldBlock

func (*Blockchain) ProcessNewBlock

func (bc *Blockchain) ProcessNewBlock(data BlockData) *Block

ProcessNewBlock saves provided data as a block in the blockchain

func (*Blockchain) StageBlock

func (bc *Blockchain) StageBlock(b *Block)

StageBlock stages a block

Jump to

Keyboard shortcuts

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