blockchain

package
v0.0.0-...-75fa6d2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: GPL-3.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockSavedHook func(block *Block) = nil

Functions

func RegisterStorage

func RegisterStorage(s Storage)

func ResetChainCache

func ResetChainCache()

Types

type Block

type Block struct {
	Height    uint64 `json:"height"`
	Time      uint64 `json:"time"`
	PrevHash  string `json:"prev_hash"`
	Hash      string `json:"hash"`
	Signature string `json:"signature"`
	Payload   []byte `json:"payload"`
	// contains filtered or unexported fields
}

func DeserializeBlock

func DeserializeBlock(message json.RawMessage) (*Block, error)

func (Block) ChainID

func (b Block) ChainID() string

TODO: store result to reduce calculations

func (Block) DataForHashing

func (b Block) DataForHashing() []byte

Create a byte array for hashing height + time + prev_hash + payload int value should be converted to string literally hash string should be converted to string with base58 decoding TODO: store result to reduce calculations

func (Block) Serialize

func (b Block) Serialize() []byte

func (Block) Size

func (b Block) Size() int

func (Block) String

func (b Block) String() string

func (*Block) Validate

func (b *Block) Validate() BlockValidationError

TODO: store result to reduce calculations

type BlockValidationError

type BlockValidationError interface {
	Code() string
	Error() string
}

type Chain

type Chain struct {
	ID    string
	Count uint64

	Ref int64
	// contains filtered or unexported fields
}

func CreateChain

func CreateChain(payload []byte) *Chain

Create a chain object with genesis block payload

func LoadAllChains

func LoadAllChains() []*Chain

func LoadChain

func LoadChain(id string) *Chain

func NewOwnedChain

func NewOwnedChain(wif string) *Chain

func NewReadonlyChain

func NewReadonlyChain(id string) *Chain

func (*Chain) CacheBlock

func (c *Chain) CacheBlock(block *Block) BlockValidationError

func (*Chain) CommitCache

func (c *Chain) CommitCache()

func (Chain) CreateBlock

func (c Chain) CreateBlock(payload []byte) *Block

func (Chain) GetBlock

func (c Chain) GetBlock(height uint64) *Block

func (Chain) GetBlocks

func (c Chain) GetBlocks(from uint64, to uint64) []*Block

func (Chain) IsOwner

func (c Chain) IsOwner() bool

func (*Chain) SaveBlock

func (c *Chain) SaveBlock(block *Block) bool

func (*Chain) Sync

func (c *Chain) Sync()

func (Chain) ValidateBlock

func (c Chain) ValidateBlock(block *Block) BlockValidationError

TODO: may need to cache database query result

func (Chain) WIF

func (c Chain) WIF() string

type DangledBlockError

type DangledBlockError struct {
	// contains filtered or unexported fields
}

func (DangledBlockError) Code

func (e DangledBlockError) Code() string

func (DangledBlockError) Error

func (e DangledBlockError) Error() string

type ExistBlockError

type ExistBlockError struct {
	// contains filtered or unexported fields
}

func (ExistBlockError) Code

func (e ExistBlockError) Code() string

func (ExistBlockError) Error

func (e ExistBlockError) Error() string

type ForkError

type ForkError struct {
	// contains filtered or unexported fields
}

func (ForkError) Code

func (e ForkError) Code() string

func (ForkError) Error

func (e ForkError) Error() string

type InvalidBlockError

type InvalidBlockError struct {
	// contains filtered or unexported fields
}

func (InvalidBlockError) Code

func (e InvalidBlockError) Code() string

func (InvalidBlockError) Error

func (e InvalidBlockError) Error() string

type MismatchedIDError

type MismatchedIDError struct {
	// contains filtered or unexported fields
}

func (MismatchedIDError) Code

func (e MismatchedIDError) Code() string

func (MismatchedIDError) Error

func (e MismatchedIDError) Error() string

type Storage

type Storage interface {
	GetChain(chainID string, ref *int64, wif *string, count *uint64) bool
	GetAllChains(func(ref int64, id string, wif string, count uint64))
	GetBlock(id int64, height uint64) *Block
	GetBlockByHash(id int64, hash string) *Block
	GetBlocks(id int64, from uint64, to uint64) []*Block
	SaveChain(chain *Chain) error
	IncreaseCount(chain *Chain)
	SaveBlock(id int64, block *Block)
	CleanChain(chain *Chain)
}

func SharedStorage

func SharedStorage() Storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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