blockchain

package
v0.0.0-...-31eb2eb Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const BlocksBucket = "blocksBucket"
View Source
const LeafKey = "l"

Variables

This section is empty.

Functions

func NewUnspentTxs

func NewUnspentTxs(from, to string, amount int, bc *Blockchain) *transaction.Transaction

* Generate Inputs, Output (change if neccessary) * Inputs: * * Get "spendable" outputs * * Generate inputs using TxId * * For now outputs are just indexes * * ScriptSig -> from

Types

type Blockchain

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

func CreateBlockchain

func CreateBlockchain(address string) *Blockchain

func NewBlockchain

func NewBlockchain() *Blockchain

* @TODO: check if address required as a param

func (*Blockchain) FindSpendableTxOutputs

func (bc *Blockchain) FindSpendableTxOutputs(address string, amount int) (map[string][]int, int)

* amount required for the current transaction * @returns spendable outputs, accumulatedAmount

func (*Blockchain) FindUnspentTransactionOutputs

func (bc *Blockchain) FindUnspentTransactionOutputs(address string) []transaction.TXOutput

* Find unspent transaction outputs utilizes the above function to return only * outputs, which will make finding balances easier

func (*Blockchain) FindUnspentTransactions

func (bc *Blockchain) FindUnspentTransactions(address string) []transaction.Transaction

* Parse through each block in blockchain * Within the block parse through each transaction * If tx is not coinbase tx * Parse through TXInput's: * - If input has same address as the func param * * Append to array in map with current txId as key * * This will be used to check if output is unspent later * * * Parse through TXOutput's: * - If current tx has unspent outputs * * Check if output is spent, using the map from above * * If yes continue to next output * * * If the output can now be unlocked with address, append to * unspent tx's * * If all blocks have been traversed, break * * Return any unspent transactions *

func (*Blockchain) Iterator

func (bc *Blockchain) Iterator() *BlockchainIterator

* Initially currentHash will be the tip of the blockchain

func (*Blockchain) MineBlock

func (bc *Blockchain) MineBlock(tx []*transaction.Transaction)

type BlockchainIterator

type BlockchainIterator struct {
	CurrentHash []byte
	Db          *bolt.DB
}

func (*BlockchainIterator) Previous

func (bcI *BlockchainIterator) Previous() *block.Block

* Get the hash of the Prev block

Jump to

Keyboard shortcuts

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