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 (bc *BlockChain) FindTransaction(ID []byte) (Transaction, error)
- func (chain *BlockChain) FindUTXO() map[string]TxOutputs
- 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 (bc *BlockChain) SignTransaction(tx *Transaction, privKey ecdsa.PrivateKey)
- func (bc *BlockChain) VerifyTransaction(tx *Transaction) bool
- type BlockChainIterator
- 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(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 = 18
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct { Timestamp int64 `json:"timestamp"` Hash []byte `json:"hash"` Transactions []*Transaction `json:"transactions"` PrevHash []byte `json:"prevHash"` Nonce int `json:"nonce"` Height int `json:"height"` }
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) FindTransaction ¶
func (bc *BlockChain) FindTransaction(ID []byte) (Transaction, error)
func (*BlockChain) FindUTXO ¶
func (chain *BlockChain) FindUTXO() map[string]TxOutputs
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 (bc *BlockChain) SignTransaction(tx *Transaction, privKey ecdsa.PrivateKey)
func (*BlockChain) VerifyTransaction ¶
func (bc *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"` Inputs []TxInput `json:"inputs"` Outputs []TxOutput `json:"outputs"` }
func CoinbaseTx ¶
func CoinbaseTx(to, data string) *Transaction
func DeserializeTransaction ¶
func DeserializeTransaction(data []byte) Transaction
func NewTransaction ¶
func RewardTx ¶
func RewardTx(to, data string) *Transaction
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(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 TxOutputs ¶
type TxOutputs struct {
Outputs []TxOutput `json:"outputs"`
}
func DeserializeOutputs ¶
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.