blocktrain

package
v0.0.0-...-e6e99b1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BufferSize = 4
)

Variables

View Source
var Log = true

Functions

func Hash

func Hash(input []byte) []byte

func StatusToString

func StatusToString(status VerificationStatus) string

Types

type Block

type Block struct {
	Timestamp time.Time
	PrevHash  []byte
	TXHash    []byte
}

func NewBlock

func NewBlock(tx *MerkleNode, prevBlock *Block) *Block

func (*Block) Hash

func (block *Block) Hash() []byte

func (*Block) PrintBlock

func (block *Block) PrintBlock()

type Chain

type Chain struct {
	Store       DataStore
	SeedHash    []byte
	Buffer      []MerkleData
	LatestBlock *Block
}

func Genesis

func Genesis(store DataStore) *Chain

func (*Chain) Commit

func (chain *Chain) Commit(data []byte) (txID string)

func (*Chain) PrintChain

func (chain *Chain) PrintChain()

func (*Chain) Retrieve

func (chain *Chain) Retrieve(txID string) []byte

func (*Chain) Verify

func (chain *Chain) Verify(txID string, data []byte) VerificationStatus

type DataStore

type DataStore interface {
	InsertTree(root *MerkleNode)
	InsertBlock(block *Block)
	InsertData(data []byte, txID string)
	GetTree(hash []byte) *MerkleNode
	GetBlock(hash []byte) *Block
	GetData(txID string) []byte
}

type MerkleData

type MerkleData struct {
	Data []byte
	TxID string
}

type MerkleNode

type MerkleNode struct {
	Hash []byte
	TxID string
	// contains filtered or unexported fields
}

func NewMerkleTree

func NewMerkleTree(data []MerkleData) *MerkleNode

func (*MerkleNode) Contains

func (node *MerkleNode) Contains(txID string) bool

func (*MerkleNode) PrintRecursive

func (node *MerkleNode) PrintRecursive(level int)

func (*MerkleNode) Verify

func (node *MerkleNode) Verify(txID string, data []byte) bool

type VerificationStatus

type VerificationStatus int
const (
	InBuffer VerificationStatus = iota
	InBufferInvalid
	Invalid
	UnknownTxID
	Verified
)

Jump to

Keyboard shortcuts

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