Documentation ¶
Index ¶
- Constants
- func ToHex(num int64) []byte
- type Block
- type BlockChain
- func (chain *BlockChain) AddBlock(block *Block)
- 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() *BlockChainIterator
- func (chain *BlockChain) MineBlock(transactions []Transaction) Block
- func (chain *BlockChain) SignTransaction(tx Transaction, privKey ecdsa.PrivateKey)
- func (chain *BlockChain) VerifyTransaction(tx Transaction) bool
- type BlockChainIterator
- type MerkleNode
- type MerkleTree
- type ProofOfWork
- type Transaction
- func (tx *Transaction) Deserialize(buffer []byte) error
- func (tx *Transaction) Hash() []byte
- func (tx *Transaction) IsCoinbase() bool
- func (tx *Transaction) Serialize() []byte
- func (tx *Transaction) SetID()
- func (tx *Transaction) Sign(privKey *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) FindUnspentTransactions(pubKeyHash []byte) []TxOutput
- func (u *UTXOSet) Reindex()
- func (u *UTXOSet) Update(block Block)
Constants ¶
View Source
const Difficulty = 14
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct { Timestamp int64 Hash []byte `json:"hash,omitempty"` Transactions []Transaction `json:"transactions,omitempty"` PrevHash []byte `json:"prev_hash,omitempty"` Nonce int Height int }
func Genesis ¶
func Genesis(coinbase Transaction) Block
func (Block) Deserialize ¶
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) FindTransaction ¶
func (chain *BlockChain) FindTransaction(ID []byte) (Transaction, error)
func (*BlockChain) FindUTXO ¶
func (chain *BlockChain) FindUTXO() map[string]TxOutputs
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() *BlockChainIterator
func (*BlockChain) MineBlock ¶
func (chain *BlockChain) MineBlock(transactions []Transaction) Block
func (*BlockChain) SignTransaction ¶
func (chain *BlockChain) SignTransaction(tx Transaction, privKey ecdsa.PrivateKey)
func (*BlockChain) VerifyTransaction ¶
func (chain *BlockChain) VerifyTransaction(tx Transaction) bool
type BlockChainIterator ¶
func (*BlockChainIterator) Next ¶
func (iter *BlockChainIterator) 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 ¶
func NewProof ¶
func NewProof(b Block) *ProofOfWork
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 ¶
type Transaction struct { ID []byte `json:"id,omitempty"` Inputs []TxInput `json:"tx_input,omitempty"` Outputs []TxOutput `json:"tx_output,omitempty"` }
func CoinbaseTx ¶
func CoinbaseTx(to, data string) Transaction
func NewTransaction ¶
func (*Transaction) Deserialize ¶
func (tx *Transaction) Deserialize(buffer []byte) error
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) SetID ¶
func (tx *Transaction) SetID()
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(privKey *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 TxInput ¶
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.