Documentation ¶
Index ¶
- type Block
- type Blockchain
- func (bc *Blockchain) AddBlock(block *Block)
- func (bc *Blockchain) Close()
- func (bc *Blockchain) FindTransaction(id []byte) (transaction.Transaction, error)
- func (bc *Blockchain) FindUTXO() map[string]transaction.TXOutputs
- func (bc *Blockchain) GetBestHeight() int
- func (bc *Blockchain) GetBlock(blockHash []byte) (Block, error)
- func (bc *Blockchain) GetBlockHashes() [][]byte
- func (bc *Blockchain) GetDB() *bbolt.DB
- func (bc *Blockchain) Iterator() *BlockchainIterator
- func (bc *Blockchain) MineBlock(transactions []*transaction.Transaction) *Block
- func (bc *Blockchain) SignTransaction(tx *transaction.Transaction, privateKey ecdsa.PrivateKey)
- func (bc *Blockchain) VerifyTransaction(tx *transaction.Transaction) bool
- type BlockchainIterator
- type ProofOfWork
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func DeserializeBlock ¶
func NewBlock ¶
func NewBlock(transactions []*transaction.Transaction, prevBlockHash []byte, height int) *Block
NewBlock creates and returns Block
func NewGenesisBlock ¶
func NewGenesisBlock(coinbase *transaction.Transaction) *Block
NewGenesisBlock creates and returns genesis Block
func (*Block) HashTransactions ¶
func (*Block) PrevBlockHash ¶
func (*Block) Transactions ¶
func (b *Block) Transactions() []*transaction.Transaction
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
func CreateBlockchain ¶
func CreateBlockchain(address string, nodeId string) *Blockchain
CreateBlockchain creates a new blockchain DB
func NewBlockchain ¶
func NewBlockchain(nodeId string) *Blockchain
NewBlockchain creates a new Blockchain with genesis Block
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *Block)
AddBlock saves the block into the blockchain
func (*Blockchain) FindTransaction ¶
func (bc *Blockchain) FindTransaction(id []byte) (transaction.Transaction, error)
FindTransaction finds a transaction by its ID
func (*Blockchain) FindUTXO ¶
func (bc *Blockchain) FindUTXO() map[string]transaction.TXOutputs
FindUTXO finds all unspent transaction outputs and returns transactions with spent outputs removed
func (*Blockchain) GetBestHeight ¶
func (bc *Blockchain) GetBestHeight() int
GetBestHeight returns the height of the latest block
func (*Blockchain) GetBlock ¶
func (bc *Blockchain) GetBlock(blockHash []byte) (Block, error)
GetBlock finds a block by its hash and returns it
func (*Blockchain) GetBlockHashes ¶
func (bc *Blockchain) GetBlockHashes() [][]byte
GetBlockHashes returns a list of hashes of all the blocks in the chain
func (*Blockchain) GetDB ¶
func (bc *Blockchain) GetDB() *bbolt.DB
GetDB returns instance of bbolt.DB
func (*Blockchain) Iterator ¶
func (bc *Blockchain) Iterator() *BlockchainIterator
Iterator returns a BlockchainIterator
func (*Blockchain) MineBlock ¶
func (bc *Blockchain) MineBlock(transactions []*transaction.Transaction) *Block
MineBlock mines a new block with the provided transactions
func (*Blockchain) SignTransaction ¶
func (bc *Blockchain) SignTransaction(tx *transaction.Transaction, privateKey ecdsa.PrivateKey)
SignTransaction signs inputs of a Transaction
func (*Blockchain) VerifyTransaction ¶
func (bc *Blockchain) VerifyTransaction(tx *transaction.Transaction) bool
VerifyTransaction verifies transaction input signatures
type BlockchainIterator ¶
type BlockchainIterator struct {
// contains filtered or unexported fields
}
func (*BlockchainIterator) Next ¶
func (i *BlockchainIterator) Next() *Block
type ProofOfWork ¶
type ProofOfWork struct {
// contains filtered or unexported fields
}
ProofOfWork represents a proof-of-work
func NewProofOfWork ¶
func NewProofOfWork(block *Block) *ProofOfWork
NewProofOfWork builds and returns a ProofOfWork
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() bool
Validate validates block's PoW