blockchain

package
v0.0.0-...-5b5caab Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

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

func DeserializeBlock(d []byte) *Block

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

func (b *Block) HashTransactions() []byte

HashTransactions returns a hash of the transactions in the block

func (*Block) Serialize

func (b *Block) Serialize() []byte

Serialize serializes the block

type Blockchain

type Blockchain struct {
	Tip []byte
	Db  *bolt.DB
}

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) Run

func (pow *ProofOfWork) Run() (int, []byte)

Run performs a proof-of-work

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

func (u UTXOSet) CountTransactions() int

CountTransactions returns the number of transactions in the UTXO set

func (UTXOSet) FindSpendableOutputs

func (u UTXOSet) FindSpendableOutputs(pubkeyHash []byte, amount int) (int, map[string][]int)

FindSpendableOutputs finds and returns unspent outputs to reference in inputs

func (UTXOSet) FindUTXO

func (u UTXOSet) FindUTXO(pubKeyHash []byte) []txs.TXOutput

FindUTXO finds UTXO for a public key hash

func (UTXOSet) Reindex

func (u UTXOSet) Reindex()

Reindex rebuilds the UTXO set

func (UTXOSet) Update

func (u UTXOSet) Update(block *Block)

Update updates the UTXO set with transactions from the Block The Block is considered to be the tip of a blockchain

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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