Documentation ¶
Index ¶
- Constants
- func NewUnspentTxs(from, to string, amount int, bc *Blockchain) *transaction.Transaction
- type Blockchain
- func (bc *Blockchain) FindSpendableTxOutputs(address string, amount int) (map[string][]int, int)
- func (bc *Blockchain) FindUnspentTransactionOutputs(address string) []transaction.TXOutput
- func (bc *Blockchain) FindUnspentTransactions(address string) []transaction.Transaction
- func (bc *Blockchain) Iterator() *BlockchainIterator
- func (bc *Blockchain) MineBlock(tx []*transaction.Transaction)
- type BlockchainIterator
Constants ¶
const BlocksBucket = "blocksBucket"
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 ¶
func CreateBlockchain ¶
func CreateBlockchain(address string) *Blockchain
func (*Blockchain) FindSpendableTxOutputs ¶
* 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 ¶
func (*BlockchainIterator) Previous ¶
func (bcI *BlockchainIterator) Previous() *block.Block
* Get the hash of the Prev block