Documentation
¶
Overview ¶
gencode go -schema block.schema -package blockchain -out block_schema.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
Types ¶
type Block ¶
type Block struct {
// 本区块在区块链中的高度
Height uint64 `json:"height,omitempty"`
// 本区块产生的时间戳
Timestamp int64 `json:"timestamp,omitempty"`
// 数据Data的哈希值
Hash string `json:"hash,omitempty"`
// 上一个区块中的Data的哈希值
PrevHash string `json:"prev_hash,omitempty"`
// 难度系数
Difficulty uint32 `json:"difficulty"`
// 随机数
Nonce uint32 `json:"nonce"`
// 本区块中的数据
Data []byte `json:"data,omitempty"`
}
Block 代表区块链中的一块.
type Blockchain ¶
type Blockchain struct {
Blocks []*Block
sync.RWMutex
Store Store
Difficulty uint32
PrefixZero string
}
Blockchain 是一条完整的区块链
func (*Blockchain) GenerateGenesisBlock ¶
func (bc *Blockchain) GenerateGenesisBlock()
GenerateGenesisBlock 初始化创世块.
func (*Blockchain) LoadFromStore ¶
func (bc *Blockchain) LoadFromStore() error
LoadFromStore 从文件中加载blockchain.
type Server ¶
type Server struct {
Addr string
Blockchain *Blockchain
// contains filtered or unexported fields
}
Server 提供区块链rpc服务,比如增加区块,查看区块等.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
bc
command
|
|
|
key
command
|
|
|
base58check/base58
Package base58 implements a human-friendly base58 encoding.
|
Package base58 implements a human-friendly base58 encoding. |
Click to show internal directories.
Click to hide internal directories.