Documentation
¶
Index ¶
- func GenerateMerkleProof(transactions []*Transaction, index int) ([][]byte, error)
- func HashData(data []byte) []byte
- func HashTransaction(tx *Transaction) []byte
- func PutIntoDb(bc *Blockchain) error
- func VerifyTransaction(rootHash []byte, tx *Transaction, proof [][]byte) bool
- type Block
- type BlockHeightTxIndex
- type Blockchain
- func (bc *Blockchain) AddBlock(nonce int, txns []*Transaction)
- func (bc *Blockchain) AddTransactionToTransactionPool(txn *Transaction)
- func (bc *Blockchain) Airdrop(address string)
- func (bc *Blockchain) CalculateBalance(address string) int
- func (bc *Blockchain) CopyTransactionPool() []*Transaction
- func (bc *Blockchain) LastBlock() *Block
- func (bc *Blockchain) Mining() bool
- func (bc *Blockchain) ProofOfWork() (int, []*Transaction)
- func (bc *Blockchain) ToJSON() string
- func (bc *Blockchain) ValidProof(nonce int, previousHash string, transactions []*Transaction, difficulty int) bool
- type Node
- type Transaction
- type TransactionIndex
- type WalletIndex
- type WalletTransactionIndex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateMerkleProof ¶
func GenerateMerkleProof(transactions []*Transaction, index int) ([][]byte, error)
func HashTransaction ¶
func HashTransaction(tx *Transaction) []byte
func PutIntoDb ¶
func PutIntoDb(bc *Blockchain) error
func VerifyTransaction ¶
func VerifyTransaction(rootHash []byte, tx *Transaction, proof [][]byte) bool
Types ¶
type Block ¶
type Block struct {
Number int `json:"number"`
PrevHash string `json:"prevHash"`
Timestamp int64 `json:"timestamp"`
Nonce int `json:"nonce"`
Transactions []*Transaction `json:"transactions"`
MerkleRoot string `json:"merkle_root"`
}
func NewBlock ¶
func NewBlock(prevHash string, blockHeight int, nonce int, txns []*Transaction) *Block
func (*Block) AddTransactionToTheBlock ¶
func (b *Block) AddTransactionToTheBlock(txn *Transaction)
type BlockHeightTxIndex ¶
type Blockchain ¶
type Blockchain struct {
TransactionPool []*Transaction `json:"transaction_pool"`
Blocks []*Block `json:"block_chain"`
WalletIndex *WalletIndex
TransactionIndex *TransactionIndex
}
func NewBlockchain ¶
func NewBlockchain(genesisBlock *Block) *Blockchain
func ReadFromDb ¶
func ReadFromDb() (Blockchain, error)
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(nonce int, txns []*Transaction)
func (*Blockchain) AddTransactionToTransactionPool ¶
func (bc *Blockchain) AddTransactionToTransactionPool(txn *Transaction)
func (*Blockchain) Airdrop ¶
func (bc *Blockchain) Airdrop(address string)
func (*Blockchain) CalculateBalance ¶
func (bc *Blockchain) CalculateBalance(address string) int
func (*Blockchain) CopyTransactionPool ¶
func (bc *Blockchain) CopyTransactionPool() []*Transaction
func (*Blockchain) LastBlock ¶
func (bc *Blockchain) LastBlock() *Block
func (*Blockchain) Mining ¶
func (bc *Blockchain) Mining() bool
func (*Blockchain) ProofOfWork ¶
func (bc *Blockchain) ProofOfWork() (int, []*Transaction)
func (*Blockchain) ToJSON ¶
func (bc *Blockchain) ToJSON() string
func (*Blockchain) ValidProof ¶
func (bc *Blockchain) ValidProof(nonce int, previousHash string, transactions []*Transaction, difficulty int) bool
type Node ¶
func BuildMerkleTree ¶
func CreateLeafNodes ¶
func CreateLeafNodes(transactions []*Transaction) []*Node
type Transaction ¶
type Transaction struct {
From string `json:"from"`
To string `json:"to"`
Value uint64 `json:"value"`
Data []byte `json:"data"`
Status string `json:"status"`
TransactioHash string `json:"transaction_hash"`
}
func NewTransaction ¶
func NewTransaction(from string, to string, value uint64, data []byte) *Transaction
func (*Transaction) Hash ¶
func (t *Transaction) Hash() string
func (*Transaction) ToJSON ¶
func (t *Transaction) ToJSON() string
func (*Transaction) VerifyTransaction ¶
func (t *Transaction) VerifyTransaction() bool
type TransactionIndex ¶
type TransactionIndex struct {
TxBlockHeight map[string]*BlockHeightTxIndex `json:"transactions"`
}
func NewTransactionIndex ¶
func NewTransactionIndex() *TransactionIndex
func (*TransactionIndex) AddTransaction ¶
func (ti *TransactionIndex) AddTransaction(txHash string, txIndex int, blockHeight int)
func (*TransactionIndex) GetTransactionMetadata ¶
func (ti *TransactionIndex) GetTransactionMetadata(txHash string) *BlockHeightTxIndex
type WalletIndex ¶
type WalletIndex struct {
Transactions map[string][]*WalletTransactionIndex `json:"transactions"`
}
func NewWalletIndex ¶
func NewWalletIndex() *WalletIndex
func (*WalletIndex) AddTransaction ¶
func (w *WalletIndex) AddTransaction(address string, blockIndex int, txIndex int, transaction *Transaction)
func (*WalletIndex) GetWalletTransactions ¶
func (w *WalletIndex) GetWalletTransactions(address string) []*WalletTransactionIndex
type WalletTransactionIndex ¶
type WalletTransactionIndex struct {
BlockIndex int `json:"block_index"`
TransactionIndex int `json:"transaction_index"`
Transaction *Transaction `json:"transactions"`
}
Click to show internal directories.
Click to hide internal directories.