blockchain

package
v0.0.0-...-820de1c Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package blockchain contains the "Blockchain" struct that holds all mined blocks. It is also responsible for the "Block" struct and all methods that are related with hashing, validating etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBlock

func AddBlock(b t.Block) error

AddBlock adds a "Block" to the given blockchain state.

func HashBlockValues

func HashBlockValues(timestamp int64, lastHash string, txs []t.Transaction, difficulty uint64, nonce int) (string, error)

HashBlockValues takes values of a Block, plus a nonce, and receives the derived hash string.

func LastBlock

func LastBlock() (t.Block, error)

LastBlock returns the last Block of the current chain

func NewGenesisBlock

func NewGenesisBlock() t.Block

NewGenesisBlock returns a "Block" that contains static data. Can be used to initialize a new chain.

func VerifyBlockHash

func VerifyBlockHash(b t.Block) (bool, error)

VerifyBlockHash returns "true" if the hash inside the "Block" is a valid hash of itself.

Types

type State

type State struct {
	Blocks []t.Block `json:"blocks"`
}

State contains the general blockchain state, most importantly all mined blocks.

func GetState

func GetState() (State, error)

GetState returns the current state of the blockchain with all their blocks.

func New

func New() State

New returns a "State" struct with the genesis block as the first and only value in it's "Blocks" slice.

func (*State) IsValidChain

func (s *State) IsValidChain() bool

IsValidChain validates if all blocks contain valid hashes and are chained properly through their "lastHash".

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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