common

package
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: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDecodingEmptyBlock = errors.New("Empty Block decoding failed")
View Source
var ErrInsufficientFields = errors.New("Previous seal or transaction list seal is not set")
View Source
var ErrTransactionType = errors.New("Wrong transaction type")

Functions

This section is empty.

Types

type Block

type Block interface {
	// Block의 required field setters
	SetSeal(seal []byte)
	SetPrevSeal(prevSeal []byte)
	SetHeight(height uint64)
	PutTx(tx Transaction) error
	SetTxSeal(txSeal [][]byte)
	SetCreator(creator string)
	SetTimestamp(currentTime time.Time)

	// Block의 required field getters
	GetSeal() []byte
	GetPrevSeal() []byte
	GetHeight() uint64
	GetTxList() []Transaction
	GetTxSeal() [][]byte
	GetCreator() string
	GetTimestamp() time.Time

	// Block을 저장을 위한 []byte로 변환 및 재변환
	Serialize() ([]byte, error)
	Deserialize(serializedBlock []byte) error

	// Block 상태 체크 함수
	IsReadyToPublish() bool
	IsPrev(serializedPrevBlock []byte) bool
}

Block 인터페이스는 Block이 기본적으로 가져야 하는 기능들을 정의한다.

type Transaction

type Transaction interface {
	// Transaction의 required field getters
	GetID() string
	GetContent() ([]byte, error)
	GetSignature() []byte

	// Transaction의 required field setters
	CalculateSeal() ([]byte, error)
	SetSignature([]byte)

	// Transaction의 저장을 위한 []byte로 변환 및 재변환
	Serialize() ([]byte, error)
	Deserialize(serializedBytes []byte) error
}

Transaction interface는 Transaction이 공통적으로 가져야 하는 함수들을 정의함.

type Validator

type Validator interface {
	// Seal들을 작성해주는 함수들
	BuildSeal(timeStamp time.Time, prevSeal []byte, txSeal [][]byte, creator string) ([]byte, error)
	BuildTxSeal(txList []Transaction) ([][]byte, error)

	// Seal들을 검증해주는 함수들
	ValidateSeal(seal []byte, comparisonBlock Block) (bool, error)
	ValidateTxSeal(txSeal [][]byte, txList []Transaction) (bool, error)
	ValidateTransaction(txSeal [][]byte, transaction Transaction) (bool, error)
}

Validator 는 Block의 Transaction들이 위변조 되지 않고 처음 작성된대로 저장되었음을 검증해준다. 위변조가 되지 않음을 증명하는 []byte 값을 Seal(인장)이라고 부르며, 흔히 Hash 값이 사용된다. Default 구현체는 Merkle Tree를 기반으로 Seal을 만들고, 검증한다.

Jump to

Keyboard shortcuts

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