validating

package
v0.0.0-...-e59846b Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotGetOutputBytes = errors.New("Cannot obtain output bytes")

ErrCannotGetOutputBytes indicates error obtaining output bytes

View Source
var ErrDuplicateTransaction = errors.New("Duplicate transaction in same block")

ErrDuplicateTransaction indicates when the sender has duplicate transactions in same block

View Source
var ErrInvalidInputBalance = errors.New("Invalid input balance")

ErrInvalidInputBalance indicates when the sender has invalid input balance

View Source
var ErrInvalidMinerRewardAmount = errors.New("Miner reward amount is invalid")

ErrInvalidMinerRewardAmount indicates when miner reward tx amount is not same as config

View Source
var ErrInvalidOutputTotalBalance = errors.New("Output has invalid total balance")

ErrInvalidOutputTotalBalance invalid output total balance compared with input amount

View Source
var ErrInvalidPubKey = errors.New("Invalid public key")

ErrInvalidPubKey invalid public key

View Source
var ErrInvalidSignature = errors.New("Signature is invalid")

ErrInvalidSignature invalid signature

View Source
var ErrMinerRewardExceedsLimit = errors.New("Miner reward exceeds limit")

ErrMinerRewardExceedsLimit indicates when miner reward is more than 1

Functions

func IsValidTransaction

func IsValidTransaction(tx Transaction) (bool, error)

IsValidTransaction returns true if transaction itself contains valid input and output information

Types

type Block

type Block struct {
	Timestamp  int64         `json:"timestamp"`
	LastHash   *string       `json:"lastHash"`
	Hash       *string       `json:"hash"`
	Data       []Transaction `json:"data"`
	Nonce      uint32        `json:"nonce"`
	Difficulty uint32        `json:"difficulty"`
}

Block represents a block in blockchain

type Blockchain

type Blockchain struct {
	Chain []Block
}

Blockchain represents a chain of mined blocks

type Input

type Input struct {
	Timestamp int64  `json:"timestamp"`
	Amount    uint64 `json:"amount"`
	Address   string `json:"address"`
	Signature string `json:"sig"`
}

Input of transaction

type MockedListing

type MockedListing struct {
	mock.Mock
}

MockedListing is a mocked object that implememnts listing.Service

func (*MockedListing) GetBlockCount

func (m *MockedListing) GetBlockCount() uint32

GetBlockCount returns the latest block count in blockchain

func (*MockedListing) GetBlockchain

func (m *MockedListing) GetBlockchain() *listing.Blockchain

GetBlockchain returns a list of blocks from genesis block

func (*MockedListing) GetLastBlock

func (m *MockedListing) GetLastBlock() listing.Block

GetLastBlock adds mined block to blockchain

type Service

type Service interface {
	IsValidChain(bc *Blockchain) bool
	ContainsValidTransactions(bc *Blockchain) (bool, error)
}

Service provides blockchain validating operations

func NewService

func NewService(l listing.Service, c calculating.Service, rewardInputAddress string, reward uint64) Service

NewService creates a validating service with necessary dependencies

type Transaction

type Transaction struct {
	ID     string            `json:"id"`
	Input  Input             `json:"input"`
	Output map[string]uint64 `json:"output"`
}

Transaction in data

Jump to

Keyboard shortcuts

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