Documentation ¶
Overview ¶
Package block 是区块和区块链的结构体定义和操作方法
Index ¶
- Variables
- func ByteToInt64(b []byte) int64
- func Int64ToByte(n int64) []byte
- type Block
- type BlockChain
- func (bc *BlockChain) CheckLength()
- func (bc *BlockChain) Close()
- func (bc *BlockChain) Draw(start int64, end int64) string
- func (bc *BlockChain) GetBlockByHash(hash []byte) (*Block, error)
- func (bc *BlockChain) GetBlockByNumber(number int64) (*Block, error)
- func (bc *BlockChain) GetBlockByteByHash(hash []byte) ([]byte, error)
- func (bc *BlockChain) GetHashByNumber(number int64) ([]byte, error)
- func (bc *BlockChain) Length() int64
- func (bc *BlockChain) Push(block *Block) error
- func (bc *BlockChain) Top() (*Block, error)
- type BlockHead
- func (b *BlockHead) Decode(bhByte []byte) error
- func (*BlockHead) Descriptor() ([]byte, []int)
- func (b *BlockHead) Encode() ([]byte, error)
- func (m *BlockHead) GetInfo() []byte
- func (m *BlockHead) GetMerkleHash() []byte
- func (m *BlockHead) GetNumber() int64
- func (m *BlockHead) GetParentHash() []byte
- func (m *BlockHead) GetTime() int64
- func (m *BlockHead) GetTxsHash() []byte
- func (m *BlockHead) GetVersion() int64
- func (m *BlockHead) GetWitness() string
- func (b *BlockHead) Hash() ([]byte, error)
- func (m *BlockHead) Marshal() (dAtA []byte, err error)
- func (m *BlockHead) MarshalTo(dAtA []byte) (int, error)
- func (*BlockHead) ProtoMessage()
- func (m *BlockHead) Reset()
- func (m *BlockHead) Size() (n int)
- func (m *BlockHead) String() string
- func (m *BlockHead) Unmarshal(dAtA []byte) error
- func (m *BlockHead) XXX_DiscardUnknown()
- func (m *BlockHead) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *BlockHead) XXX_Merge(src proto.Message)
- func (m *BlockHead) XXX_Size() int
- func (m *BlockHead) XXX_Unmarshal(b []byte) error
- type BlockRaw
- func (*BlockRaw) Descriptor() ([]byte, []int)
- func (m *BlockRaw) GetHead() *BlockHead
- func (m *BlockRaw) GetReceipts() [][]byte
- func (m *BlockRaw) GetSign() []byte
- func (m *BlockRaw) GetTxs() [][]byte
- func (m *BlockRaw) Marshal() (dAtA []byte, err error)
- func (m *BlockRaw) MarshalTo(dAtA []byte) (int, error)
- func (*BlockRaw) ProtoMessage()
- func (m *BlockRaw) Reset()
- func (m *BlockRaw) Size() (n int)
- func (m *BlockRaw) String() string
- func (m *BlockRaw) Unmarshal(dAtA []byte) error
- func (m *BlockRaw) XXX_DiscardUnknown()
- func (m *BlockRaw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *BlockRaw) XXX_Merge(src proto.Message)
- func (m *BlockRaw) XXX_Size() int
- func (m *BlockRaw) XXX_Unmarshal(b []byte) error
- type Chain
- type ChainIterator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidLengthBlock = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowBlock = fmt.Errorf("proto: integer overflow") )
Functions ¶
Types ¶
type Block ¶
type Block struct { Head *BlockHead Sign *crypto.Signature Txs []*tx.Tx Receipts []*tx.TxReceipt // contains filtered or unexported fields }
Block is the implementation of block
func (*Block) CalculateHeadHash ¶
CalculateHeadHash calculate the hash of the head
func (*Block) CalculateMerkleHash ¶
CalculateMerkleHash calculate the hash of the MerkleTree
func (*Block) CalculateTxsHash ¶
CalculateTxsHash calculate the hash of the transaction
type BlockChain ¶
type BlockChain struct {
// contains filtered or unexported fields
}
BlockChain is the implementation of chain
func (*BlockChain) CheckLength ¶
func (bc *BlockChain) CheckLength()
CheckLength is check length of block in database
func (*BlockChain) GetBlockByHash ¶
func (bc *BlockChain) GetBlockByHash(hash []byte) (*Block, error)
GetBlockByHash is get block by hash
func (*BlockChain) GetBlockByNumber ¶
func (bc *BlockChain) GetBlockByNumber(number int64) (*Block, error)
GetBlockByNumber is get block by number
func (*BlockChain) GetBlockByteByHash ¶
func (bc *BlockChain) GetBlockByteByHash(hash []byte) ([]byte, error)
GetBlockByteByHash is get block byte by hash
func (*BlockChain) GetHashByNumber ¶
func (bc *BlockChain) GetHashByNumber(number int64) ([]byte, error)
GetHashByNumber is get hash by number
func (*BlockChain) Length ¶
func (bc *BlockChain) Length() int64
Length return length of block chain
func (*BlockChain) Push ¶
func (bc *BlockChain) Push(block *Block) error
Push save the block to database
type BlockHead ¶
type BlockHead struct { Version int64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` ParentHash []byte `protobuf:"bytes,2,opt,name=parentHash,proto3" json:"parentHash,omitempty"` TxsHash []byte `protobuf:"bytes,3,opt,name=txsHash,proto3" json:"txsHash,omitempty"` MerkleHash []byte `protobuf:"bytes,4,opt,name=merkleHash,proto3" json:"merkleHash,omitempty"` Info []byte `protobuf:"bytes,5,opt,name=info,proto3" json:"info,omitempty"` Number int64 `protobuf:"varint,6,opt,name=number,proto3" json:"number,omitempty"` Witness string `protobuf:"bytes,7,opt,name=witness,proto3" json:"witness,omitempty"` Time int64 `protobuf:"varint,8,opt,name=time,proto3" json:"time,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*BlockHead) Descriptor ¶
func (*BlockHead) GetMerkleHash ¶
func (*BlockHead) GetParentHash ¶
func (*BlockHead) GetTxsHash ¶
func (*BlockHead) GetVersion ¶
func (*BlockHead) GetWitness ¶
func (*BlockHead) ProtoMessage ¶
func (*BlockHead) ProtoMessage()
func (*BlockHead) XXX_DiscardUnknown ¶
func (m *BlockHead) XXX_DiscardUnknown()
func (*BlockHead) XXX_Marshal ¶
func (*BlockHead) XXX_Unmarshal ¶
type BlockRaw ¶
type BlockRaw struct { Head *BlockHead `protobuf:"bytes,1,opt,name=head" json:"head,omitempty"` Sign []byte `protobuf:"bytes,2,opt,name=sign,proto3" json:"sign,omitempty"` Txs [][]byte `protobuf:"bytes,3,rep,name=txs" json:"txs,omitempty"` Receipts [][]byte `protobuf:"bytes,4,rep,name=receipts" json:"receipts,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*BlockRaw) Descriptor ¶
func (*BlockRaw) GetReceipts ¶
func (*BlockRaw) ProtoMessage ¶
func (*BlockRaw) ProtoMessage()
func (*BlockRaw) XXX_DiscardUnknown ¶
func (m *BlockRaw) XXX_DiscardUnknown()
func (*BlockRaw) XXX_Marshal ¶
func (*BlockRaw) XXX_Unmarshal ¶
type Chain ¶
type Chain interface { Push(block *Block) error Length() int64 CheckLength() Top() (*Block, error) GetHashByNumber(number int64) ([]byte, error) GetBlockByNumber(number int64) (*Block, error) GetBlockByHash(blockHash []byte) (*Block, error) GetBlockByteByHash(blockHash []byte) ([]byte, error) Close() Draw(int64, int64) string }
Chain defines Chain's API.
func NewBlockChain ¶
NewBlockChain returns a Chain instance
type ChainIterator ¶
type ChainIterator interface {
Next() *Block
}
ChainIterator is iterator of block chain
Click to show internal directories.
Click to hide internal directories.