yggdrasill

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Yggdrasill Build Status

Yggdrasill is a block storage(Blockchain) library that supports custom blocks and transactions. Define the custom block struct you want! If you implement a block interface, any struct of block can be easily verified and stored in a Block storage(Blockchain).

Implementation Detail

Document (Korean)

Usage

DefaultTransaction
paramType := 1
funcName := "InvokeThisFunction"
args := make([]string, 0)

// Define parameters
params := NewParams(paramType, funcName, args)

jsonrpc := "jsonrpc"
txDataType := Invoke // constant for TxDataType
contractID := "contractID01"

// Define TxData
txData := NewTxData(jsonrpc, txDataType, params, constractID)

senderID := "peerID01"
txID := "transactionID01"
time := time.Now()

// Define new DefaultTransaction
tx := NewDefaultTransaction(senderID, txID, time, txData)
DefaultBlock
prevBlockSeal := []byte{...}
height := 0
blockCreatorID := "hero"

// Define new empty block
block := NewEmptyBlock(prevBlockSeal, height, blockCreatorID)

// Get a validator
v := &validator.DefaultValidator{}

// Get a transaction list, which will be stored in the block
txList := []transaction.Transaction{...}

// Then, build a seal for a transaction list
txListSeal, _ := v.BuildTxSeal(txList)

// Set timestamp
block.SetTimestamp(time.Now)

// At last, build a seal for the block.
// It should be the last because the seal will be different if the contents of the block are changed.
blockSeal, _ := v.BuildSeal(block)
block.SetSeal(blockSeal)
DefaultValidator
v := &validator.DefaultValidator{}
Yggdrasill
// Get a validator
var validator common.Validator
validator = new(impl.DefaultValidator)

// Get a db
dbPath := "./.db"
db := leveldbwrapper.CreateNewDB(dbPath)

// Build a yggdrasill object
y, err := NewYggdrasill(db, validator, nil)

Lincese

Yggdrasill source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRequiredParameters = errors.New("required parameters not passed")
View Source
var ErrNoValidator = errors.New("validator not defined")
View Source
var ErrPrevSealMismatch = errors.New("PrevSeal value mismatch")
View Source
var ErrSealValidation = errors.New("seal validation failed")
View Source
var ErrTxSealValidation = errors.New("txSeal validation failed")

Functions

This section is empty.

Types

type BlockStorage

type BlockStorage struct {
	DBProvider *DBProvider
	// contains filtered or unexported fields
}

func NewBlockStorage

func NewBlockStorage(keyValueDB key_value_db.KeyValueDB, validator common.Validator, opts map[string]interface{}) (*BlockStorage, error)

NewBlockStorage 함수는 새로운 BlockStorage 객체를 생성한다. keyValueDB와 validator는 필수이며, opts는 현재 지원되지 않는다.

func (*BlockStorage) AddBlock

func (y *BlockStorage) AddBlock(block common.Block) error

AddBlock 함수는 새로운 Block을 Yggdrasill의 DB에 저장한다. 저장하기 전에 validator로 Block을 검증한다.

func (*BlockStorage) Close

func (y *BlockStorage) Close()

Close 함수는 BlockStorage 객체의 DB를 닫는다.

func (*BlockStorage) GetBlockByHeight

func (y *BlockStorage) GetBlockByHeight(block common.Block, height uint64) error

GetBlockByHeight 함수는 BlockStorage 객체에 저장된 Block을 height 값으로 찾아 반환한다.

func (*BlockStorage) GetBlockBySeal

func (y *BlockStorage) GetBlockBySeal(block common.Block, seal []byte) error

GetBlockBySeal 함수는 BlockStorage 객체에 저장된 Block을 seal 값으로 찾아 반환한다.

func (*BlockStorage) GetBlockByTxID

func (y *BlockStorage) GetBlockByTxID(block common.Block, txID string) error

GetBlockByTxID 함수는 BlockStorage 객체에 저장된 Block을 Transaction의 ID 값으로 찾아 반환한다.

func (*BlockStorage) GetLastBlock

func (y *BlockStorage) GetLastBlock(block common.Block) error

GetLastBlock 함수는 BlockStorage 객체에 저장된 마지막 block을 반환한다.

func (*BlockStorage) GetTransactionByTxID

func (y *BlockStorage) GetTransactionByTxID(transaction common.Transaction, txID string) error

GetTransactionByTxID 함수는 BlockStorage 객체에 저장된 Block 안에 저장된 Transaction을 ID 값으로 찾아 반환한다.

func (*BlockStorage) GetValidator

func (y *BlockStorage) GetValidator() common.Validator

type BlockStorageManager

type BlockStorageManager interface {
	Close()
	GetValidator() common.Validator
	AddBlock(block common.Block) error
	GetBlockByHeight(block common.Block, height uint64) error
	GetBlockBySeal(block common.Block, seal []byte) error
	GetBlockByTxID(block common.Block, txid string) error
	GetLastBlock(block common.Block) error
	GetTransactionByTxID(transaction common.Transaction, txid string) error
}

type DBHandle

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

func (*DBHandle) Delete

func (h *DBHandle) Delete(key []byte, sync bool) error

func (*DBHandle) Get

func (h *DBHandle) Get(key []byte) ([]byte, error)

func (*DBHandle) GetIteratorWithPrefix

func (h *DBHandle) GetIteratorWithPrefix() key_value_db.KeyValueDBIterator

func (*DBHandle) Put

func (h *DBHandle) Put(key []byte, value []byte, sync bool) error

func (*DBHandle) Snapshot

func (h *DBHandle) Snapshot() (map[string][]byte, error)

func (*DBHandle) WriteBatch

func (h *DBHandle) WriteBatch(KVs map[string][]byte, sync bool) error

type DBProvider

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

func CreateNewDBProvider

func CreateNewDBProvider(keyValueDB key_value_db.KeyValueDB) *DBProvider

func (*DBProvider) Close

func (p *DBProvider) Close()

func (*DBProvider) GetDBHandle

func (p *DBProvider) GetDBHandle(dbName string) *DBHandle

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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