Documentation ¶
Index ¶
- Constants
- func DBExists(path string) bool
- func Handle(err error)
- func ToHex(num int64) []byte
- type Block
- type BlockChain
- func (chain *BlockChain) AddBlock(block *Block)
- func (chain *BlockChain) FindSpendableOutputs(pubKeyHash []byte, amount int) (int, map[string][]int)
- func (chain *BlockChain) FindTransaction(ID []byte) (Transaction, error)
- func (chain *BlockChain) FindUTXO() map[string]TxOutputs
- func (chain *BlockChain) FindUnspentTransactions(pubKeyHash []byte) []Transaction
- func (chain *BlockChain) GetBestHeight() int
- func (chain *BlockChain) GetBlock(blockHash []byte) (Block, error)
- func (chain *BlockChain) GetBlockHashes() [][]byte
- func (chain *BlockChain) Iterator() *ChainIterator
- func (chain *BlockChain) MineBlock(transactions []*Transaction) *Block
- func (chain *BlockChain) SignTransaction(tx *Transaction, privateKey ecdsa.PrivateKey)
- func (chain *BlockChain) VerifyTransaction(tx *Transaction) bool
- type ChainIterator
- type MerkleNode
- type MerkleTree
- type ProofOfWork
- type Transaction
- func (tx *Transaction) Hash() []byte
- func (tx *Transaction) IsCoinbase() bool
- func (tx Transaction) Serialize() []byte
- func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTXs map[string]Transaction)
- func (tx Transaction) String() string
- func (tx *Transaction) TrimmedCopy() Transaction
- func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool
- type TxInput
- type TxOutput
- type TxOutputs
- type UTXOSet
- func (u UTXOSet) CountTransactions() int
- func (u *UTXOSet) DeleteByPrefix(prefix []byte)
- func (u UTXOSet) FindSpendableOutputs(pubKeyHash []byte, amount int) (int, map[string][]int)
- func (u UTXOSet) FindUTXO(pubKeyHash []byte) []TxOutput
- func (u UTXOSet) FindUnspentTransactions(pubKeyHash []byte) []TxOutput
- func (u UTXOSet) Reindex()
- func (u *UTXOSet) Update(block *Block)
Constants ¶
View Source
const Difficulty = 12
PoW difficulty
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct { Timestamp int64 Hash []byte Transactions []*Transaction PrevHash []byte Nonce int Height int }
func CreateBlock ¶
func CreateBlock(txs []*Transaction, prevHash []byte, height int) *Block
func Deserialize ¶
func Genesis ¶
func Genesis(coinbase *Transaction) *Block
func (*Block) HashTransactions ¶
type BlockChain ¶
func ContinueBlockChain ¶
func ContinueBlockChain(nodeId string) *BlockChain
func InitBlockChain ¶
func InitBlockChain(address, nodeId string) *BlockChain
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(block *Block)
func (*BlockChain) FindSpendableOutputs ¶
func (*BlockChain) FindTransaction ¶
func (chain *BlockChain) FindTransaction(ID []byte) (Transaction, error)
func (*BlockChain) FindUTXO ¶
func (chain *BlockChain) FindUTXO() map[string]TxOutputs
Finds unspent transaction outputs Unspent means that these outputs were not referenced in any inputs
func (*BlockChain) FindUnspentTransactions ¶
func (chain *BlockChain) FindUnspentTransactions(pubKeyHash []byte) []Transaction
func (*BlockChain) GetBestHeight ¶
func (chain *BlockChain) GetBestHeight() int
func (*BlockChain) GetBlockHashes ¶
func (chain *BlockChain) GetBlockHashes() [][]byte
func (*BlockChain) Iterator ¶
func (chain *BlockChain) Iterator() *ChainIterator
func (*BlockChain) MineBlock ¶
func (chain *BlockChain) MineBlock(transactions []*Transaction) *Block
func (*BlockChain) SignTransaction ¶
func (chain *BlockChain) SignTransaction(tx *Transaction, privateKey ecdsa.PrivateKey)
func (*BlockChain) VerifyTransaction ¶
func (chain *BlockChain) VerifyTransaction(tx *Transaction) bool
type ChainIterator ¶
func (*ChainIterator) Next ¶
func (iter *ChainIterator) Next() *Block
type MerkleNode ¶
type MerkleNode struct { Left *MerkleNode Right *MerkleNode Data []byte }
func NewMerkleNode ¶
func NewMerkleNode(left, right *MerkleNode, data []byte) *MerkleNode
type MerkleTree ¶
type MerkleTree struct {
RootNode *MerkleNode
}
func NewMerkleTree ¶
func NewMerkleTree(data [][]byte) *MerkleTree
type ProofOfWork ¶
Represents proof of work
func (*ProofOfWork) InitData ¶
func (pow *ProofOfWork) InitData(nonce int) []byte
func (*ProofOfWork) Run ¶
func (pow *ProofOfWork) Run() (int, []byte)
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() bool
type Transaction ¶
func CoinbaseTx ¶
func CoinbaseTx(to, data string) *Transaction
func DeserializeTransaction ¶
func DeserializeTransaction(data []byte) Transaction
func NewTransaction ¶
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() []byte
func (*Transaction) IsCoinbase ¶
func (tx *Transaction) IsCoinbase() bool
func (Transaction) Serialize ¶
func (tx Transaction) Serialize() []byte
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTXs map[string]Transaction)
func (Transaction) String ¶
func (tx Transaction) String() string
func (*Transaction) TrimmedCopy ¶
func (tx *Transaction) TrimmedCopy() Transaction
func (*Transaction) Verify ¶
func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool
type UTXOSet ¶
type UTXOSet struct {
BlockChain *BlockChain
}
func (UTXOSet) CountTransactions ¶
func (*UTXOSet) DeleteByPrefix ¶
func (UTXOSet) FindSpendableOutputs ¶
func (UTXOSet) FindUnspentTransactions ¶
Click to show internal directories.
Click to hide internal directories.