Documentation ¶
Index ¶
- Constants
- Variables
- func NewBlockchainChainError(errorCode int, err error) error
- type Block
- type Chain
- func (c *Chain) AddBlock(block Block) error
- func (c *Chain) GetBlock(blockNum int) Block
- func (c *Chain) MineBlock(payload string)
- func (c *Chain) Print()
- func (c *Chain) ValidateBlock(blockNum int) error
- func (c *Chain) ValidateChain() (int, error)
- func (c *Chain) ValidateNewBlock(block Block) error
- type Peer
- func (p *Peer) AddBlock(block Block) error
- func (p *Peer) AddPeer(peer *Peer) error
- func (p *Peer) BroadcastBlock(block Block)
- func (p *Peer) DeletePeerByID(id uint8)
- func (p *Peer) GetBlock(blockNum int) Block
- func (p *Peer) GetChain() *Chain
- func (p *Peer) GetChainLen() int
- func (p *Peer) MineBlock(payload string)
- func (p *Peer) Sync() error
Constants ¶
View Source
const ( GENESIS_BLOCK_NUMBER = 0 GENESIS_BLOCK_PREV_HASH = "0" GENESIS_BLOCK_PAYLOAD = "genesis" // pre-calculated genesis block hash GENESIS_BLOCK_HASH = "e2a1f4f34d6d2ade6eaf221683ee2bcf1c579ca640310954c2e0f0e3457783c3" )
magic hardcoded genesis block values
View Source
const ( UnknownError = -1 // block errors WrongBlockNumberError = iota NegativeBlockNumberError ExcitingBlockNumberError WrongPrevBlockHashError WrongBlockHashError EmptyBlockHashError BlockValidationError ChainValidationError EmptyChainError MineBlockError PeerSyncError AddBlockError )
Variables ¶
View Source
var ErrorMessages = map[int]string{ UnknownError: "unkown error", WrongBlockNumberError: "wrong block number", NegativeBlockNumberError: "negative block number", ExcitingBlockNumberError: "block number exceeds chain lenght", WrongPrevBlockHashError: "wrong previous block hash", WrongBlockHashError: "wrong block hash", EmptyBlockHashError: "block hash is empty", BlockValidationError: "block validation error", ChainValidationError: "chain validation error", EmptyChainError: "chain is empty", MineBlockError: "cannot mine block", PeerSyncError: "cannot synchronize to chain", AddBlockError: "cannot add block to chain", }
Functions ¶
func NewBlockchainChainError ¶
Types ¶
type Block ¶
func GetGenesisBlock ¶
func GetGenesisBlock() Block
type Chain ¶
func (*Chain) ValidateBlock ¶
func (*Chain) ValidateChain ¶
func (*Chain) ValidateNewBlock ¶
Click to show internal directories.
Click to hide internal directories.