Documentation ¶
Index ¶
- Constants
- func Decimals(decimal int64) int64
- type Block
- func (block Block) Bytes() []byte
- func (block *Block) CheckSubTransaction(tx userevent.Transaction, subTxs userevent.SubTransactions) bool
- func (block *Block) ContractCall(tx userevent.Transaction) *userevent.TransactionReceipt
- func (block *Block) DeployContract(tx userevent.Transaction) *userevent.TransactionReceipt
- func (block *Block) Finish()
- func (block Block) GetHeader() *Header
- func (block *Block) GetSticker() *context.Sticker
- func (block Block) GetTransactions() []userevent.Transaction
- func (block Block) GetTxReceipts() []userevent.TransactionReceipt
- func (block *Block) NewTransaction(tx userevent.Transaction) *userevent.TransactionReceipt
- func (block *Block) NormalTransfer(tx userevent.Transaction) *userevent.TransactionReceipt
- func (block *Block) SetHeader(header *Header)
- func (block *Block) Sign(privKey []byte) error
- func (block *Block) UpgradeContract(tx userevent.Transaction) *userevent.TransactionReceipt
- type BlockChain
- func (chain *BlockChain) GetLastHeight() int64
- func (chain *BlockChain) LastHeader() Header
- func (chain *BlockChain) NewTransaction(tx *userevent.Transaction) bool
- func (chain *BlockChain) NotifyPool(txs []userevent.Transaction)
- func (chain *BlockChain) PackTime(block *Block) time.Duration
- func (chain *BlockChain) PackTransaction(clog *ctxlog.ContextLog, block *Block)
- func (chain *BlockChain) SetLastHeader(header Header)
- func (chain *BlockChain) ValidateBlock(next Block) bool
- type BlockManager
- func (manager *BlockManager) CheckHeightInterval(height, interval int64) bool
- func (manager *BlockManager) GetBlock(hash []byte) *Block
- func (manager *BlockManager) GetBlockStatus(hash []byte) int
- func (manager *BlockManager) GetVoteTime(height int64) int64
- func (manager *BlockManager) Insert(block *Block)
- func (manager *BlockManager) SetBlockStatus(hash []byte, status int)
- func (manager *BlockManager) SetBlockStatusByHeight(height, ms int64)
- func (manager *BlockManager) SetVoteTime(height int64, time int64)
- type BlockVoteDetail
- type Header
- func (header Header) Author() []byte
- func (header *Header) Bytes() []byte
- func (header *Header) CalculateHash() []byte
- func (header *Header) CheckFromAndBurnGas(tx userevent.Transaction) bool
- func (header *Header) CheckSubTx(from, to *types.Account, tx userevent.SubTransaction) bool
- func (header *Header) CheckTransfer(tx userevent.Transaction) bool
- func (header Header) Equal(peerHeader Header) bool
- func (header Header) ExistAddress(address []byte) bool
- func (header Header) GetAccount(address []byte) (*types.Account, error)
- func (header Header) GetParent() []byte
- func (header Header) GetTimestamp() int64
- func (header *Header) HandleTx(from, to *types.Account, tx userevent.SubTransaction) bool
- func (header *Header) ModifyContract(address, data []byte) error
- func (header *Header) NewSubTransaction(txs userevent.SubTransactions) bool
- func (header *Header) Transfer(from, to *types.Account, tx userevent.SubTransaction) bool
- func (header *Header) UpdateMiner()
- type IBlock
- type PeerBlockVote
- type VoteResults
- func (voteResults VoteResults) Broadcasted(blockHash []byte) bool
- func (voteResults VoteResults) GetVoteResults(hash string) Votes
- func (voteResults VoteResults) Insert(vote PeerBlockVote)
- func (voteResults VoteResults) Number(blockHash []byte) int
- func (voteResults VoteResults) SetVoteResults(hash string, votes Votes)
- type Votes
Constants ¶
View Source
const ( VM_CALL_TIMEOUT = 200 * time.Millisecond EMPTY_TX = "ca4510738395af1429224dd785675309c344b2b549632e20275c69b15ed1d210" )
View Source
const ( // 1xx未处理 BLOCK_TO_BE_HANDLE = 100 // 2xx 处理成功待后续处理 BLOCK_VALID = 201 BLOCK_VOTED = 202 // 3xx 错误的区块 BLOCK_ERROR_START = 300 BLOCK_ERROR_PACK_TIME = 301 BLOCK_ERROR_BROADCAST_TIME = 302 BLOCK_ERROR_HASH = 303 BLOCK_ERROR_SIGN = 304 BLOCK_ERROR_BODY = 305 BLOCK_ERROR_END = 399 // 400已经写入区块链 BLOCK_SAVED = 400 )
View Source
const ( HEADER_VERSION_PURE_MTP = 0 HEADER_VERSION_MIXED = 1 HEADER_VERSION_MERKLER = 2 )
View Source
const (
BackboneBlockInterval = 3 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct { Header *Header `json:"header"` Hash types.HexBytes `json:"hash"` Signature types.HexBytes `json:"signature"` Miner types.Peer `json:"miner"` Transactions userevent.Transactions `json:"-"` TransactionReceipts userevent.Receipts `json:"-"` }
func CreateGenesisBlock ¶
func GetBlockFromBytes ¶
func (*Block) CheckSubTransaction ¶
func (block *Block) CheckSubTransaction(tx userevent.Transaction, subTxs userevent.SubTransactions) bool
func (*Block) ContractCall ¶
func (block *Block) ContractCall(tx userevent.Transaction) *userevent.TransactionReceipt
func (*Block) DeployContract ¶
func (block *Block) DeployContract(tx userevent.Transaction) *userevent.TransactionReceipt
func (*Block) GetSticker ¶
func (Block) GetTransactions ¶
func (block Block) GetTransactions() []userevent.Transaction
func (Block) GetTxReceipts ¶
func (block Block) GetTxReceipts() []userevent.TransactionReceipt
func (*Block) NewTransaction ¶
func (block *Block) NewTransaction(tx userevent.Transaction) *userevent.TransactionReceipt
func (*Block) NormalTransfer ¶
func (block *Block) NormalTransfer(tx userevent.Transaction) *userevent.TransactionReceipt
func (*Block) UpgradeContract ¶
func (block *Block) UpgradeContract(tx userevent.Transaction) *userevent.TransactionReceipt
type BlockChain ¶
type BlockChain struct { ChainId int64 Pool *pool.TxPool // contains filtered or unexported fields }
func NewBlockChain ¶
func NewBlockChain(chainId int64) *BlockChain
func (*BlockChain) GetLastHeight ¶
func (chain *BlockChain) GetLastHeight() int64
func (*BlockChain) LastHeader ¶
func (chain *BlockChain) LastHeader() Header
func (*BlockChain) NewTransaction ¶
func (chain *BlockChain) NewTransaction(tx *userevent.Transaction) bool
func (*BlockChain) NotifyPool ¶
func (chain *BlockChain) NotifyPool(txs []userevent.Transaction)
当区块写入区块时,notify交易池,一些nonce比较大的交易可以进行打包
func (*BlockChain) PackTransaction ¶
func (chain *BlockChain) PackTransaction(clog *ctxlog.ContextLog, block *Block)
func (*BlockChain) SetLastHeader ¶
func (chain *BlockChain) SetLastHeader(header Header)
func (*BlockChain) ValidateBlock ¶
func (chain *BlockChain) ValidateBlock(next Block) bool
type BlockManager ¶
type BlockManager struct { Blocks *sync.Map BlockStatus *sync.Map // 根据区块hash计算,主要是从peer来的区块 100:待处理 101:已经处理成功,未写入区块 400:错误的区块头 200:处理成功,已经写入区块 HeightManager *sync.Map // 根据block的height进行计算,主要是防止内部多次进行打包 100代表未打包,101代表已打包 HeightVote *sync.Map //上次在某个高度的投票时间,防止重复投票 }
内部操作不加lock,外部在需要加锁的地方加锁,保证操作的原子性
func NewBlockManager ¶
func NewBlockManager() *BlockManager
func (*BlockManager) CheckHeightInterval ¶
func (manager *BlockManager) CheckHeightInterval(height, interval int64) bool
根据区块高度判断自己是否可以对此高度进行打包 一个区块在1个interval内不可以对同一个高度的区块进行打包
func (*BlockManager) GetBlock ¶
func (manager *BlockManager) GetBlock(hash []byte) *Block
func (*BlockManager) GetBlockStatus ¶
func (manager *BlockManager) GetBlockStatus(hash []byte) int
获取指定区块的状态, -1表示不存在
func (*BlockManager) GetVoteTime ¶
func (manager *BlockManager) GetVoteTime(height int64) int64
func (*BlockManager) SetBlockStatus ¶
func (manager *BlockManager) SetBlockStatus(hash []byte, status int)
func (*BlockManager) SetBlockStatusByHeight ¶
func (manager *BlockManager) SetBlockStatusByHeight(height, ms int64)
func (*BlockManager) SetVoteTime ¶
func (manager *BlockManager) SetVoteTime(height int64, time int64)
type BlockVoteDetail ¶
type Header ¶
type Header struct { Height int64 `json:"height"` Timestamp int64 `json:"timestamp"` TotalFee int64 `json:"totalFee"` PreviousHash types.HexBytes `json:"previousHash"` Coinbase types.HexBytes `json:"miner"` StatTree *MPTPlus.MTP `json:"statRoot"` TokenTree *MPTPlus.MTP `json:"tokenRoot"` TxHash types.HexBytes `json:"txHash"` TxRoot *MPTPlus.MTP `json:"txRoot"` ReceiptHash types.HexBytes `json:"receiptHash"` ReceiptRoot *MPTPlus.MTP `json:"receiptRoot"` ChainStat *MPTPlus.MTP `json:"chainStat"` ChainEvent *MPTPlus.MTP `json:"chainEvent"` Version int `json:"version"` }
func FromBytes2Header ¶
func GenesisHeader ¶
func NewHeader_V2 ¶
func (*Header) CalculateHash ¶
func (*Header) CheckFromAndBurnGas ¶
func (header *Header) CheckFromAndBurnGas(tx userevent.Transaction) bool
func (*Header) CheckSubTx ¶
func (*Header) CheckTransfer ¶
func (header *Header) CheckTransfer(tx userevent.Transaction) bool
func (Header) ExistAddress ¶
func (Header) GetTimestamp ¶
func (*Header) ModifyContract ¶
func (*Header) NewSubTransaction ¶
func (header *Header) NewSubTransaction(txs userevent.SubTransactions) bool
func (*Header) UpdateMiner ¶
func (header *Header) UpdateMiner()
type IBlock ¶
type IBlock interface { GetTransactions() []userevent.Transaction GetTxReceipts() []userevent.TransactionReceipt }
type PeerBlockVote ¶
type PeerBlockVote struct { Vote BlockVoteDetail `json:"vote"` Peer types.Peer `json:"peer"` Signature types.HexBytes `json:"signature"` }
func (PeerBlockVote) Bytes ¶
func (vote PeerBlockVote) Bytes() []byte
func (PeerBlockVote) Equal ¶
func (vote1 PeerBlockVote) Equal(vote2 PeerBlockVote) bool
func (PeerBlockVote) Msg ¶
func (vote PeerBlockVote) Msg() []byte
func (*PeerBlockVote) Sign ¶
func (vote *PeerBlockVote) Sign(PrivKey []byte) error
func (PeerBlockVote) Validate ¶
func (vote PeerBlockVote) Validate() bool
type VoteResults ¶
type VoteResults struct {
// contains filtered or unexported fields
}
var VoteResultManager VoteResults
func NewVoteResults ¶
func NewVoteResults() VoteResults
func (VoteResults) Broadcasted ¶
func (voteResults VoteResults) Broadcasted(blockHash []byte) bool
func (VoteResults) GetVoteResults ¶
func (voteResults VoteResults) GetVoteResults(hash string) Votes
func (VoteResults) Insert ¶
func (voteResults VoteResults) Insert(vote PeerBlockVote)
func (VoteResults) Number ¶
func (voteResults VoteResults) Number(blockHash []byte) int
func (VoteResults) SetVoteResults ¶
func (voteResults VoteResults) SetVoteResults(hash string, votes Votes)
type Votes ¶
type Votes []PeerBlockVote
Click to show internal directories.
Click to hide internal directories.