OSDN Git Service

9cb74b5596daf6ad24ae080661580888d13254c9
[bytom/bytom.git] / protocol / bc / blockheader.go
1 package bc
2
3 import "io"
4
5 // BlockHeader contains the header information for a blockchain
6 // block. It satisfies the Entry interface.
7
8 func (BlockHeader) typ() string { return "blockheader" }
9 func (bh *BlockHeader) writeForHash(w io.Writer) {
10         mustWriteForHash(w, bh.Version)
11         mustWriteForHash(w, bh.Height)
12         mustWriteForHash(w, bh.PreviousBlockId)
13         mustWriteForHash(w, bh.Seed)
14         mustWriteForHash(w, bh.Timestamp)
15         mustWriteForHash(w, bh.TransactionsRoot)
16         mustWriteForHash(w, bh.AssetsRoot)
17         mustWriteForHash(w, bh.Nonce)
18         mustWriteForHash(w, bh.Bits)
19         mustWriteForHash(w, bh.TransactionStatus)
20 }
21
22 // NewBlockHeader creates a new BlockHeader and populates
23 // its body.
24 func NewBlockHeader(version, height uint64, previousBlockID, seed *Hash, timestamp uint64, transactionsRoot, assetsRoot *Hash, ts *TransactionStatus, nonce, bits uint64) *BlockHeader {
25         return &BlockHeader{
26                 Version:           version,
27                 Height:            height,
28                 PreviousBlockId:   previousBlockID,
29                 Seed:              seed,
30                 Timestamp:         timestamp,
31                 TransactionsRoot:  transactionsRoot,
32                 AssetsRoot:        assetsRoot,
33                 TransactionStatus: ts,
34                 Nonce:             nonce,
35                 Bits:              bits,
36         }
37 }