Documentation
¶
Index ¶
- func DBExists() bool
- func Int64ToBytes(num int64) []byte
- func JsonToArray(jsonString string) []string
- type Block
- type BlockChain
- func (blc *BlockChain) AddBlockToBlockchain(txs []*Transaction)
- func (blc *BlockChain) GetBalance(address string) int64
- func (blc *BlockChain) GetUTXOs(address string) []*UTXO
- func (blc *BlockChain) Iterator() *BlockChainIterator
- func (blc *BlockChain) MineNewBlock(from []string, to []string, amount []string) *BlockChain
- func (blc *BlockChain) PrintBlockChain()
- type BlockChainIterator
- type CLI
- type ProofOfWork
- type TXInput
- type TXOutput
- type Transaction
- type UTXO
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Int64ToBytes ¶
func JsonToArray ¶
Types ¶
type Block ¶
type Block struct {
// 区块高度
Height int64
// 当前区块 HASH 值
Hash []byte
// 上一个区块的 HASH 值
PrevBlockHash []byte
// 交易数据
Txs []*Transaction
// 时间戳
Timestamp int64
// Nonce 用于工作量整蒙
Nonce int64
}
func CreateGenesisBlock ¶
func CreateGenesisBlock(txs []*Transaction) *Block
CreateGenesisBlock 单独写一个方法,生成创世区块
func NewBlock ¶
func NewBlock(txs []*Transaction, height int64, prevBlockHash []byte) *Block
NewBlock 创建新的区块
func (*Block) HashTransactions ¶
HashTransactions 将 transactions 转化为 []byte
type BlockChain ¶
func CreateBlockchainWithGenesisBlock ¶
func CreateBlockchainWithGenesisBlock(address string) *BlockChain
CreateBlockchainWithGenesisBlock 创建带有创世区块的区块链
func GetBlockChainFromBolt ¶
func GetBlockChainFromBolt() *BlockChain
func (*BlockChain) AddBlockToBlockchain ¶
func (blc *BlockChain) AddBlockToBlockchain(txs []*Transaction)
AddBlockToBlockchain 增加区块到区块链里面
func (*BlockChain) GetBalance ¶
func (blc *BlockChain) GetBalance(address string) int64
func (*BlockChain) GetUTXOs ¶
func (blc *BlockChain) GetUTXOs(address string) []*UTXO
GetUTXOs 如果一个地址对应的 TxOutput 未花费,那么这个 Transaction 就应该添加到数组中返回
func (*BlockChain) Iterator ¶
func (blc *BlockChain) Iterator() *BlockChainIterator
func (*BlockChain) MineNewBlock ¶
func (blc *BlockChain) MineNewBlock(from []string, to []string, amount []string) *BlockChain
MineNewBlock 挖掘新的区块
func (*BlockChain) PrintBlockChain ¶
func (blc *BlockChain) PrintBlockChain()
PrintBlockChain 遍历输出所有区块的信息
type BlockChainIterator ¶
func (*BlockChainIterator) Next ¶
func (blcIterator *BlockChainIterator) Next() *Block
type ProofOfWork ¶
type ProofOfWork struct {
Block *Block // 当前要验证的区块
// contains filtered or unexported fields
}
func NewProofOfWork ¶
func NewProofOfWork(block *Block) *ProofOfWork
func (ProofOfWork) Run ¶
func (proofOfWork ProofOfWork) Run() ([]byte, int64)
type TXInput ¶
type TXInput struct {
// 交易的 Hash
TxHash []byte
// 存储 TXOutput 在 Vout 里面的索引
Vout int
// 用户名
ScriptSig string
}
func (*TXInput) UnLockWithAddress ¶
UnLockWithAddress 判断当前的消费是谁的钱
type TXOutput ¶
func (*TXOutput) UnLockScriptPubKeyWithAddress ¶
UnLockScriptPubKeyWithAddress 解锁
type Transaction ¶
Transaction UTXO
func NewCoinbaseTransaction ¶
func NewCoinbaseTransaction(address string) *Transaction
NewCoinbaseTransaction 1. 创世区块创建时的 Transaction
func NewSimpleTransaction ¶
func NewSimpleTransaction(from string, to string, amount int) *Transaction
NewSimpleTransaction 2. 转账时产生的 Transaction
func (*Transaction) HashTransaction ¶
func (tx *Transaction) HashTransaction()
func (*Transaction) IsCoinbaseTransaction ¶
func (tx *Transaction) IsCoinbaseTransaction() bool
IsCoinbaseTransaction 判断当前交易是否是 Coinbase 交易
Click to show internal directories.
Click to hide internal directories.