blockchain

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: GPL-3.0 Imports: 10 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
	AddressMap map[string]string
	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]string) 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 Ledger

type Ledger struct {
	sync.Mutex
	Blockchain Blockchain
	// 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(s map[string]string)

Add data to the blockchain

func (*Ledger) ExistsValue

func (l *Ledger) ExistsValue(v string) (exists bool)

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

func (*Ledger) GetKey

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

GetKey retrieve the current key from the blockchain

func (*Ledger) Persist

func (l *Ledger) Persist(ctx context.Context, t time.Duration, key string, async func() string)

Persist an 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) 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