core

package
v0.0.0-...-2a42317 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Blockchain []Block

Blockchain is the main set of blocks in the network

View Source
var Mutex = &sync.Mutex{}

Mutex provides locking mechanism for one goroutine

Functions

func CalculateBlockHash

func CalculateBlockHash(block Block) string

CalculateBlockHash hashes using SHA256 algorithm

func CheckDuplicateVote

func CheckDuplicateVote(blockchain []Block, vote identity.VoterInfo) bool

CheckDuplicateVote sees if a vote casted is a duplicate

func IsBlockValid

func IsBlockValid(newBlock, oldBlock Block) bool

IsBlockValid makes sure block is valid by checking index, and comparing the hash of the previous block

func Run

func Run() error

Run starts the web server

Types

type Block

type Block struct {
	Index     int
	Timestamp string
	Vote      Vote
	Hash      string
	PrevHash  string
}

Block represents each 'item' in the blockchain

func GenerateBlock

func GenerateBlock(oldBlock Block, Candidate string, payload identity.VoterInfo) Block

GenerateBlock creates a new block using previous block's hash

type Message

type Message struct {
	VoteCandidate string
	VoterIdentity identity.VoterInfo
}

Message takes incoming JSON payload for writing a vote

type Vote

type Vote struct {
	Candidate     string
	VoterIdentity string
}

Vote represents a 'vote' casted

Jump to

Keyboard shortcuts

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