Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCannotGetOutputBytes = errors.New("Cannot obtain output bytes")
ErrCannotGetOutputBytes indicates error obtaining output bytes
var ErrDuplicateTransaction = errors.New("Duplicate transaction in same block")
ErrDuplicateTransaction indicates when the sender has duplicate transactions in same block
var ErrInvalidInputBalance = errors.New("Invalid input balance")
ErrInvalidInputBalance indicates when the sender has invalid input balance
var ErrInvalidMinerRewardAmount = errors.New("Miner reward amount is invalid")
ErrInvalidMinerRewardAmount indicates when miner reward tx amount is not same as config
var ErrInvalidOutputTotalBalance = errors.New("Output has invalid total balance")
ErrInvalidOutputTotalBalance invalid output total balance compared with input amount
var ErrInvalidPubKey = errors.New("Invalid public key")
ErrInvalidPubKey invalid public key
var ErrInvalidSignature = errors.New("Signature is invalid")
ErrInvalidSignature invalid signature
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 ¶
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