(blkNum uint32, prevBlkHash common.Uint256, txs []*types.Transaction, consensusPayload []byte, blocktimestamp uint32)
| 187 | } |
| 188 | |
| 189 | func (self *Server) constructBlock(blkNum uint32, prevBlkHash common.Uint256, txs []*types.Transaction, consensusPayload []byte, blocktimestamp uint32) (*types.Block, error) { |
| 190 | txHash := []common.Uint256{} |
| 191 | for _, t := range txs { |
| 192 | txHash = append(txHash, t.Hash()) |
| 193 | } |
| 194 | lastBlock, _ := self.blockPool.getSealedBlock(blkNum - 1) |
| 195 | if lastBlock == nil { |
| 196 | log.Errorf("constructBlock getlastblock failed blknum:%d", blkNum-1) |
| 197 | return nil, fmt.Errorf("constructBlock getlastblock failed blknum:%d", blkNum-1) |
| 198 | } |
| 199 | |
| 200 | txRoot := common.ComputeMerkleRoot(txHash) |
| 201 | blockRoot := ledger.DefLedger.GetBlockRootWithNewTxRoots(lastBlock.Block.Header.Height, []common.Uint256{lastBlock.Block.Header.TransactionsRoot, txRoot}) |
| 202 | |
| 203 | blkHeader := &types.Header{ |
| 204 | PrevBlockHash: prevBlkHash, |
| 205 | TransactionsRoot: txRoot, |
| 206 | BlockRoot: blockRoot, |
| 207 | Timestamp: blocktimestamp, |
| 208 | Height: uint32(blkNum), |
| 209 | ConsensusData: common.GetNonce(), |
| 210 | ConsensusPayload: consensusPayload, |
| 211 | } |
| 212 | blk := &types.Block{ |
| 213 | Header: blkHeader, |
| 214 | Transactions: txs, |
| 215 | } |
| 216 | blkHash := blk.Hash() |
| 217 | sig, err := signature.Sign(self.account, blkHash[:]) |
| 218 | if err != nil { |
| 219 | return nil, fmt.Errorf("sign block failed, block hash:%s, error: %s", blkHash.ToHexString(), err) |
| 220 | } |
| 221 | blkHeader.Bookkeepers = []keypair.PublicKey{self.account.PublicKey} |
| 222 | blkHeader.SigData = [][]byte{sig} |
| 223 | |
| 224 | return blk, nil |
| 225 | } |
| 226 | |
| 227 | func (self *Server) constructProposalMsg(blkNum uint32, sysTxs, userTxs []*types.Transaction, chainconfig *vconfig.ChainConfig) (*blockProposalMsg, error) { |
| 228 |
no test coverage detected