OSDN Git Service

add nonce and bits into the block header
[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.TimestampMs)
14         mustWriteForHash(w, bh.TransactionsRoot)
15         mustWriteForHash(w, bh.AssetsRoot)
16 }
17
18 // NewBlockHeader creates a new BlockHeader and populates
19 // its body.
20 func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestampMS uint64, transactionsRoot, assetsRoot *Hash, nonce, bits uint64) *BlockHeader {
21         return &BlockHeader{
22                 Version:          version,
23                 Height:           height,
24                 PreviousBlockId:  previousBlockID,
25                 TimestampMs:      timestampMS,
26                 TransactionsRoot: transactionsRoot,
27                 AssetsRoot:       assetsRoot,
28                 Nonce:            nonce,
29                 Bits:             bits,
30         }
31 }