Documentation ¶
Index ¶
- func IntToHex(data int64) []byte
- func IsValidArgs()
- func JSONToSlice(jsonString string) []string
- func PrintUsage()
- type Block
- type BlockChain
- func (bc *BlockChain) AddBlock(txs []*Transaction)
- func (blc *BlockChain) Iterator() *BlockChainIterator
- func (blockchain *BlockChain) MineNewBlock(from, to, amount []string)
- func (bc *BlockChain) PrintChain()
- func (blockchain *BlockChain) SpentOutput(address string) map[string][]int
- func (blockchain *BlockChain) UnUTXOS(address string) []*TxOutput
- type BlockChainIterator
- type CLI
- type ProofOfWork
- type Transaction
- type TxInput
- type TxOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONToSlice ¶
标准JSON格式转切片 windows下需要添加引号 bc.exe send -from "[\"troytan\"]" -to "[\"Alice\"]" -amount "[\"100\"]"
Types ¶
type Block ¶
type Block struct { TimeStamp int64 //区块时间戳,代表区块时间 Hash []byte //当前区块哈希 PreBlockHash []byte //前区块哈希 Height int64 //区块高度 //Data []byte //交易数据 Txs []*Transaction //交易数据(交易列表) Nonce int64 //在运行pow时生成的哈希变化值,也代表pow运行时动态修改的数据 }
区块基本结构与功能管理文件
func (*Block) HashTransaction ¶
把指定区块中所有交易结构都序列化(类Merkle的哈希计算方法)
type BlockChain ¶
区块链的基本结构
func CreateBlockChainWithGenesisBlock ¶
func CreateBlockChainWithGenesisBlock(address string) *BlockChain
初始化区块链
func (*BlockChain) MineNewBlock ¶
func (blockchain *BlockChain) MineNewBlock(from, to, amount []string)
实现挖矿功能 通过接收交易生成区块
func (*BlockChain) SpentOutput ¶
func (blockchain *BlockChain) SpentOutput(address string) map[string][]int
获取指定地址所有已花费输出
func (*BlockChain) UnUTXOS ¶
func (blockchain *BlockChain) UnUTXOS(address string) []*TxOutput
type BlockChainIterator ¶
迭代器基本结构
type ProofOfWork ¶
type ProofOfWork struct { //需要共识验证的模块 Block *Block // contains filtered or unexported fields }
工作量证明的结构
func (*ProofOfWork) Run ¶
func (proofOfWork *ProofOfWork) Run() ([]byte, int)
执行pow,比较哈希值 返回哈希值,以及碰撞次数
type Transaction ¶
type Transaction struct { //交易哈希(标识) TxHash []byte //输入列表 Vins []*TxInput //输出列表 Vouts []*TxOutput }
定义一个交易基本结构
func NewSimpleTransaction ¶
func NewSimpleTransaction(from string, to string, amount int) *Transaction
生成普通转账交易
func (*Transaction) IsCoinbaseTransaction ¶
func (tx *Transaction) IsCoinbaseTransaction() bool
判断指定的交易是否是一个coinbase交易
Click to show internal directories.
Click to hide internal directories.