Documentation ¶
Index ¶
- Constants
- func DBexists() bool
- func Handle(err error)
- type Block
- type BlockChain
- func (chain *BlockChain) AddBlock(transactions []*Transaction)
- func (chain *BlockChain) FindSpendableOutputs(address string, amount int) (int, map[string][]int)
- func (chain *BlockChain) FindTransactions(address string) []Transaction
- func (chain *BlockChain) FindUTXO(address string) []TxOutput
- func (chain *BlockChain) FindUnspentTransactions(address string) []Transaction
- func (chain *BlockChain) Iterator() *BlockChainIterator
- type BlockChainIterator
- type ProofOfWork
- type Transaction
- type TxInput
- type TxOutput
Constants ¶
const Difference = 12 // Possbile TODO: Change this constant to a dynamic algorithim
The Greater the Difference in the algorithm, the harder the work will be to compute
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct { Hash []byte Transactions []*Transaction PrevHash []byte Nonce int }
Block is a single unit in the blockchain
func CreateBlock ¶
func CreateBlock(txs []*Transaction, prevHash []byte) *Block
CreateBlock will create a new block, but not add it to the chain
func Deserialize ¶
func Genesis ¶
func Genesis(coinbase *Transaction) *Block
Genesis needs to be the first block in a chain, as the first block doesn't have an address to point back to
func (*Block) HashTransactions ¶
type BlockChain ¶
BlockChain is an array of block pointers
func ContinueBlockChain ¶
func ContinueBlockChain(address string) *BlockChain
ContinueBlockChain will be called to append to an existing blockchain
func InitBlockChain ¶
func InitBlockChain(address string) *BlockChain
InitBlockChain will be what starts a new blockChain
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(transactions []*Transaction)
AddBlock Will add a Block type unit to a blockchain
func (*BlockChain) FindSpendableOutputs ¶
func (*BlockChain) FindTransactions ¶
func (chain *BlockChain) FindTransactions(address string) []Transaction
func (*BlockChain) FindUTXO ¶
func (chain *BlockChain) FindUTXO(address string) []TxOutput
func (*BlockChain) FindUnspentTransactions ¶
func (chain *BlockChain) FindUnspentTransactions(address string) []Transaction
func (*BlockChain) Iterator ¶
func (chain *BlockChain) Iterator() *BlockChainIterator
Iterator takes our BlockChain struct and returns it as a BlockCHainIterator struct
type BlockChainIterator ¶
func (*BlockChainIterator) Next ¶
func (iterator *BlockChainIterator) Next() *Block
Next will iterate through the BlockChainIterator
type ProofOfWork ¶
func NewProofOfWork ¶
func NewProofOfWork(b *Block) *ProofOfWork
func (*ProofOfWork) InitData ¶
func (pow *ProofOfWork) InitData(nonce int) []byte
InitData takes your block and adds a nonce (counter/incrementer) to it.
func (*ProofOfWork) Run ¶
func (pow *ProofOfWork) Run() (int, []byte)
Run will hash our data, turn that hash into a big int, and then compare that big int to our Target which is inside the Proof Of Work Struct
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() bool
Validate will check our Run() function performed as expected
type Transaction ¶
func CoinbaseTx ¶
func CoinbaseTx(toAddress, data string) *Transaction
CoinbaseTx is the function that will run when someone on a node succesfully "mines" a block. The reward inside as it were.
func NewTransaction ¶
func NewTransaction(from, to string, amount int, chain *BlockChain) *Transaction
func (*Transaction) IsCoinbase ¶
func (tx *Transaction) IsCoinbase() bool
func (*Transaction) SetID ¶
func (tx *Transaction) SetID()
TxOutput represents a transaction in the blockchain For Example, I sent you 5 coins. Value would == 5, and it would have my unique PubKey
type TxInput ¶
type TxInput struct { ID []byte //ID will find the Transaction that a specific output is inside of Out int //Out will be the index of the specific output we found within a transaction. //For example if a transaction has 4 outputs, we can use this "out" field to specify which output we are looking for Sig string }
TxInput is represntative of a reference to a previous TxOutput