Documentation ¶
Index ¶
- func NewUTXOTransaction(from, to string, amount int, UTXOSet *UTXOSet) *txs.Transaction
- type Block
- type Blockchain
- func (bc *Blockchain) FindTransaction(ID []byte) (txs.Transaction, error)
- func (bc *Blockchain) FindUTXO() map[string]txs.TXOutputs
- func (bc *Blockchain) Iterator() *BlockchainIterator
- func (bc *Blockchain) MineBlock(transactions []*txs.Transaction) *Block
- func (bc *Blockchain) SignTransaction(tx *txs.Transaction, privKey ecdsa.PrivateKey)
- func (bc *Blockchain) VerifyTransaction(tx *txs.Transaction) bool
- type BlockchainIterator
- type ProofOfWork
- type UTXOSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewUTXOTransaction ¶
func NewUTXOTransaction(from, to string, amount int, UTXOSet *UTXOSet) *txs.Transaction
NewUTXOTransaction creates a new transaction
Types ¶
type Block ¶
type Block struct { Timestamp int64 Transactions []*txs.Transaction PrevBlockHash []byte Hash []byte Nonce int }
Block represents a block in the blockchain
func DeserializeBlock ¶
DeserializeBlock deserializes a block
func NewBlock ¶
func NewBlock(transactions []*txs.Transaction, prevBlockHash []byte) *Block
NewBlock creates and returns Block
func NewGenesisBlock ¶
func NewGenesisBlock(coinbase *txs.Transaction) *Block
NewGenesisBlock creates and returns genesis Block
func (*Block) HashTransactions ¶
HashTransactions returns a hash of the transactions in the block
type Blockchain ¶
Blockchain implements interactions with a DB
func CreateBlockchain ¶
func CreateBlockchain(address string) *Blockchain
CreateBlockchain creates a new blockchain DB
func NewBlockchain ¶
func NewBlockchain() *Blockchain
NewBlockchain creates a new Blockchain with genesis Block
func (*Blockchain) FindTransaction ¶
func (bc *Blockchain) FindTransaction(ID []byte) (txs.Transaction, error)
FindTransaction finds a transaction by its ID
func (*Blockchain) FindUTXO ¶
func (bc *Blockchain) FindUTXO() map[string]txs.TXOutputs
FindUTXO finds all unspent transaction outputs and returns transactions with spent outputs removed
func (*Blockchain) Iterator ¶
func (bc *Blockchain) Iterator() *BlockchainIterator
Iterator returns a BlockchainIterat
func (*Blockchain) MineBlock ¶
func (bc *Blockchain) MineBlock(transactions []*txs.Transaction) *Block
MineBlock mines a new block with the provided transactions
func (*Blockchain) SignTransaction ¶
func (bc *Blockchain) SignTransaction(tx *txs.Transaction, privKey ecdsa.PrivateKey)
SignTransaction signs inputs of a Transaction
func (*Blockchain) VerifyTransaction ¶
func (bc *Blockchain) VerifyTransaction(tx *txs.Transaction) bool
VerifyTransaction verifies transaction input signatures
type BlockchainIterator ¶
type BlockchainIterator struct {
// contains filtered or unexported fields
}
BlockchainIterator is used to iterate over blockchain blocks
func (*BlockchainIterator) Next ¶
func (i *BlockchainIterator) Next() *Block
Next returns next block starting from the tip
type ProofOfWork ¶
type ProofOfWork struct {
// contains filtered or unexported fields
}
ProofOfWork represents a proof-of-work
func NewProofOfWork ¶
func NewProofOfWork(b *Block) *ProofOfWork
NewProofOfWork builds and returns a ProofOfWork
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() bool
Validate validates block's PoW
type UTXOSet ¶
type UTXOSet struct {
Blockchain *Blockchain
}
UTXOSet represents UTXO set
func (UTXOSet) CountTransactions ¶
CountTransactions returns the number of transactions in the UTXO set
func (UTXOSet) FindSpendableOutputs ¶
FindSpendableOutputs finds and returns unspent outputs to reference in inputs