validation

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Examples

Constants

View Source
const (
	PERIOD_HOURLY       = time.Hour
	PERIOD_DAILY        = PERIOD_HOURLY * 24
	PERIOD_WEEKLY       = PERIOD_HOURLY * 168    // (24 * 7)
	PERIOD_YEARLY       = PERIOD_HOURLY * 8766   // (24 * 365.25)
	PERIOD_DECENNIALLY  = PERIOD_HOURLY * 87660  // (24 * 365.25 * 10)
	PERIOD_CENTENNIALLY = PERIOD_HOURLY * 876600 // (24 * 365.25 * 100)

	THRESHOLD_PERIOD_HOUR    = bcgo.THRESHOLD_F
	THRESHOLD_PERIOD_DAY     = bcgo.THRESHOLD_E
	THRESHOLD_PERIOD_WEEK    = bcgo.THRESHOLD_D
	THRESHOLD_PERIOD_YEAR    = bcgo.THRESHOLD_C
	THRESHOLD_PERIOD_DECADE  = bcgo.THRESHOLD_B
	THRESHOLD_PERIOD_CENTURY = bcgo.THRESHOLD_A
)

Variables

This section is empty.

Functions

func CreateValidationBlock

func CreateValidationBlock(timestamp uint64, channel, alias string, head []byte, block *bcgo.Block, entries []*bcgo.BlockEntry) *bcgo.Block

func CreateValidationEntries

func CreateValidationEntries(timestamp uint64, node bcgo.Node, channels map[string]bool) ([]*bcgo.BlockEntry, error)

func CreateValidationEntry

func CreateValidationEntry(timestamp uint64, node bcgo.Node, channel string, updated uint64, head []byte) (*bcgo.BlockEntry, error)

Types

type ErrDifferentLiveFlag added in v1.2.1

type ErrDifferentLiveFlag struct {
	Expected, Actual string
}

ErrDifferentLiveFlag is returned when a block's live flag doesn't match the current setting.

func (ErrDifferentLiveFlag) Error added in v1.2.1

func (e ErrDifferentLiveFlag) Error() string

type ErrDuplicateBlock added in v1.2.1

type ErrDuplicateBlock struct {
	Hash string
}

ErrDuplicateBlock is returned when a block appears multiple times in a chain.

func (ErrDuplicateBlock) Error added in v1.2.1

func (e ErrDuplicateBlock) Error() string

type ErrDuplicateEntry added in v1.2.1

type ErrDuplicateEntry struct {
	Hash string
}

ErrDuplicateEntry is returned when an entry appears multiple times in a chain.

func (ErrDuplicateEntry) Error added in v1.2.1

func (e ErrDuplicateEntry) Error() string

type ErrHashTooWeak added in v1.2.1

type ErrHashTooWeak struct {
	Expected, Actual uint64
}

ErrHashTooWeak is returned when a block's hash doesn't meet the threshold.

func (ErrHashTooWeak) Error added in v1.2.1

func (e ErrHashTooWeak) Error() string

type ErrMissingValidatedBlock added in v1.2.1

type ErrMissingValidatedBlock struct {
	PVC, Channel string
	Missing      []string
}

ErrMissingValidatedBlock is returned when a chain doesn't contain a block recorded in periodic validation chain.

func (ErrMissingValidatedBlock) Error added in v1.2.1

func (e ErrMissingValidatedBlock) Error() string

type Live

type Live struct {
}

Live is a validator which ensures the Live flag in each Records' Metadata matches the Live environment variable.

func (*Live) Validate

func (v *Live) Validate(channel bcgo.Channel, cache bcgo.Cache, network bcgo.Network, hash []byte, block *bcgo.Block) error

Validate ensures all records have a live flag in their metadata which matches the environment variable.

type Periodic

type Periodic interface {
	bcgo.Validator
	AddChannel(string)
	FillChannelSet(map[string]bool, bcgo.Cache, bcgo.Network) error
	Update(bcgo.Cache, bcgo.Network, uint64) error
	Start()
	Stop()
}

func NewCentennially

func NewCentennially(node bcgo.Node, channel bcgo.Channel, listener bcgo.MiningListener) Periodic

func NewDaily

func NewDaily(node bcgo.Node, channel bcgo.Channel, listener bcgo.MiningListener) Periodic

func NewDecennially

func NewDecennially(node bcgo.Node, channel bcgo.Channel, listener bcgo.MiningListener) Periodic

func NewHourly

func NewHourly(node bcgo.Node, channel bcgo.Channel, listener bcgo.MiningListener) Periodic

func NewPeriodic

func NewPeriodic(node bcgo.Node, channel bcgo.Channel, threshold uint64, listener bcgo.MiningListener, period time.Duration) Periodic

func NewWeekly

func NewWeekly(node bcgo.Node, channel bcgo.Channel, listener bcgo.MiningListener) Periodic

func NewYearly

func NewYearly(node bcgo.Node, channel bcgo.Channel, listener bcgo.MiningListener) Periodic

type PoW

type PoW interface {
	bcgo.Validator
}
Example
package main

import (
	"aletheiaware.com/bcgo"
	"aletheiaware.com/bcgo/cache"
	"aletheiaware.com/bcgo/channel"
	"aletheiaware.com/bcgo/validation"
	"aletheiaware.com/cryptogo"
	"fmt"
	"log"
)

func main() {
	validator := validation.NewPoW(bcgo.THRESHOLD_G)
	channel := channel.New("FooBar")
	channel.AddValidator(validator)
	cache := cache.NewMemory(10)
	block := &bcgo.Block{
		ChannelName: "TEST",
		Length:      1,
	}
	hash, err := cryptogo.HashProtobuf(block)
	if err != nil {
		log.Fatal("Could not hash block:", err)
	}
	fmt.Println(validator.Validate(channel, cache, nil, hash, block))
}
Output:

Hash doesn't meet Proof-of-Work threshold: 288 vs 262

func NewPoW

func NewPoW(threshold uint64) PoW

type Unique

type Unique struct {
}

func (*Unique) Validate

func (v *Unique) Validate(channel bcgo.Channel, cache bcgo.Cache, network bcgo.Network, hash []byte, block *bcgo.Block) error

Jump to

Keyboard shortcuts

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