blockchain

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: GPL-3.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Index     int
	Timestamp string
	Storage   map[string]map[string]Data
	Hash      string
	PrevHash  string
}

Block represents each 'item' in the blockchain

func (Block) Checksum

func (b Block) Checksum() string

Checksum does SHA256 hashing of the block

func (Block) IsValid

func (newBlock Block) IsValid(oldBlock Block) bool

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

func (Block) NewBlock

func (oldBlock Block) NewBlock(s map[string]map[string]Data) Block

create a new block using previous block's hash

type Blockchain

type Blockchain []Block

Blockchain is a series of validated Blocks

func (Blockchain) IsMoreRecent

func (b Blockchain) IsMoreRecent(bb Blockchain) bool

type Data added in v0.1.0

type Data string

func (Data) Unmarshal added in v0.2.0

func (d Data) Unmarshal(i interface{}) error

Unmarshal the result into the interface. Use it to retrieve data set with SetValue

type DataString added in v0.2.0

type DataString string

type Ledger

type Ledger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(w io.Writer, maxChainSize int) *Ledger

New returns a new ledger which writes to the writer

func (*Ledger) Add

func (l *Ledger) Add(b string, s map[string]interface{})

Add data to the blockchain

func (*Ledger) Announce added in v0.1.0

func (l *Ledger) Announce(ctx context.Context, t time.Duration, async func())

Announce keeps updating async data to the blockchain. Sends a broadcast at the specified interval by making sure the async retrieved value is written to the blockchain

func (*Ledger) BlockChain added in v0.1.0

func (l *Ledger) BlockChain() Blockchain

func (*Ledger) CurrentData added in v0.1.0

func (l *Ledger) CurrentData() map[string]map[string]Data

func (*Ledger) Exists added in v0.1.0

func (l *Ledger) Exists(b string, f func(Data) bool) (exists bool)

ExistsValue returns true if there is one element with a matching value

func (*Ledger) GetKey

func (l *Ledger) GetKey(b, s string) (value Data, exists bool)

GetKey retrieve the current key from the blockchain

func (*Ledger) String

func (l *Ledger) String() string

String returns the blockchain as string

func (*Ledger) Syncronizer

func (l *Ledger) Syncronizer(ctx context.Context, t time.Duration)

Syncronizer starts a goroutine which writes the blockchain to the periodically

func (*Ledger) Update

func (l *Ledger) Update(h *hub.Message) (err error)

Update the blockchain from a message

Jump to

Keyboard shortcuts

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